在Matlab中获取神经网络的神经元权重 [英] Getting the Neuron Weights for a Neural Network in Matlab

查看:389
本文介绍了在Matlab中获取神经网络的神经元权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have trained a Neural Network as shown below:

net.b返回两个值:

<25x1 double>
0.124136217326482

net.IW返回两个值:

<25x16 double>
[]

net.LW返回以下内容:

[]  []
<1x25 double>   []

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

I am assuming that new.LW returns the weights of the 25 neurons in the single hidden layer.

我不知道net.IW返回什么以及它们在哪里得到16.

I don't understand what net.IW returns and where they get the number 16.

请帮助!

编辑:添加了培训代码

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

尺寸

  • trainX有10列2153行
  • trainY有1列2153行

这段代码之后,我仅用10个输入列执行预测,因此其他6个列完全是内部的.

After this code, I go on to perform predictions with only 10 input columns, so the other 6 are something completely internal.

我期望的是

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

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

10x25数组告诉我从输入层到隐藏层的每条线"的权重.

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

25x1数组告诉我从隐藏层到输出层的每条线"的权重.

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

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

Your data simply has NaN values in col 1,2,3,8,9, and 10.

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

我过滤了结果并得到了有意义的结果.

I filtered the results and got these results which make sense.

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

为观看者提供有效数据的解决方案

假设您这样设置一个NN.

Suppose you setup a NN like this.

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

您应该使用feedforwardnet而不是newff.

在R2010b NNET 7.0中已作废.上一次在R2010a NNET 6.0.4中使用.

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

推荐的功能是feedforwardnet.

The recommended function is feedforwardnet.

请注意,我的调用会生成与以下用于NN初始化的调用类似的NN.

Note that my call generates a similar NN to the following call for NN initialization.

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

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

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

您只需要传播输入/神经元值即可

You simply need to propagate the input/neuron values to get this

10x25数组告诉我从输入层到隐藏层的每条线"的权重.

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

net.IW{1}

25x1数组告诉我从隐藏层到输出层的每条线"的权重.

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

net.LW{2,1}'

要测试尺寸,请执行以下操作:

To test the sizes:

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

培训窗口

网络视图

这篇关于在Matlab中获取神经网络的神经元权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆