马尔可夫切换状态空间模型(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

马尔可夫切换状态空间模型(Markov Switching State Space Model)是一种用于描述随机过程的统计模型。它基于马尔可夫过程的概念,其中系统的状态在不同的时间段内可能发生切换。

在马尔可夫切换状态空间模型中,系统的状态由一个离散的隐变量表示,该隐变量可以在不同的状态之间切换。每个状态都对应着一个特定的观测值,这些观测值可以是连续的或离散的。

该模型的核心思想是,系统的状态在不同时间段内可能呈现出不同的动态行为。这种状态的切换可以由马尔可夫链来建模,其中状态的切换概率取决于当前状态和前一个状态。通过建立一个状态转移矩阵,可以描述系统在不同状态之间切换的概率。

马尔可夫切换状态空间模型在金融、经济学、生物学等领域中得到广泛应用。它可以用于描述经济周期的变化、金融市场的波动、生物学系统中的基因表达等动态过程。通过对系统状态的建模,可以更好地理解和预测这些复杂的现象。

本文用于通过最大可能性将马尔可夫切换状态空间模型 (SSM) 拟合到多变量时间序列数据。本文考虑了三种开关SSM:开关动力学,开关观察和切换矢量自回归(VAR)。最大似然估计器通过近似电磁算法计算。(精确的计算是不可处理的,因为可能的政权历史呈指数级,M^T与M是马尔可夫链的状态/政权数,T是时间序列的长度。为了使计算易于处理,本文在EM算法的E步中使用了Kim(1994)的过滤/平滑算法。

📚2 运行结果

主函数部分代码:

%=========================================================================%%           TOY EXAMPLE FOR MATLAB TOOLBOX 'switch-ssm'                   %%=========================================================================%clc; clearvars; close all;% This example is not calibrated to produce good statistical results,% it is simply meant to illustrate the toolbox functionalities.% The example demonstrates the toolbox functions for switching dynamics % models. The functions for the switching VAR and switching observations% models work exactly in the same way.%-------------------------------------------------------------------------%%               1) Simulate SSM with switching dynamics                   %%-------------------------------------------------------------------------%fprintf(['\n\n---------------\n',...    'DATA SIMULATION',...    '\n---------------\n\n']);% Model: % y(t) = C(S(t)) x(t) + w(t)                        (observation equation)% x(t) = A(1,S(t)) x(t-1) + ... + A(p,S(t)) x(t-p) + v(t) (state equation)% P(S(t)=j | S(t-1)=i) = Z(i,j)                          (regime equation)%@@@@@ Model dimensionsN = 5; % number of variablesT = 200; % number of time pointsM = 2; % number of regimesp = 2; % VAR orderr = 2; % factor dimensionfprintf('Model: switching dynamics\nM = %d\np = %d\nr = %d\n',...    M,p,r);%@@@@@@ Model parameters% VAR transition matrices A(l,j), l=1:p, j=1:M A = zeros(r,r,p,M); A(:,:,1,1) = 0.6 * eye(r);A(:,:,1,2) = 0.9 * eye(r);A(:,:,2,1) = 0.1 * eye(r);A(:,:,2,2) = -0.2 * eye(r);% Observation matrix [C,~,~] = svd(randn(N,r),'econ'); % Innovation variance/covariance V(v(t)|S(t)=j), j=1:M sigQ = .01;Q = repmat(sigQ * eye(r),[1,1,M]); % Noise variance/covariance matrix V(w(t))sigR = .005;R = sigR * eye(N);  % Initial mean of state vector E(x(1)|S(1)=j), j=1:M mu = zeros(r,M); % Initial variance/covariance V(x(1)|S(1)=j), j=1:MSigma = repmat(.02 * eye(r),[1,1,M]);% Initial probabilities  P(S(1)=j), j=1:MPi = repelem(1/M,M,1);% Transition probabilities P(S(t)=j | S(t-1)=i), i,j=1:MZ = [.98,.02;.02,.98];% Collect all model parameters in single structuretheta = struct('A',A, 'C',C, 'Q',Q, 'R',R, 'mu',mu, 'Sigma',Sigma, ...    'Pi',Pi, 'Z',Z);%@@@@@ Simulate datafprintf('Generating model... ')[y,S,x] = simulate_dyn(theta,T);% Visualize the datatiledlayout(3,1);nexttileplot(x');title("Hidden state vector")nexttileplot(y');title("Observed time series")nexttileplot(S,'*');title("Regimes")xlabel("Time")fprintf('Done') %%%-------------------------------------------------------------------------%%               2) Fit switching SSM to simulated data                    %%-------------------------------------------------------------------------%fprintf(['\n\n----------------\n',...    'MODEL ESTIMATION',...    '\n----------------\n\n']);% Minimal example (no algorithm tuning, no estimation constraints)% [Mf,Ms,Sf,Ss,xf,xs,theta,LL] = switch_dyn(y,M,p,r);  %@@@@@ More advanced example% Set the relative tolerance for convergence to 1e-6 (The EM will stop if% for 5 sucessive iterations, the relative change in log-likelihood is less% than 1e-6) and the maximum number of EM iterations to 500. Disable% progress display.control = struct('eps',1e-6,'ItrNo',500,'verbose',false);% Specify EM initialization method: use fixed intervals of length 50 to% estimate VAR parameters A and Q (one pair of estimate for each interval),% then cluster the parameter estimates by k-means and re-estimate A(j) and% Q(j) (j=1:M) over associated time segmentation opts = struct('segmentation','fixed','len',25); % Other initialization method: dichotomic segmentation (binary search for% change points in time series). Set minimal distance between change points % to 20% opts = struct('segmentation','binary','delta',20);% Set up equality constraints: force mu(j) and Sigma(j) to be equal% across regimes (j=1:M)equal = struct('mu',true,'Sigma',true); % Set up fixed coefficient constraints: make covariance matrices Q% and R diagonal (set off-diagonal terms to zero and leave other terms% unspecified as NaN)fixed = struct('Q',repmat(diag(NaN(r,1)),[1,1,M]),'R',diag(NaN(N,1)));% Force the columns of the observation matrix C to have Euclidean norm 1% and force the eigenvalues associated with VAR processes x(t) to be less% than .98 (for stationarity)scale = struct('A',.98,'C',1);% Initialize  EMfprintf('Calculating MLE... ')[thetahat0,S0] = init_dyn(y,M,p,r,opts,[],equal,fixed,scale); % Fix mu and Sigma to their pilot estimates (these parameters are usually% not relevant and fixing them can help the numerical stability of the EMfixed.mu = thetahat0.mu; fixed.Sigma = thetahat0.Sigma;% Run EM (first pass)[Mf,Ms,Sf,Ss,xf,xs,thetahat1,LL] = ...    switch_dyn(y,M,p,r,thetahat0,control,equal,fixed,scale); %#ok<*ASGLU>

🎉3 参考文献

[1]李强. 时滞马尔科夫切换复值神经网络的动力学分析[D].东南大学,2022.​

[1]叶志勇,王泽权,唐朝君等.基于离散时间观测带有马尔可夫切换的随机网络系统的反馈控制[J].重庆理工大学学报(自然科学),2019,33(08):222-226.

部分理论引用网络文献,若有侵权联系博主删除。

🌈4 Matlab代码实现

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值