【啃书】《智能优化算法及其MATLAB实例》例9.1运用BP网络拟合白噪声的正弦样本数据

问题描述

在这里插入图片描述

仿真过程

在这里插入图片描述
在这里插入图片描述
BP算法的运算流程

matlab源码

%20201029lu注:在matlab2019a成功运行
%%%%%%%%%%%%%运用BP网络拟合白噪声的正弦样本数据%%%%%%%%%%%%%%%%
clear all;                      %清除所有变量
close all;                      %清图
clc;                            %清屏
%%%%%%%%%%%%%%%%%%%%%定义训练样本矢量%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%P 为输入矢量%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P = [-1:0.05:1];
%%%%%%%%%%%%%%%%%%%%%%T 为目标矢量%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T = sin(2*pi*P)+0.1*randn(size(P));
%%%%%%%%%%%%%%%%%%%%%%绘制样本数据点%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
plot(P,T,'+');
hold on;
plot(P,sin(2*pi*P),':');
%%%%%%%%%%%%%%%%%%%%%绘制不含噪声的正弦曲线%%%%%%%%%%%%%%%%%%%
net=newff(minmax(P),[20,1],{'tansig','purelin'},'trainbr');
%%%%%%%%%%%%%%%%%%%采用贝叶斯正则化算法 TRAINBR%%%%%%%%%%%%%%%
%net.trainFcn='trainbr';
%%%%%%%%%%%%%%%%%%%%%%设置训练参数%%%%%%%%%%%%%%%%%%%%%%%%%%%%
net.trainParam.show = 50;              %显示中间结果的周期
net.trainParam.lr = 0.05;              %学习率
net.trainParam.epochs = 500;           %最大迭代次数
net.trainParam.goal = 1e-3;            %目标误差
%%%%%%%%%%%%%%%%%%%%用相应算法训练 BP 网络%%%%%%%%%%%%%%%%%%%%
[net,tr]=train(net,P,T);
%%%%%%%%%%%%%%%%%%%%%对 BP 网络进行仿真%%%%%%%%%%%%%%%%%%%%%%%
A = sim(net,P);
%%%%%%%%%%%%%%%%%%%%%%计算仿真误差%%%%%%%%%%%%%%%%%%%%%%%%%%%%
E = T - A;
MSE=mse(E);
%%%%%%%%%%%%%%%%%%%%%%绘制匹配结果曲线%%%%%%%%%%%%%%%%%%%%%%%%
plot(P,A,P,T,'+',P,sin(2*pi*P),':');
legend('样本点','标准正弦曲线','拟合正弦曲线');

在这里插入图片描述

中 智能优化算法及其MATLAB实例(第二版)[包子阳,余继周][电子工业出版社][2018年01月][9787121330308]

经过调试,随书所有代码均可以在matlabR2019a上成功运行https://mianbaoduo.com/o/bread/YZyVlp9v

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值