% 动态神经网络时间序列预测研究-基于MATLAB的NARX实现
%% 清空环境变量
clear
clc
%% 加载数据
load phdata
inputSeries = phInputs;
targetSeries = phTargets;
%% 建立非线性自回归模型
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
%% 网络数据预处理函数定义
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
%% 时间序列数据准备工作
[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
%% 训练数据、验证数据、测试数据划分
net.divideFcn = 'dividerand';
net.divideMode = 'value';
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
%% 网络训练函数设定
net.trainFcn = 'trainlm'; % Levenberg-Marquardt
%% 误差函数设定
net.performFcn = 'mse'; % Mean squared error
%% 绘图函数设定
net.plotFcns = {'plotperform','plottrainstate','plotresponse', ...
'ploterrcorr', 'plotinerrcorr'};
%% 网络训练
[net,tr] = train(net,inputs,targets,inputStates,layerStates);
%% 网络测试
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
%% 计算训练集、验证集、测试集误差
trainTargets = gmultiply(targets,tr.trainMask);
valTargets = gmultiply(targets,tr.valMask);
testTargets = gmultiply(targets,tr.testMask);
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
%% 网络训练效果可视化
figure, plotperform(tr)
figure, plottrainstate(tr)
figure, plotregression(targets,outputs)
figure, plotresponse(targets,outputs)
figure, ploterrcorr(errors)
figure, plotinerrcorr(inputs,errors)
%% close loop模式的实现
% 更改NARX神经网络模式
narx_net_closed = closeloop(net);
view(net)
view(narx_net_closed)
% 计算1500-2000个点的拟合效果
phInputs_c=phInputs(1500:2000);
PhTargets_c=phTargets(1500:2000);
[p1,Pi1,Ai1,t1] = preparets(narx_net_closed,phInputs_c,{},PhTargets_c);
% 网络仿真
yp1 = narx_net_closed(p1,Pi1,Ai1);
plot([cell2mat(yp1)' cell2mat(t1)'])
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、资源内容:基于Matlab实现动态神经网络时间序列预测研究仿真(程序).rar 2、适用人群:计算机,电子信息工程、数学等专业的学习者,作为“参考资料”参考学习使用。 3、解压说明:本资源需要电脑端使用WinRAR、7zip等解压工具进行解压,没有解压工具的自行百度下载即可。 4、免责声明:本资源作为“参考资料”而不是“定制需求”,代码只能作为参考,不能完全复制照搬。不一定能够满足所有人的需求,需要有一定的基础能够看懂代码,能够自行调试代码并解决报错,能够自行添加功能修改代码。由于作者大厂工作较忙,不提供答疑服务,如不存在资源缺失问题概不负责,谢谢理解。
资源推荐
资源详情
资源评论
收起资源包目录
基于Matlab实现动态神经网络时间序列预测研究仿真(程序).rar (11个子文件)
基于Matlab实现动态神经网络时间序列预测研究仿真(程序)
chapter40.m 2KB
img
chapter40_07.png 27KB
chapter40_02.png 7KB
chapter40_08.png 28KB
chapter40_01.png 8KB
chapter40_05.png 5KB
chapter40_06.png 5KB
chapter40.png 4KB
chapter40_03.png 7KB
chapter40_09.png 7KB
chapter40_04.png 16KB
共 11 条
- 1
资源评论
Matlab仿真实验室
- 粉丝: 2w+
- 资源: 2180
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功