2017-05-27 205 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);