基于LMS算法的Mackey Glass时间序列预测(Matlab代码实现)

简介: 基于LMS算法的Mackey Glass时间序列预测(Matlab代码实现)

💥1 概述

时间序列预测方法是科学、经济、工程等领域的研究重点之一。经典的时间序列预测方法在用于非线性系统预测时有一定的困难,而神经网络具有较好的非线性特性,为时间序列预测开辟了新的途径。但神经网络具有易陷入局部极小值以及全局搜索能力弱等缺点;而遗传算法具有较好的全局最优搜索能力,遗传神经网络将两者结合,既保留了遗传算法的全局寻优的特点,又兼有神经网络的非线性特性和收敛的快速性。Mackey-Glass(MG)混沌时间序列具有非线性特性,是时间序列预测问题中的基准问题之一,具有代表性。


时滞混沌系统即具有混沌运动的时滞系统。时滞系统是系统中一处或几处的信号传递有时间延迟的系统。所谓混沌是指具有以下特点的一类现象:由确定性产生;具有有界性;具有非周期性;初始条件具有极端敏感性。


📚2 运行结果

🎉3 参考文献

[1]邵海见,邓星.基于RBF神经网络结构选择方法的Mackey-Glass与Lorenz混沌时间序列预测建模[J].江苏科技大学学报(自然科学版),2018,32(05):701-706.

👨‍💻4 Matlab代码

%% mackeyglass
% This script generates a Mackey-Glass time series using the 4th order
% Runge-Kutta method.
%% Input parameters
a        = 0.2;     % value for a in eq (1)
b        = 0.1;     % value for b in eq (1)
tau      = 17;    % delay constant in eq (1)
x0       = 1.2;   % initial condition: x(t=0)=x0
deltat   = 0.1;     % time step size (which coincides with the integration step)
sample_n = 5000;  % total no. of samples, excluding the given initial condition
interval = 1;     % output is printed at every 'interval' time steps
%% Main algorithm
% * x_t             : x at instant t         , i.e. x(t)        (current value of x)
% * x_t_minus_tau   : x at instant (t-tau)   , i.e. x(t-tau)   
% * x_t_plus_deltat : x at instant (t+deltat), i.e. x(t+deltat) (next value of x)
% * X               : the (sample_n+1)-dimensional vector containing x0 plus all other computed values of x
% * T               : the (sample_n+1)-dimensional vector containing time samples
% * x_history       : a circular vector storing all computed samples within x(t-tau) and x(t)
time = 0;
index = 1;
history_length = floor(tau/deltat);
x_history = zeros(history_length, 1); % here we assume x(t)=0 for -tau <= t < 0
x_t = x0;
X = zeros(sample_n, 1); % vector of all generated x samples
T = zeros(sample_n, 1); % vector of time samples
for i = 1:sample_n
    X(i) = x_t;
    if tau == 0
        x_t_minus_tau = 0.0;
    else
        x_t_minus_tau = x_history(index);
    end
    x_t_plus_deltat = mackeyglass_rk4(x_t, x_t_minus_tau, deltat, a, b);
    if (tau ~= 0)
        x_history(index) = x_t_plus_deltat;
        index = mod(index, history_length)+1;
    end
    time = time + deltat;
    T(i) = time;
    x_t = x_t_plus_deltat;
end
% Save training and test data
Data = X;
save('Dataset\Data.mat','');
figure
plot(T, X);
set(gca,'xlim',[0, T(end)]);
xlabel('t');
ylabel('x(t)');
title(sprintf('A Mackey-Glass time serie (tau=%d)', tau));


主函数部分代码:

clc
clear all
close all
%% Load Mackey Glass Time series data
load Dataset\Data.mat 
%% Training and Testing datasets
% For training
Tr=1:4000;    % First 4000 samples for training
Xr(Tr)=Data(Tr);      % Selecting a chuck of series data x(t)
% For testing
Ts=4000:5000;   % Last 1000 samples for testing
Xs(Ts)=Data(Ts);      % Selecting a chuck of series data x(t)
%% LMS Parameters
% We run the LMS algorithm for different learning rates
etaValues = [5e-4 1e-3 5e-3 0.01]; % Learning rate
M=5;    % Order of LMS filter
W_init=randn(M+1,1); % Initialize weights
figure(2)
plot(Tr(2*M:end-M),Xr(Tr(2*M:end-M)));      % Actual values of mackey glass series
figure(3)
plot(Ts,Xs(Ts));        % Actual unseen data
for eta = etaValues
    U=zeros(1,M+1); % Initialize values of taps
    W=W_init; % Initialize weights
    E=[];         % Initialize squared error vector
    %% Learning weights of LMS (Training)
    for i=Tr(1):Tr(end)-1
        U(1:end-1)=U(2:end);    % Shifting of tap window
        U(end)=Xr(i);           % Input (past/current samples)
        Y(i)=W'*U';             % Predicted output
        e(i)=Xr(i+1)-Y(i);        % Error in predicted output
        W=W+eta*e(i)*U';     % Weight update rule of LMS
        E(i)=e(i).^2;   % Concatenate current squared error
    end
    %% Prediction of a next outcome of series using previous samples (Testing)
    for i=Ts(1):Ts(end)
        U(1:end-1)=U(2:end);    % Shifting of tap window
        U(end)=Xs(i);           % Input (past/current samples)
        Y(i)=W'*U';             % Calculating output (future value)
        e(i)=Xs(i)-Y(i);        % Error in predicted output
        E(i)=e(i).^2;   % Current mean squared error (MSE)
    end
    % Plot the squared error over the training sample iterations
    figure(1),hold on;
    plot(Tr(1:end-1),E(:,Tr(1:end-1)));   % MSE curve
    hold off;
    % Plot the predicted training data
    figure(2), hold on;
    plot(Tr(2*M:end-M),Y(Tr(2*M:end-M))')   % Predicted values during training
    hold off;
%   Comment out the following parts to plot prediction of the test data    
    figure(3), hold on; 
    plot(Ts(2*M:end),Y(Ts(2*M:end))');  % Predicted values of mackey glass series (testing)
    hold off;
    MSEtr= mean(E(Tr));  % MSE of training
    MSEts= mean(E(Ts));  % MSE of testing
    disp(['MSE for test samples (Learning Rate: ' num2str(eta) '):' num2str(MSEts)]);
end
相关文章
|
1天前
|
传感器 算法
基于GA遗传算法的多机无源定位系统GDOP优化matlab仿真
本项目基于遗传算法(GA)优化多机无源定位系统的GDOP,使用MATLAB2022A进行仿真。通过遗传算法的选择、交叉和变异操作,迭代优化传感器配置,最小化GDOP值,提高定位精度。仿真输出包括GDOP优化结果、遗传算法收敛曲线及三维空间坐标点分布图。核心程序实现了染色体编码、适应度评估、遗传操作等关键步骤,最终展示优化后的传感器布局及其性能。
|
2天前
|
机器学习/深度学习 算法 安全
基于深度学习的路面裂缝检测算法matlab仿真
本项目基于YOLOv2算法实现高效的路面裂缝检测,使用Matlab 2022a开发。完整程序运行效果无水印,核心代码配有详细中文注释及操作视频。通过深度学习技术,将目标检测转化为回归问题,直接预测裂缝位置和类别,大幅提升检测效率与准确性。适用于实时检测任务,确保道路安全维护。 简介涵盖了算法理论、数据集准备、网络训练及检测过程,采用Darknet-19卷积神经网络结构,结合随机梯度下降算法进行训练。
|
3天前
|
算法 数据可视化 数据安全/隐私保护
一级倒立摆平衡控制系统MATLAB仿真,可显示倒立摆平衡动画,对比极点配置,线性二次型,PID,PI及PD五种算法
本课题基于MATLAB对一级倒立摆控制系统进行升级仿真,增加了PI、PD控制器,并对比了极点配置、线性二次型、PID、PI及PD五种算法的控制效果。通过GUI界面显示倒立摆动画和控制输出曲线,展示了不同控制器在偏转角和小车位移变化上的性能差异。理论部分介绍了倒立摆系统的力学模型,包括小车和杆的动力学方程。核心程序实现了不同控制算法的选择与仿真结果的可视化。
31 15
|
3天前
|
算法
基于SOA海鸥优化算法的三维曲面最高点搜索matlab仿真
本程序基于海鸥优化算法(SOA)进行三维曲面最高点搜索的MATLAB仿真,输出收敛曲线和搜索结果。使用MATLAB2022A版本运行,核心代码实现种群初始化、适应度计算、交叉变异等操作。SOA模拟海鸥觅食行为,通过搜索飞行、跟随飞行和掠食飞行三种策略高效探索解空间,找到全局最优解。
|
5天前
|
机器学习/深度学习 数据采集 算法
基于GWO灰狼优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目基于MATLAB2022a,展示了时间序列预测算法的运行效果(无水印)。核心程序包含详细中文注释和操作视频。算法采用CNN-GRU-SAM网络,结合灰狼优化(GWO),通过卷积层提取局部特征、GRU处理长期依赖、自注意力机制捕捉全局特征,最终实现复杂非线性时间序列的高效预测。
|
5天前
|
传感器 算法 物联网
基于粒子群算法的网络最优节点部署优化matlab仿真
本项目基于粒子群优化(PSO)算法,实现WSN网络节点的最优部署,以最大化节点覆盖范围。使用MATLAB2022A进行开发与测试,展示了优化后的节点分布及其覆盖范围。核心代码通过定义目标函数和约束条件,利用PSO算法迭代搜索最佳节点位置,并绘制优化结果图。PSO算法灵感源于鸟群觅食行为,适用于连续和离散空间的优化问题,在通信网络、物联网等领域有广泛应用。该算法通过模拟粒子群体智慧,高效逼近最优解,提升网络性能。
|
6天前
|
机器学习/深度学习 存储 算法
近端策略优化(PPO)算法的理论基础与PyTorch代码详解
近端策略优化(PPO)是深度强化学习中高效的策略优化方法,广泛应用于大语言模型的RLHF训练。PPO通过引入策略更新约束机制,平衡了更新幅度,提升了训练稳定性。其核心思想是在优势演员-评论家方法的基础上,采用裁剪和非裁剪项组成的替代目标函数,限制策略比率在[1-ϵ, 1+ϵ]区间内,防止过大的策略更新。本文详细探讨了PPO的基本原理、损失函数设计及PyTorch实现流程,提供了完整的代码示例。
114 10
近端策略优化(PPO)算法的理论基础与PyTorch代码详解
|
6月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
272 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
6月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
138 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
6月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
162 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现

热门文章

最新文章