在 Matlab 中获取神经网络的神经元权重

Getting the Neuron Weights for a Neural Network in Matlab

我训练了一个神经网络,如下所示:

net.b returns 两个值:

<25x1 double>
0.124136217326482

net.IW returns 两个值:

<25x16 double>
[]

net.LW returns 以下:

[]  []
<1x25 double>   []

我假设 new.LW returns 单个隐藏层中 25 个神经元的权重。

我不明白 net.IW returns 以及他们从哪里得到数字 16。

请帮忙!

编辑: 添加了训练代码

netJan = newff(trainX', trainY', networkConfigJan, {'tansig','purelin'},'trainlm');
netJan.trainParam.goal = 1e-9;
netJan.trainFcn = 'traingda';
netJan = train(netJan, trainX', trainY');

维度

在这段代码之后,我继续只用 10 个输入列执行预测,所以其他 6 个完全是内部的东西。

我期待的是:

25x1 数组告诉我隐藏层中每个神经元的值。

10x25 数组告诉我每个 'line' 从输入层到隐藏层的权重。

25x1 数组告诉我每个 'line' 从隐藏层到输出层的权重。

编辑 2:

net = feedforwardnet( [25] );
net = train( net, trainX', trainY' );
size( net.IW{1}' ) % 10 x 25 , Yay!
net = newff(trainX', trainY', [25]);
net = train(net, trainX', trainY');
size( net.IW{1}' ) % 16 x 25, How is this possible?

你的隐藏问题

您的数据在第 1、2、3、8、9 和 10 列中只有 NaN 个值。

>> sum( isnan( trainX ) )
ans =
     3     3     3     0     0     0     0     1     1     1

我过滤了结果并得到了这些有意义的结果。

>> goodX = trainX( sum( ~isnan( trainX ), 2 ), : );
>> goodY = trainY( sum( ~isnan( trainX ), 2 ), : );
>> netJan = newff(goodX', goodY', [25], {'tansig','purelin'},'trainlm');
>> size( netJan.IW{1}' )
ans =
    10    25
>> size( netJan.LW{2,1}' )
ans =
    25     1

查看者有有效数据的解决方法

假设你像这样设置一个神经网络。

% Dummy NN
trainX = rand(2153,10);
trainY = rand(2153,1);
net = feedforwardnet( [25] );
net = train( net, trainX', trainY' );

您应该使用 feedforwardnet 而不是 newff

Obsoleted in R2010b NNET 7.0. Last used in R2010a NNET 6.0.4.

The recommended function is feedforwardnet.

请注意,我的调用生成了与以下 NN 初始化调用类似​​的 NN。

netJan = newff(trainX', trainY', [25], {'tansig','purelin'},'trainlm');
netJan.trainParam.goal = 1e-9;
netJan.trainFcn = 'traingda';
netJan = train(netJan, trainX', trainY');

25x1 array telling me the value of each neuron in the hidden layer.

您只需传播 input/neuron 值即可获得此

10x25 array telling me the weight of each 'line' going from input layer to hidden layer.

net.IW{1}

25x1 array telling me the weight of each 'line' going from hidden layer to output layer.

net.LW{2,1}'

测试尺码:

>> size( trainX )
ans =
        2153          10
>> size( trainY )
ans =
        2153           1
>> size( net.IW{1}' )
ans =
    10    25
>> size( net.LW{2,1}' )
ans =
    25     1

培训window

网络视图