6

我有 11 个状态和一个转移概率矩阵,但我没有排放,因为我的模型没有隐藏。它仅包含状态 (1,2,3, ..., 11)
我想根据我的转移概率矩阵生成随机状态,但 HMM 工具箱需要一个发射概率矩阵。我应该怎么办?

[seq, states] = hmmgenerate(100, Trans, Emis) 
4

1 回答 1

7

考虑以下:

%# number of states
N = 11;

%# some random transition matrix
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));

%# fake emission matrix (only one symbol)
emis = ones(N,1);

%# get a sample of length = 10
[~,states] = hmmgenerate(10, trans, emis)

产生的状态序列:

>> states
states =
    10     1     3    11     9     4    11     1     4     6

编辑:

事实上,使用马尔可夫链相对容易,我们可以自己做。这是另一个不使用统计工具箱中的 HMM 函数的示例。

%# number of states
N = 3;

%# transition matrix
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));

%# probability of being in state i at time t=0
prior = rand(1,N);
prior = prior ./ sum(prior);

%# generate a sequence of states
len = 100;          %# length of sequence
states = zeros(1,len);
states(1) = randsample(N, 1, true, prior);
for t=2:len
    states(t) = randsample(N, 1, true, trans(states(t-1),:));
end

%# show sequence
stairs(states, 'LineWidth',2)
set(gca, 'YGrid','on', 'YLim',[0 N+1])
xlabel('time'), ylabel('states')
title('sequence of states')

状态序列

我使用 RANDSAMPLE 函数在每次迭代时进行采样。如果您只想使用核心函数(没有工具箱),请参阅MATLAB 中的加权随机数以获得替代方法。

于 2012-06-15T19:08:43.847 回答