标签:span 一个 pass data random bubuko 接下来 __init__ style
通过前面的理论学习,以及关于Error和weight的关系分析,得出的公式,练习做一个自己的神经网络,通过Python3.5:
跟随书上的python introduction,介绍下numpy中的zeros():
import numpy a = numpy.zeros([3,2]) a[0,0] = 1 a[1,1] = 2 a[2,1] = 5 print(a)
结果是:
[[1. 0.]
[0. 2.]
[0. 5.]]
可以用这个方法来生成矩阵。
接下来用python搭建神经网络的骨骼:
搭建一下基本的模型:
import numpy class neuralNetwork: def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate): self.inodes = inputnodes self.hnodes = hiddennodes self.onodes = outputnodes self.lr = learningrate # generate the link weights between the range of -1 to +1 self.wih = numpy.random.normal(0.0, pow(self.hnodes, -0.5), (self.hnodes, self.inodes)) self.who = numpy.random.normal(0.0, pow(self.onodes, -0.5), (self.onodes, self.hnodes)) pass def train(self): pass def query(self): pass #Test input_nodes = 3 hidden_nodes = 3 output_nodes = 3 learning_rate = 0.5 # create instance of neural network n = neuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate)
cunstructor里面有开始节点,hidden节点,以及output节点,包括learning rate.
各个link weight使用numpy随机数的形式,初始化生成一系列的weight然后再通过training data 去寻找error,进行反向modify
学习Make your own neural network 记录(二)
标签:span 一个 pass data random bubuko 接下来 __init__ style
原文地址:https://www.cnblogs.com/ChrisInsistPy/p/9056066.html