基于MCMC、差分进化马尔可夫链、集成卡尔曼滤波器、近似贝叶斯计算研究(Matlab代码实现)

 👨‍🎓个人主页:研学社的博客   

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

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

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

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

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

function DEMCD

ifferential Evolution / Differential Evolution Markov Chain. In the case of 'DE',this function also plot a figure for the objective function of all generations.Input fields

  • func : evaluation (objective) function.
  • bound : 2 X n matrix, where n is the parameter dimension. Lower (first row) and upper(second row) bounds of parameter.
  • size : size of population.
  • life : maximum generation of population.
  • funcPrior :(optional) prior distribution function to generate first generation. Default is uninformative prior within bounds.
  • type :(optional) 'DE' or 'DEMC'. The former seek the global minimum, the later maps the posterior. Default is 'DEMC'.
  • greedy :(optional) logical scalar, faster convergence but less stable. Breaks detailed balance and should not be used with 'DEMC'.
  • logFlag :(optional) logical scalar, use log liklihood or not. Default is 'false'.
  • mutation :(optional) scalar, mutation rate.
  • CR :(optional) scalar, crossover rate.
  • simplex :(optional) 1 X n logical maxtrix. 'true' specifies the parameters that should be positive and sum up to 1.
  • name :(optional) name of output figure. Default 'DEMCtest'.

Output fields

  • chain : population at each generation.
  • obj : evaluation (objective) function value at each generation.
  • best : best individual at last generation.

function MCMC

Markov Chain Monte Carlo with Random-Walk Metropolis.

Input fields

One of 'loc', 'funcPrior', 'bound'(in descending priority) must be specified.

  • life : length of Markov Chain.
  • func : liklihood function. Calculates the liklihood from parameter.
  • funcProp : (optional) proposal distribution function. Make new proposal
  • according to parameter. Default is normal distribution with sigma = 1.
  • loc : (optional) initial parameter.
  • funcPrior : (optional) prior function to generate initial parameter.
  • bound : (optional) 2 X n matrix, where n is the parameter dimension.
  • Lower(first row) and upper(second row) bounds of parameter.

Output fields

  • chain : m X n matrix, where m = length and n = parameter dimension.
  • time : m X 1 matrix, time stamp of each step.

Warning : Using 'bound' might break detailed balance and result in gibberish posterior. Not recommended.

function EnKF

Ensemble Kalman filter. Updated forecast and analysis states using observation and ensemble Kalman filter.

Input fields

  • R : measurement error (sigma).
  • Fstates : forecast states. 1 X n matrix, n = number of state
  • Astates : analysis states. 1 X n matrix.
  • obs : observation states. Scaler.
  • func : model operator, from current state to next state.

Output

The same structue with updated Fstates and Astates, as well as estimation of model error (C).

function ModAv

Multi-model averaging function. Supported methods:

  • EWA : Equal Weights Averaging
  • BGA : Bates-Granger Averaging
  • AICA : Akaike's Information Criterion Averaging
  • BICA : Bayes Information Criterion Averaging
  • GRA : Granger-Ramanathan Averaging
  • BMA : Bayesian Model Averaging
  • MMA : Mallows Model Averaging
  • MMAd : Mallows Model Averaging (lie on simplex)

Input fields

  • Xcali : m1 X n model prediction matrix for calibration period. m1 = time
  • length of calibration period, n = model number.
  • Ycali : m1 X 1 observation matrix for calibration period.
  • Xeval : m2 X n model prediction matrix for evaluation period.
  • Yeval : m2 X 1 observation matrix for evaluation period.
  • p : 1 X n matrix of model parameter numbers.
  • method : abbreviation of method.

Output fields

  • weight : model weights.
  • RMSEcali : RMSE of calibration period.
  • RMSEeval : RMSE of evaluation period.
  • chain : (BMA, MMA and MMAd) model weights in all iterations.
  • obj : (BMA, MMA and MMAd) objective function value for all iterations.
  • sigma : (BMA) optimized model sigma.

Warning: Method BMA could be slow and unstable.

function ABCPMC

Approximate Bayesian Computing-Population Monte Carlo method.

Input fields

  • obs : 1 X d, d = dimension of target
  • bound : 2 X n matrix, where n is the parameter dimension. Lower
  • (first row) and upper(second row) bounds of parameter.
  • funcPrior : prior distribution function to generate parameter.
  • funcSummar : function to model target from parameter.
  • funcDist : function to calculate distance between modeled and observed
  • target.
  • epsl : 1 X i epsilon matrix, where i is the number of generations.
  • size : population size

Output

The same strucuture with extra fields.

  • inds : individuals (parameters) for all generations.
  • summar : modeled target at all generations.
  • weight : weight matrix for all generations.
  • C : Covariance matrix for all geneations.
  • acRate : overall acceptance rate.

📚2 运行结果

 

部分代码:

%% Set default proposal distribution function to normal distribution.
if ~isfield(bead,'funcProp')
    bead.funcProp = @ (x) normrnd(x,1);
end

%% Retrive bead.loc and bead.dms (parameter dimension)
if ~isfield(bead,'loc')
    if isfield(bead,'funcPrior')
        bead.loc = bead.funcPrior();
    else
        bead.dms = size(bead.bound,2);
        bead.loc = rand(1,bead.dms)*(bead.bound(2,:)-bead.bound(1,:))+...
            bead.bound(1,:);
    end 
end
bead.dms = numel(bead.loc);

%% Create empty matrixes
rng('shuffle');
result.chain = NaN(bead.life, bead.dms);
result.time = NaN(bead.life, 1);

%% Initialize the first bead 
bead.p = bead.func(bead.loc);
bead.gen = 1;

%% Start Markov Chian and record
tic;
result.chain(bead.gen) = bead.loc;
result.time(bead.gen) = toc;
while bead.gen<=bead.life
    bead = RWM(bead);
    result.chain(bead.gen) = bead.loc;
    result.time(bead.gen) = toc;
end
end

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]赵国强,鞠敏,刘丹丹,邓金涛,袁文文.基于卡尔曼滤波的坡度估算及验证[J].汽车电器,2022(12):68-69+72.DOI:10.13273/j.cnki.qcdq.2022.12.027.

🌈4 Matlab代码实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
您可以使用以下的MATLAB代码实现马尔可夫链模型: ``` format rat clc, clear a = [4 3 2 1 4 3 1 1 2 3 2 1 2 3 4 4 3 3 1 1 1 3 3 2 1 2 2 2 4 4 2 3 2 3 1 1 2 4 3 1]; % 计算状态转移矩阵 f = zeros(4, 4); for i = 1:4 for j = 1:4 f(i,j) = length(findstr([i j], a)); end end ni = sum(f'); p = zeros(4, 4); for i = 1:4 p(i,:) = f(i,:) / ni(i); end p ``` 这段代码首先定义了观测序列a,然后计算了状态转移矩阵p。具体的计算过程可以参考引用中提供的MATLAB代码。在此代码中,使用了循环来遍历观测序列a,并计算每个状态之间的转移次数。然后,通过归一化转移次数得到了状态转移概率矩阵p。 这个代码可以在MATLAB环境中运行,通过输出p可以得到马尔可夫链的状态转移概率矩阵。如果您对马尔可夫链的定义和应用有兴趣,可以参考引用和中提供的链接了解更多信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MATLAB 马尔可夫链](https://blog.csdn.net/qq_63585949/article/details/128940019)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [MATLAB-马尔可夫链(马氏链)模型](https://blog.csdn.net/Hou_____/article/details/125708173)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Matlab 马尔可夫链预测双色球](https://blog.csdn.net/weixin_43979311/article/details/102636564)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

荔枝科研社

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

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

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

打赏作者

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

抵扣说明:

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

余额充值