当前位置:网站首页>《MATLAB 神经网络43个案例分析》:第40章 动态神经网络时间序列预测研究——基于MATLAB的NARX实现
《MATLAB 神经网络43个案例分析》:第40章 动态神经网络时间序列预测研究——基于MATLAB的NARX实现
2022-07-01 12:25:00 【mozun2020】
《MATLAB 神经网络43个案例分析》:第40章 动态神经网络时间序列预测研究——基于MATLAB的NARX实现
1. 前言
《MATLAB 神经网络43个案例分析》是MATLAB技术论坛(www.matlabsky.com)策划,由王小川老师主导,2013年北京航空航天大学出版社出版的关于MATLAB为工具的一本MATLAB实例教学书籍,是在《MATLAB神经网络30个案例分析》的基础上修改、补充而成的,秉承着“理论讲解—案例分析—应用扩展”这一特色,帮助读者更加直观、生动地学习神经网络。
《MATLAB神经网络43个案例分析》共有43章,内容涵盖常见的神经网络(BP、RBF、SOM、Hopfield、Elman、LVQ、Kohonen、GRNN、NARX等)以及相关智能算法(SVM、决策树、随机森林、极限学习机等)。同时,部分章节也涉及了常见的优化算法(遗传算法、蚁群算法等)与神经网络的结合问题。此外,《MATLAB神经网络43个案例分析》还介绍了MATLAB R2012b中神经网络工具箱的新增功能与特性,如神经网络并行计算、定制神经网络、神经网络高效编程等。
近年来随着人工智能研究的兴起,神经网络这个相关方向也迎来了又一阵研究热潮,由于其在信号处理领域中的不俗表现,神经网络方法也在不断深入应用到语音和图像方向的各种应用当中,本文结合书中案例,对其进行仿真实现,也算是进行一次重新学习,希望可以温故知新,加强并提升自己对神经网络这一方法在各领域中应用的理解与实践。自己正好在多抓鱼上入手了这本书,下面开始进行仿真示例,主要以介绍各章节中源码应用示例为主,本文主要基于MATLAB2015b(32位)平台仿真实现,这是本书第四十章动态神经网络时间序列预测研究实例,话不多说,开始!
2. MATLAB 仿真示例
打开MATLAB,点击“主页”,点击“打开”,找到示例文件
选中chapter40.m,点击“打开”
chapter40.m源码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:动态神经网络时间序列预测研究-基于MATLAB的NARX实现
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-06-21
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Matlab神经网络43个案例分析
% 动态神经网络时间序列预测研究-基于MATLAB的NARX实现
% by 王小川(@王小川_matlab)
% http://www.matlabsky.com
% Email:[email protected]163.com
% http://weibo.com/hgsz2003
%% 清空环境变量
clear
clc
tic
%% 加载数据
% load phdata
[phInputs,phTargets] = ph_dataset;
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)'])
toc
添加完毕,点击“运行”,开始仿真,输出仿真结果如下:
performance =
0.0188
trainPerformance =
0.0180
valPerformance =
0.0164
testPerformance =
0.0252
时间已过 7.422134 秒。

(依次点击Performance,Training State,Time-Series Response,Error Autocorrelation,Input-Error Cross-correlation可分别得到相应图示)







3. 小结
动态神经网络已成为深度学习新型研究课题。相比静态模型(固定计算图、固定参数),动态网络可以按照不同输入自适应调整自身结构或者参数量,形成了精度、计算效率、自适应等方面的显著优势。对本章内容感兴趣或者想充分学习了解的,建议去研习书中第四十章节的内容(学习链接附在文末)。后期会对其中一些知识点在自己理解的基础上进行补充,欢迎大家一起学习交流。
边栏推荐
- ASTM D 3801 vertical burning test of solid plastics
- Machine learning - Data Science Library - day two
- Chained storage of queues
- Golang introduces the implementation method of the corresponding configuration file according to the parameters
- C summary of knowledge points 3
- Understanding of NAND flash deblocking
- CPI教程-异步接口创建及使用
- 栈-------
- Machine learning - Data Science Library Day 3 - Notes
- How to use opcache, an optimization acceleration component of PHP
猜你喜欢

Chained storage of queues

Build yocto system offline for i.mx8mmini development board

On recursion and Fibonacci sequence

Rural guys earn from more than 2000 a month to hundreds of thousands a year. Most brick movers can walk my way ǃ

Switch basic experiment

Onenet Internet of things platform - mqtt product devices send messages to message queues MQ

The Missing Semester

Onenet Internet of things platform - create mqtts products and devices

GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021

谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
随机推荐
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
(mixed version 1) multiple TXT text to one table
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
ASP.NET Core 6 从入门到企业级实战开发应用技术汇总
2022-06-28-06-29
Ansible相关内容梳理
Relationship between accuracy factor (DOP) and covariance in GPS data (reference link)
USB peripheral driver - cable connect/disconnect
Use of easyexcel
[shell programming] - shell introductory learning
The Missing Semester
leetcode 406. Queue reconstruction by height
Onenet Internet of things platform - mqtts product equipment connected to the platform
On recursion and Fibonacci sequence
Golang des-cbc
Message queue monitoring refund task batch process
AI matting tool
Unity xlua co process packaging
Joint Time-Frequency and Time Domain Learning for Speech Enhancement