2

我需要帮助纠正此代码以在 matlab 中使用神经网络实现 XOR。但是,我无法设置从输入层到第一层的输入权重。该网络分别有2,2和1个神经元的输入层、隐藏层和输出层。有人可以帮我吗?

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)
4

1 回答 1

0

doc network告诉我:

如果 net.inputConnect(i,j) 为 1,则 net.inputWeights{i,j} 是定义从输入 j 到层 i 的权重的结构。

net.inputWeights因此,您应该为输入和第一层节点的每个组合设置元素,而不是为 设置元胞数组,如下所示:net.inputWeights

net.inputWeights{1,1} = weight11; % input1 node 1
net.inputWeigtts{1,2} = weight12; % input1 node 2
...
于 2012-06-20T07:40:10.700 回答