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

转载请注明出处】http://blog.csdn.net/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 Frequency            show: 两次显示之间的训练次数
    Maximum Epochs                   epochs: 训练次数
    Maximum Training Time              time: 最长训练时间(秒)
    Performance Goal                      goal: 网络性能目标
    Minimum Gradient                  min_grad: 性能函数最小梯度
    Maximum Validation Checks         max_fail: 最大验证失败次数
    Learning Rate                           lr: 学习速率
    Learning Rate Increase              lr_inc: 学习速率增长值
    Learning Rate                       lr_dec: 学习速率下降值
    Maximum Performance Increase  max_perf_inc:
    Momentum Constant                       mc: 动量因子

三、新版newff与旧版newff语法对比【例子源代码下载
      http://download.csdn.net/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 ; 
    end
end
sprintf('识别率是 %3.3f%%',100 * hitNum / s2 )

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



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

新版Matlab中神经网络训练函数Newff的详细讲解-新版Matlab中神经网络训练函数Newff的使用方法.doc 本帖最后由 小小2008鸟 于 2013-1-15 21:42 编辑 新版Matlab中神经网络训练函数Newff的详细讲解 一、   介绍新版newffSyntax·          net = newff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) Descriptionnewff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) takes several arguments PR x Q1 matrix of Q1 sample R-element input vectorsTSN x Q2 matrix of Q2 sample SN-element target vectorsSiSize of ith layer, for N-1 layers, default = [ ]. TFiTransfer function of ith layer. (Default = 'tansig' for hidden layers and 'purelin' for output layer.)BTFBackpropagation network training function BLFBackpropagation weight/bias learning function IPFRow cell array of input processing functions. OPFRow cell array of output processing functions. DDFData divison function ExamplesHere is a problem consisting of inputs P and targets T to be solved with a network.·          P = [0 1 2 3 4 5 6 7 8 9 10];T = [0 1 2 3 4 3 2 1 2 3 4];Here a network is created with one hidden layer of five neurons.·          net = newff;The network is simulated and its output plotted against the targets.·          Y = sim;plotThe network is trained for 50 epochs. Again the network's output is plotted.·          net.trainParam.epochs = 50;net = train;Y = sim; plot 二、   新版newff与旧版newff调用语法对比 Example1比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[14,4],{'tansig','purelin'},'trainlm');新版定义:net=newff; Example2比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[49,10,4],{'tansig','tansig','tansig'},'traingdx');新版定义:net=newff; 更详细请看word文档 新版Matlab中神经网络训练函数Newff的使用方法.doc
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI吃大瓜

尊重原创,感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值