2017-05-27 210 views
0

指定神经网络的连接权我使用MATLAB R2014a,我想创建神经网络下面:错误在MATLAB

Connection weights of dashed lines are -1 and other solid lines weight's are 1

使用下面的代码:

net=network; 
net.numInputs=2; 
net.numLayers=3; 
net.inputConnect=[1 1;0 0;0 0]; 
net.layerConnect=[0 0 0;1 0 0;0 1 0]; 
net.layers{1}.size=2; 
net.layers{2}.size=4; 
net.layers{3}.size=2; 
net.outputConnect=[0 0 1]; 
net.layers{:}.transferFcn = 'hardlim'; 
net.trainFcn = 'trainscg'; 
net.inputs{1}.size=4; 
net.inputs{2}.size=4; 

我收到此网络:

enter image description here

现在,当我要使用此代码指定输入权重:

net.inputWeights=[1 1;0 0; 0 0]; 

或者这一个:

net.inputWeights{1,1}=1; 

我得到这个错误:

Error using network/subsasgn>network_subsasgn (line 267) 
You must assign to subobject properties individually[.][3] 

Error in network/subsasgn (line 13) 
net = network_subsasgn(net,subscripts,v,netname); 

而且随着net.IW=[1 1;0 0; 0 0];,错误将是这样的:

Error using network/subsasgn>network_subsasgn (line 553) 
net.IW must be a 3-by-2 cell array. 

Error in network/subsasgn (line 13) 
net = network_subsasgn(net,subscripts,v,netname); 

我也试过net=configure(net,x,t)net = train(net,x,t)功能时,例如:x=[1 2 3 4]; t=[1.5 2.5 3.5 4.5];,但我收到此错误configure功能:

Error using network/configure (line 111) 
The numbers of input signals and networks inputs do not match. 

,这一次为train

Error using network/train (line 320) 
Number of inputs does not match net.numInputs. 

所以,我怎么能完成这个定制神经网络的细节,如连接权重?

在此先感谢

回答

0

最后,我已经解决了与下面的代码的问题:

当我用了,我在我的问题解释的代码,也没有改变连接的权重能力手动模式。但是通过这段代码(我在回答中显示的代码),我可以在不出现任何错误的情况下更改权重和其他设置。在MATLAB中,feedforwardnet是正确的功能。

net=feedforwardnet([2,4,2]); 
net.numInputs=2; 
net.inputConnect=[1 1;0 0;0 0;0 0]; 
net.layerConnect=[0 0 0 0;1 0 0 0;0 1 0 0;0 0 1 0]; 
net.inputs{1}.size=1; 
net.inputs{2}.size=1; 
net.IW{1,1}=[1;0]; 
net.IW{1,2}=[0;1]; 
net.LW{2,1}=[-1 1;1 -1;-1 -1;1 1]; 
net.LW{3,2}=[1 1 0 0;0 0 1 1]; 
view(net);