【问题标题】:Matlab: PDF from a Markov ChainMatlab:来自马尔可夫链的 PDF
【发布时间】:2013-05-23 15:21:19
【问题描述】:

我已经使用 Matlab 生成了马尔可夫链。从生成的马尔可夫链中,我需要计算概率密度函数 (PDF)。

  • 我该怎么做?
    我应该在任何 PDF 函数中直接使用生成的马尔可夫链吗?

    我应该在找到 PDF 之前对数据进行任何预处理吗?

马尔可夫链是使用以下代码生成的:

%  x     = the quantity corresponding to each state, typical element x(i)
%  P     = Markov transition matrix, typical element p(i,j) i,j=1,...n
%  pi0   = probability distribution over initial state
%  T     = number of periods to simulate 
%  chain = sequence of realizations from the simulation

n = length(x); % what is the size of the state vector?
E = rand(1,T); % T-vector of draws from independent uniform [0,1]  

cumsumP = P*triu(ones(size(P)));
E0   = rand(1,1);
ppi0 = [0,cumsum(pi0)];
s0   = ((E0<=ppi0(2:n+1)).*(E0>ppi0(1:n)))';
s    = s0; 

for t=1:T,
state(:,t) = s;
ppi        = [0,s'*cumsumP];
s          = ((E(t)<=ppi(2:n+1)).*(E(t)>ppi(1:n)))';
end

chain = x'*state;    

生成马尔可夫链后,我需要计算概率密度。

  • 如何使用 Matlab 求概率密度?

【问题讨论】:

  • 你看过 Matlab 的pdf-function 吗?它是statistics toolbox 的一部分。
  • @Schorsch ya,我使用了 pdf 函数 'ksdensity' 如下, [f,xi] = ksdensity(chain,bins,'function','PDF');对吗?
  • 如果不具体说明您遇到的情况,很难说您对kdensity 的使用是否正确。它确实看起来像example on mathworks

标签: matlab markov-chains


【解决方案1】:

如果您将状态作为向量 chain 中的单个值,您可以简单地制作直方图并对其进行规范化。

chainPdf = hist(chain) / length(chain);

您可能需要在致电hist 时指定垃圾箱或垃圾箱中心的数量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    相关资源
    最近更新 更多