matlab与python实现神经网络_在神经网络上实现Matlab的权值和偏差

本文解决了一个关于神经网络构建的问题,详细介绍了如何使用neurolab库正确设置多层感知器网络的结构,包括输入层、隐藏层及输出层的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里有几个问题。在

第一个问题是你需要8个输入神经元。为此,您需要newff中的第一个列表的长度为8(8个输入中每个输入一个最小值和一个最大值)。因此,您只得到一个输入,而不是8(因此是3x1数组而不是3x8数组)。可以通过改变:net = nl.net.newff([[0, 1]], [3, 4])

收件人:

^{pr2}$

一种较短的书写方式:net = nl.net.newff([[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1]], [3, 4])

下一个问题是python使用与matlab不同的维度排序(默认情况下)。因此,一个具有(8,3)形状的2D数组在numpy中将有一个(3,8)的形状。所以你所有的重塑都是不必要的。在

第三个问题是输入偏差和偏差2的维度混淆了。我对neuralab的了解还不足以说明您是否希望将开始时的[3, 4]更改为{},或者是否要切换偏差。我会假设后者。在

最后一个问题是,在网络sim卡,但你只有7个。在

下面是代码的一个固定版本,假设您混淆了偏差,并使用一些伪值来填充遗漏的内容:import numpy as np

import neurolab as nl

net = nl.net.newff([[0, 1]]*8, [3, 4])

input_w = np.array([[-24.1874,24.1622,0.0755,-0.2521,4.4625,-10.7961,6.2183,0.2680],

[-24.1874,24.1622,0.0755,-0.2521,4.4625,-10.7961,6.2183,0.2680],

[-24.1874,24.1622,0.0755,-0.2521,4.4625,-10.7961,6.2183,0.2680]])

layer_w = np.array([[-3.7940,-0.0336,-14.9024],

[-3.7940,-0.0336,-14.9024],

[-3.7940,-0.0336,-14.9024],

[-3.7940,-0.0336,-14.9024]])

input_bias = np.array([0.4747,-1.2475,-1.2470])

bias_2 = np.array([-10.9982,1.9692,5.0705,-0.1236])

net.layers[0].np['w'][:] = input_w

net.layers[1].np['w'][:] = layer_w

net.layers[0].np['b'][:] = input_bias

net.layers[1].np['b'][:] = bias_2

print net.sim([[0.015,0.022,0.0,0.0,0.432,0.647,0.831]])

新版Matlab神经网络训练函数Newff的详细讲解-新版Matlab神经网络训练函数Newff的使用方法.doc 本帖最后由 小小2008鸟 于 2013-1-15 21:42 编辑 新版Matlab神经网络训练函数Newff的详细讲解 一、   介绍新版newffSyntax·          net = newff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) Descriptionnewff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) takes several arguments PR x Q1 matrix of Q1 sample R-element input vectorsTSN x Q2 matrix of Q2 sample SN-element target vectorsSiSize of ith layer, for N-1 layers, default = [ ]. TFiTransfer function of ith layer. (Default = 'tansig' for hidden layers and 'purelin' for output layer.)BTFBackpropagation network training function BLFBackpropagation weight/bias learning function IPFRow cell array of input processing functions. OPFRow cell array of output processing functions. DDFData divison function ExamplesHere is a problem consisting of inputs P and targets T to be solved with a network.·          P = [0 1 2 3 4 5 6 7 8 9 10];T = [0 1 2 3 4 3 2 1 2 3 4];Here a network is created with one hidden layer of five neurons.·          net = newff;The network is simulated and its output plotted against the targets.·          Y = sim;plotThe network is trained for 50 epochs. Again the network's output is plotted.·          net.trainParam.epochs = 50;net = train;Y = sim; plot 二、   新版newff旧版newff调用语法对比 Example1比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[14,4],{'tansig','purelin'},'trainlm');新版定义:net=newff; Example2比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[49,10,4],{'tansig','tansig','tansig'},'traingdx');新版定义:net=newff; 更详细请看word文档 新版Matlab神经网络训练函数Newff的使用方法.doc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值