分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

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

发布时间:2023-09-06 01:55责任编辑:顾先生关键词:暂无标签

通过前面的理论学习,以及关于Error和weight的关系分析,得出的公式,练习做一个自己的神经网络,通过Python3.5:

跟随书上的python introduction,介绍下numpy中的zeros():

import numpya = numpy.zeros([3,2])a[0,0] = 1a[1,1] = 2a[2,1] = 5print(a)

结果是:

    [[1. 0.]
    [0. 2.]
    [0. 5.]]

可以用这个方法来生成矩阵。

接下来用python搭建神经网络的骨骼:

搭建一下基本的模型:

import numpyclass 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#Testinput_nodes = 3hidden_nodes = 3output_nodes = 3learning_rate = 0.5# create instance of neural networkn = 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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved