基于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月前
|
算法 数据安全/隐私保护 计算机视觉
基于Retinex算法的图像去雾matlab仿真
本项目展示了基于Retinex算法的图像去雾技术。完整程序运行效果无水印,使用Matlab2022a开发。核心代码包含详细中文注释和操作步骤视频。Retinex理论由Edwin Land提出,旨在分离图像的光照和反射分量,增强图像对比度、颜色和细节,尤其在雾天条件下表现优异,有效解决图像去雾问题。
|
1天前
|
算法
基于遗传优化算法的风力机位置布局matlab仿真
本项目基于遗传优化算法(GA)进行风力机位置布局的MATLAB仿真,旨在最大化风场发电效率。使用MATLAB2022A版本运行,核心代码通过迭代选择、交叉、变异等操作优化风力机布局。输出包括优化收敛曲线和最佳布局图。遗传算法模拟生物进化机制,通过初始化、选择、交叉、变异和精英保留等步骤,在复杂约束条件下找到最优布局方案,提升风场整体能源产出效率。
|
7天前
|
机器学习/深度学习 存储 算法
近端策略优化(PPO)算法的理论基础与PyTorch代码详解
近端策略优化(PPO)是深度强化学习中高效的策略优化方法,广泛应用于大语言模型的RLHF训练。PPO通过引入策略更新约束机制,平衡了更新幅度,提升了训练稳定性。其核心思想是在优势演员-评论家方法的基础上,采用裁剪和非裁剪项组成的替代目标函数,限制策略比率在[1-ϵ, 1+ϵ]区间内,防止过大的策略更新。本文详细探讨了PPO的基本原理、损失函数设计及PyTorch实现流程,提供了完整的代码示例。
122 10
近端策略优化(PPO)算法的理论基础与PyTorch代码详解
|
1月前
|
算法 数据可视化 安全
基于DWA优化算法的机器人路径规划matlab仿真
本项目基于DWA优化算法实现机器人路径规划的MATLAB仿真,适用于动态环境下的自主导航。使用MATLAB2022A版本运行,展示路径规划和预测结果。核心代码通过散点图和轨迹图可视化路径点及预测路径。DWA算法通过定义速度空间、采样候选动作并评估其优劣(目标方向性、障碍物距离、速度一致性),实时调整机器人运动参数,确保安全避障并接近目标。
149 68
|
1天前
|
算法 安全 机器人
基于包围盒的机械臂防碰撞算法matlab仿真
基于包围盒的机械臂防碰撞算法通过构建包围盒来近似表示机械臂及其环境中各实体的空间占用,检测包围盒是否相交以预判并规避潜在碰撞风险。该算法适用于复杂结构对象,通过细分目标对象并逐级检测,确保操作安全。系统采用MATLAB2022a开发,仿真结果显示其有效性。此技术广泛应用于机器人运动规划与控制领域,确保机器人在复杂环境中的安全作业。
|
1天前
|
机器学习/深度学习 数据采集 算法
基于WOA鲸鱼优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目基于MATLAB 2022a实现时间序列预测,采用CNN-GRU-SAM网络结构,结合鲸鱼优化算法(WOA)优化网络参数。核心代码含操作视频,运行效果无水印。算法通过卷积层提取局部特征,GRU层处理长期依赖,自注意力机制捕捉全局特征,全连接层整合输出。数据预处理后,使用WOA迭代优化,最终输出最优预测结果。
|
4天前
|
算法
基于SOA海鸥优化算法的三维曲面最高点搜索matlab仿真
本程序基于海鸥优化算法(SOA)进行三维曲面最高点搜索的MATLAB仿真,输出收敛曲线和搜索结果。使用MATLAB2022A版本运行,核心代码实现种群初始化、适应度计算、交叉变异等操作。SOA模拟海鸥觅食行为,通过搜索飞行、跟随飞行和掠食飞行三种策略高效探索解空间,找到全局最优解。
|
1月前
|
算法 数据安全/隐私保护
室内障碍物射线追踪算法matlab模拟仿真
### 简介 本项目展示了室内障碍物射线追踪算法在无线通信中的应用。通过Matlab 2022a实现,包含完整程序运行效果(无水印),支持增加发射点和室内墙壁设置。核心代码配有详细中文注释及操作视频。该算法基于几何光学原理,模拟信号在复杂室内环境中的传播路径与强度,涵盖场景建模、射线发射、传播及接收点场强计算等步骤,为无线网络规划提供重要依据。
|
2天前
|
传感器 算法
基于GA遗传算法的多机无源定位系统GDOP优化matlab仿真
本项目基于遗传算法(GA)优化多机无源定位系统的GDOP,使用MATLAB2022A进行仿真。通过遗传算法的选择、交叉和变异操作,迭代优化传感器配置,最小化GDOP值,提高定位精度。仿真输出包括GDOP优化结果、遗传算法收敛曲线及三维空间坐标点分布图。核心程序实现了染色体编码、适应度评估、遗传操作等关键步骤,最终展示优化后的传感器布局及其性能。
|
4天前
|
算法 数据可视化 数据安全/隐私保护
一级倒立摆平衡控制系统MATLAB仿真,可显示倒立摆平衡动画,对比极点配置,线性二次型,PID,PI及PD五种算法
本课题基于MATLAB对一级倒立摆控制系统进行升级仿真,增加了PI、PD控制器,并对比了极点配置、线性二次型、PID、PI及PD五种算法的控制效果。通过GUI界面显示倒立摆动画和控制输出曲线,展示了不同控制器在偏转角和小车位移变化上的性能差异。理论部分介绍了倒立摆系统的力学模型,包括小车和杆的动力学方程。核心程序实现了不同控制算法的选择与仿真结果的可视化。
32 15

热门文章

最新文章