0
点赞
收藏
分享

微信扫一扫

用newff模拟sin函数


用newff模拟sin函数

 

%我思故我在
P=-1:0.1:1;
%建立目标值,是sin曲线上均匀取到的21个点
T=0:0.314:6.28
T=sin(T);
%创建网络
net=newff(minmax(P),[5,1],{'tansig','purelin'},'traingda');
%newff :Create a feed-forward backpropagation network
%traingda: TRAINGDA Gradient descent with adaptive lr backpropagation.
net.trainParam.show = 50; %系统每50步显示一次训练误差的变化曲线
net.trainParam.lr = 0.05; %学习速率
net.trainParam.lr_inc = 1.08; %Ratio to increase learning rate
net.trainParam.lr_dec = 0.6; %Ratio to decrease learning rate
net.trainParam.epochs = 2000; %训练步数
net.trainParam.goal = 9.5238e-004; % sse=0.02
%训练 网络
[net,tr]=train(net,P,T);
% train trains a network net according to net.trainFcn and net.trainParam.
% train(NET,P,T,Pi,Ai,VV,TV) takes,
% net -- Neural Network 函数返回值,训练后的神经网络
% P -- Network inputs
% T -- Network targets, default = zeros
% Pi -- Initial input delay conditions, default = zeros
% Ai -- Initial layer delay conditions, default = zeros
% VV -- Structure of validation vectors, default = []
% TV -- Structure of test vectors, default = []
% and returns,
% net -- New network
% TR -- Training record (epoch and perf) 函数返回值,训练记录,步数和性能
% Y -- Network outputs
% E -- Network errors.
% Pf -- Final input delay conditions
% Af -- Final layer delay conditions
figure(1)
plot(tr.lr);
figure(2)
plot(tr.perf);
%%显示预测结果
%应用生成的网络对P进行模拟
T1=sim(net,P);
figure(3);
%显示目标值
plot(P,T,'r*');
hold on;
%显示模拟值
plot(P,T1,'g*');

举报

相关推荐

0 条评论