【问题标题】:Error in specifying connection weights of neural network in MATLAB在 MATLAB 中指定神经网络的连接权重时出错
【发布时间】:2017-06-21 03:56:48
【问题描述】:

我正在使用 MATLAB R2014a,我想在神经网络下面创建:

使用下面的代码:

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;

我收到了这个网络:

现在当我想用这段代码指定输入权重时:

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.

那么,我该如何完成这个自定义神经网络以获得连接权重等详细信息?

提前致谢

【问题讨论】:

    标签: matlab neural-network


    【解决方案1】:

    最后我用下面的代码解决了这个问题:

    当我使用我在问题中解释的代码时,无法在手动模式下更改连接权重。但是使用此代码(我在答案中显示的代码),我可以更改权重和其他设置而不会出现任何错误。 feedforwardnet 是 MATLAB 中的正确函数。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 2015-06-29
      • 2011-12-09
      • 2019-04-12
      • 1970-01-01
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多