700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 解决Warning: NEWFF used in an obsolete way. See help for NEWFF to update calls to the new argument li

解决Warning: NEWFF used in an obsolete way. See help for NEWFF to update calls to the new argument li

时间:2018-08-27 10:23:15

相关推荐

解决Warning: NEWFF used in an obsolete way.  See help for NEWFF to update calls to the new argument li

解决Warning: NEWFF used in an obsolete way. See help for NEWFF to update calls to the new argument list.

【转载请注明出处】/guyuealian/article/details/66969232

使用Matlab工具箱创建神经网络时,需要用到newff函数,但若使用旧版本的newff函数,会出现下面的警告:

>> net = newff( minmax(input) , [10 3] , { 'logsig' 'purelin' } , 'traingdx') ; %旧版本

Warning: NEWFF used in an obsolete way.

> In obs_use at 18

In newff>create_network at 127

In newff at 102

See help for NEWFF to update calls to the new argument list.

一、新旧版本newff函数差异和解决方法:

这种警告是由于使用旧版本的newff参数列表,解决方法很简单,就是改为新版本形式参数列表:

net = newff( minmax(input) , [10 3] , { 'logsig' 'purelin' } , 'traingdx') ; %旧版本net2 = newff( input,output', [10] , { 'logsig' 'purelin' } , 'traingdx' ) ; %新版本

说明:旧版本中第一个参数需要结合minmax()函数使用,新版本不需要了;新版本中不需要指定输出层的神经元个数,改为由输入参数output决定,其他参数不变。

这是新旧版本创建神经网络的方法,但存在另外一个问题,即使相同的数据和参数下,新旧版本的计算结果总是不一样,而且二者偏差很大,通常新版本的newff方法的识别率总是偏低。

网上找了一些原因:newff.m分成三大块:主程序、新版实现子函数 new_5p1()、旧版实现子函数 new_5p0()。通过仔细比较新旧这两个子函数,发现新版设置了net.divideFcn 属性,其值为'dividerand'。该函数把样本数据三分为训练集、验证集和测试集,默认比例是6:2:2。

若想减少新旧版本之间的差异,需要清除net2.divideFcn等属性再训练,否则结果相去甚远,且远不止一个数量级。因此,解决新旧版本newff之间差异的方法,是在新版中net2中再添加一条语句:

net2.divideFcn = '';

下面内容是函数说明和例子,倘若您的问题解决的话,可以不看了……

二、新版newff函数参数说明:

(1)net=newff(P,T,S)或者net = newff(P,T,S,TF,BTF,BLF,PF,IPF,OPF,DDF)

P:输入参数矩阵。(RxQ1),其中Q1代表R元的输入向量。其数据意义是矩阵P有Q1列,每一列都是一个样本,而每个样本有R个属性(特征)。一般矩阵P需要归一化,即P的每一行都归一化到[0 1]或者[-1 1]。

T:目标参数矩阵。(SNxQ2),Q2代表SN元的目标向量。

S:N-1个隐含层的数目(S(i)到S(N-1)),默认为空矩阵[]。输出层的单元数目SN取决于T。返回N层的前馈BP神经网络

TF:相关层的传递函数,默认隐含层为tansig函数,输出层为purelin函数。

BTF:BP神经网络学习训练函数,默认值为trainlm函数。

BLF:权重学习函数,默认值为learngdm。

PF:性能函数,默认值为mse。

IPF,OPF,DDF均为默认值即可。

如:

net = newff( minmax(TrainData) , [50 4] , { 'logsig' 'purelin' } , 'traingdx' ) ;%旧版本PS:其中TrainData:是输入的训练的数据矩阵,注意TrainData矩阵形式每一列是一个样本,每一行是样本的属性或特征net = newff( input,output, [50] , { 'logsig' 'purelin' } , 'traingdx' ) ; %新版本

(2)传递函数

purelin 线性传递函数

tansig 正切 S 型传递函数

logsig 对数 S 型传递函数

隐含层和输出层函数的选择对BP神经网络预测精度有较大影响,一般隐含层节点转移函数选用 tansig函数或logsig函数,输出层节点转移函数选用tansig函数或purelin函数。

(3)学习训练函数

神经网络的学习分为有导师学习和无导师学习。

最速下降BP算法:traingd

动量BP算法:traingdm

学习率可变的BP算法:trainda(学习率可变的最速下降BP算法);traindx(学习率可变的动量BP算法)

弹性算法:trainrp

变梯度算法:traincgf(Fletcher-Reeves修正算法)

traincgp(Polak_Ribiere修正算法)

traincgb(Powell-Beale复位算法)

trainbfg(BFGS 拟牛顿算法)

trainoss(OSS算法)

trainlm(LM算法)

参数说明:通过net.trainParam可以查看参数

Show Training Window Feedback showWindow: true

Show Command Line Feedback showCommandLine: false

Command Line Frequencyshow: 两次显示之间的训练次数

Maximum Epochsepochs: 训练次数

Maximum Training Time time: 最长训练时间(秒)

Performance Goal goal: 网络性能目标

Minimum Gradient min_grad: 性能函数最小梯度

Maximum Validation Checksmax_fail: 最大验证失败次数

Learning Rate lr: 学习速率

Learning Rate Increase lr_inc: 学习速率增长值

Learning Rate lr_dec: 学习速率下降值

Maximum Performance Increase max_perf_inc:

Momentum Constant mc: 动量因子

三、新版newff与旧版newff语法对比【例子源代码下载】/detail/guyuealian/9795364

下面以Iris数据分类为例子,将Iris数据集分为2组,每组各75个样本,每组中每种花各有25个样本,每种样本有4个属性(特征)。其中一组作为以上程序的训练样本,另外一组作为检验样本。为了方便训练,将3类花分别编号为1,2,3 。使用这些数据训练一个4输入(分别对应4个特征),3输出(分别对应该样本属于某一品种的可能性大小)的前向网络。

根据上面的题意,我知道输入训练数据矩阵input有4个特征共75个样本(input=4×75),输出output为3个类别(3×75),假设,使用三层网络结构,那么第一层输入层的神经元个数由输入矩阵的特征决定(即3个),隐含层神经元个数可自定义设定(本例是10个),输出层的神经元个数由预期样本类别决定(即3个类别),整个Matlab程序如下:

clc,clear %读取训练数据[f1,f2,f3,f4,class] = textread('trainData.txt' , '%f%f%f%f%f',150);%特征值归一化[input,minI,maxI] = premnmx( [f1 , f2 , f3 , f4 ]') ;%构造输出矩阵s = length( class ) ;output = zeros( s , 3 ) ;for i = 1 : s output( i , class( i ) ) = 1 ;end%创建神经网络net = newff( minmax(input) , [10 3] , { 'logsig' 'purelin' } , 'traingdx') ; %旧版本% net = newff( input,output', [10] , { 'logsig' 'purelin' } , 'traingdx' ) ; %新版本% net.divideFcn = '';%设置训练参数net.trainparam.show = 50 ;net.trainparam.epochs = 500 ;net.trainparam.goal = 0.01 ;net.trainParam.lr = 0.01 ;%开始训练net = train( net, input , output' ) ;%读取测试数据[t1 t2 t3 t4 c] = textread('testData.txt' , '%f%f%f%f%f',150);%测试数据归一化testInput = tramnmx ( [t1,t2,t3,t4]' , minI, maxI ) ;%仿真Y = sim( net , testInput ) ;%统计识别正确率[s1 , s2] = size( Y ) ;hitNum = 0 ;for i = 1 : s2[m , Index] = max( Y( : , i ) ) ;if( Index == c(i) ) hitNum = hitNum + 1 ; endendsprintf('识别率是 %3.3f%%',100 * hitNum / s2 )

运行发现,旧版本的识别率是稳定在 97.333%左右,而改用新版本newff且不设置net.divideFcn = '';时的识别率只有90.667%-94.667%,设置net.divideFcn = '';后,二者相差不大了。

如果你觉得该帖子帮到你,还望贵人多多支持,鄙人会再接再厉,继续努力的~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。