新版Matlab中神经网络训练函数Newff的使用方法

上传人:痛*** 文档编号:168132410 上传时间:2022-11-07 格式:DOC 页数:8 大小:159KB
返回 下载 相关 举报
新版Matlab中神经网络训练函数Newff的使用方法_第1页
第1页 / 共8页
新版Matlab中神经网络训练函数Newff的使用方法_第2页
第2页 / 共8页
新版Matlab中神经网络训练函数Newff的使用方法_第3页
第3页 / 共8页
点击查看更多>>
资源描述
新版Matlab中神经网络训练函数Newff的使用方法一、 介绍新版newffSyntax net = newff(P,T,S1 S2.S(N-l),TF1 TF2.TFNl, BTF,BLF,PF,IPF,OPF,DDF)Descriptionnewff(P,T,S1 S2.S(N-l),TF1 TF2.TFNl, BTF,BLF,PF,IPF,OPF,DDF) takes several argumentsPR 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 = .(Output layer size SN is determined from T.)TFiTransfer function of ith layer. (Default = tansig forhidden layers and purelin for output layer.)BTFBackpropagation network training function (default = trainlm)BLFBackpropagation weight/bias learning function (default = learngdm)IPFRow cell array of input processing functions. (Default = fixunknowns,removeconstantrows,mapminmax)OPFRow cell array of output processing functions. (Default = removeconstantrows,mapminmax)DDFData divison function (default = dividerand)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(P,T,5);The network is simulated and its output plotted against the targets. Y = sim(net,P);plot(P,T,P,Y,o)The network is trained for 50 epochs. Again the networks output is plotted. net.trainParam.epochs = 50;net = train(net,P,T);Y = sim(net,P);plot(P,T,P,Y,o)二、 新版newff与旧版newff调用语法对比Example1比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff(minmax(input),7,1,tansig,purelin,trainlm);新版定义:net=newff(input,output,7,tansig,purelin,trainlm);Example2比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff(minmax(input),49,10,1,tansig,tansig,tansig,traingdx);新版定义:net=newff(input,output, 49,10, tansig,tansig,tansig,traingdx);三、 旧版newff使用方法在新版本中使用提示:旧版本定义的newff虽也能在新版本中使用,但会有警告,警告如下:Warning: NEWFF used in an obsolete way. In obs_use at 18In newffcreate_network at 127In newff at 102 See help for NEWFF to update calls to the new argument list.四、 新版newff与旧版newff使用的训练效果对比旧版本:旧用法训练次数多,但精度高 新版本:新用法训练次数少,但精度可能达不到要求造成上述原因是:程序里面的权值、阈值的初始值是随机赋值的,所以每次运行的结果都会不一样,有好有坏。你可以把预测效果不错的网络的权值和阈值作为初始值。具体可以查看net.iw1,1、net.lw2,1、net.b1、net.b2的值。现在给一个完整的例子 % 清空环境变量clcclear% 训练数据预测数据data=importdata(test.txt);%从1到768间随机排序k=rand(1,768);m,n=sort(k);%输入输出数据input=data(:,1:8);output =data(:,9);%随机提取500个样本为训练样本,268个样本为预测样本input_train=input(n(1:500),:);output_train=output(n(1:500),:);input_test=input(n(501:768),:);output_test=output(n(501:768),:);%输入数据归一化inputn,inputps=mapminmax(input_train);% BP网络训练% %初始化网络结构net=newff(inputn,output_train,10);net.trainParam.epochs=1000;net.trainParam.lr=0.1;net.trainParam.goal=0.;% 网络训练net=train(net,inputn,output_train);% BP网络预测%预测数据归一化inputn_test=mapminmax(apply,input_test,inputps);%网络预测输出BPoutput=sim(net,inputn_test);% 结果分析%根据网络输出找出数据属于哪类BPoutput(find(BPoutput=0.5)=1;% 结果分析%画出预测种类和实际种类的分类图figure(1)plot(BPoutput,og)hold onplot(output_test,r*);legend(预测类别,输出类别)title(BP网络预测分类与实际类别比对,fontsize,12)ylabel(类别标签,fontsize,12)xlabel(样本数目,fontsize,12)ylim(-0.5 1.5)%预测正确率rightnumber=0;for i=1:size(output_test,2) if BPoutput(i)=output_test(i) rightnumber=rightnumber+1; endendrightratio=rightnumber/size(output_test,2)*100;sprintf(测试准确率=%0.2f,rightratio)
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 施工组织


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!