2
我需要幫助糾正這段代碼,以在matlab中使用神經網絡實現XOR。但是,我無法將輸入權重從輸入層設置爲第一層。該網絡分別具有2,2和1個神經元的輸入層,隱層和輸出層。 有人可以幫助我嗎?matlab中的神經網絡:如何指定輸入權重
net=network;
net.numInputs = 1;
net.inputs{1}.size = 2;
net.numLayers = 2;
net.layers{1}.size = 2;
net.layers{2}.size = 1;
net.inputConnect(1) = 1;
net.layerConnect(2, 1) = 1;
net.outputConnect(2) = 1;
net.targetConnect(2) = 1;
net.layers{1}.transferFcn = 'logsig';%>> net.layers{2}.transferFcn = 'purelin';
net.layers{2}.transferFcn = 'logsig';
net.biasConnect = [ 1 ; 1];
net.layers{1}.initFcn = 'initwb';
net.layers{2}.initFcn = 'initwb';
net.inputWeights={1 1;1 1};%ask this. error is not explanatory. probably syntax.
net.biases{1}={-1.5 -0.5};
net.biases{2}=-0.5;
net.layerWeights{2,1}={-2 1};
P=[0 1 0 1;0 0 1 1];
T=[0 1 1 0];
net.initFcn = 'initlay';
net = init(net);
net.adaptFcn = 'adaptwb';
net.inputWeights{1,1}.learnFcn = 'learnp';
net.biases{1}.learnFcn = 'learnp';
net.adaptParam.passes =3;
net.performFcn = 'mse';
y = sim(net,P)