python - 神经网络示例源代码(最好是 Python)

标签 python neural-network

<分区>

我想知道是否有人有 python 神经网络的一些示例代码。如果有人知道某种带有完整演练的教程那会很棒,但是示例源也很棒!

谢谢

最佳答案

在 ubuntu 论坛上发现了这个有趣的讨论 http://ubuntuforums.org/showthread.php?t=320257

import time
import random

# Learning rate:
# Lower  = slower
# Higher = less precise
rate=.2

# Create random weights
inWeight=[random.uniform(0, 1), random.uniform(0, 1)]

# Start neuron with no stimuli
inNeuron=[0.0, 0.0]

# Learning table (or gate)
test =[[0.0, 0.0, 0.0]]
test+=[[0.0, 1.0, 1.0]]
test+=[[1.0, 0.0, 1.0]]
test+=[[1.0, 1.0, 1.0]]

# Calculate response from neural input
def outNeuron(midThresh):
    global inNeuron, inWeight
    s=inNeuron[0]*inWeight[0] + inNeuron[1]*inWeight[1]
    if s>midThresh:
        return 1.0
    else:
        return 0.0

# Display results of test
def display(out, real):
        if out == real:
            print str(out)+" should be "+str(real)+" ***"
        else:
            print str(out)+" should be "+str(real)

while 1:
    # Loop through each lesson in the learning table
    for i in range(len(test)):
        # Stimulate neurons with test input
        inNeuron[0]=test[i][0]
        inNeuron[1]=test[i][1]
        # Adjust weight of neuron #1
        # based on feedback, then display
        out = outNeuron(2)
        inWeight[0]+=rate*(test[i][2]-out)
        display(out, test[i][2])
        # Adjust weight of neuron #2
        # based on feedback, then display
        out = outNeuron(2)
        inWeight[1]+=rate*(test[i][2]-out)
        display(out, test[i][2])
        # Delay
        time.sleep(1)

编辑:还有一个名为 chainer 的框架 https://pypi.python.org/pypi/chainer/1.0.0

关于python - 神经网络示例源代码(最好是 Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1514573/

相关文章:

python - 检测 QWebEngineView 上的鼠标点击

python - 反向传播算法无法正常工作

neural-network - 如何用 MLP 训练乘法器?

graph - 如何在图形上绘制连接的网络节点?

machine-learning - 在caffe中定义新层时如何获取学习率或迭代次数

python - 加载巨大的 XML 文件并处理 MemoryError

python - 调度程序使 python 脚本运行但不生成 csv 文件

python - 分段上传到 Amazon Glacier : Content-Range incompatible with Content-Length

python - 如何在 TensorFlow 中选择交叉熵损失?

python - 为什么即使我没有在函数中点击 yield 关键字,我仍然会收到一个生成器