【问题标题】:Neural Network in matlab: How to specify input weightsmatlab中的神经网络:如何指定输入权重
【发布时间】:2012-06-22 01:56:52
【问题描述】:

我需要帮助纠正此代码以在 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)

【问题讨论】:

    标签: neural-network matlab


    【解决方案1】:

    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
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-29
      • 2013-12-27
      • 2011-12-09
      • 2017-11-28
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2010-12-02
      相关资源
      最近更新 更多