首页 > Web开发 > 详细

学习Make your own neural network 记录(二)

时间:2018-05-18 15:14:24      阅读:214      评论:0      收藏:0      [点我收藏+]

通过前面的理论学习,以及关于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 记录(二)

原文:https://www.cnblogs.com/ChrisInsistPy/p/9056066.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!