MATLAB hmmtrain假设从状态1开始初始转换

时间:2012-03-20 14:10:48

标签: matlab hidden-markov-models

MATLAB统计工具箱函数hmmtrain.m似乎假设模型在训练序列之前最初处于状态1。有没有办法关闭这个“功能”?一个例子:

>> y = [ 3 3 1 2 3 ];
>> H = eye( 3 );
>> T = ones(3)/3;
>> [ T, H ] = hmmtrain( y, T, H )

T =

         0    0.5000    0.5000
         0         0    1.0000
    0.5000         0    0.5000


H =

     1     0     0
     0     1     0
     0     0     1

训练集不包括从1到3的过渡。为什么T(1,3)非零?!

1 个答案:

答案 0 :(得分:2)

我为hmmtrain编写了以下包装函数,它创建了一个仅用于模型初始状态的特殊状态1。从外部来电者的角度来看,它不存在,您只能获得训练序列符号之间转换的统计数据;它对系统的初始状态一无所知。

  % MYHMMTRAIN - Wrapper on HMMTRAIN that removes "initial state" effects

  function [ T, H ] = myhmmtrain( y, T, H, varargin )

  % hmmtrain assumes the system always starts in state 1, 
  % so we create a "state 1" that isn't used for anything else
  N = size(T,1);
  T = [ 0           ones(1,N)/N; ...
        zeros(N,1)  T ];
  M = size(H,2);
  H = [ zeros(1,M); H ];

  % train
  [ T, H ] = hmmtrain( y, T, H, varargin{:} );

  % remove false state 1
  T = T(2:end,2:end);
  H = H(2:end,:);

  end