资源简介
隐马尔科夫模型的Matlab代码,里面有多钟变形的隐马尔科夫模型
代码片段和文件信息
function [LL prior transmat obsmat nrIterations] = ...
dhmm_em(data prior transmat obsmat varargin)
% LEARN_DHMM Find the ML/MAP parameters of an HMM with discrete outputs using EM.
% [ll_trace prior transmat obsmat iterNr] = learn_dhmm(data prior0 transmat0 obsmat0 ...)
%
% Notation: Q(t) = hidden state Y(t) = observation
%
% INPUTS:
% data{ex} or data(ex:) if all sequences have the same length
% prior(i)
% transmat(ij)
% obsmat(io)
%
% Optional parameters may be passed as ‘param_name‘ param_value pairs.
% Parameter names are shown below; default values in [] - if none argument is mandatory.
%
% ‘max_iter‘ - max number of EM iterations [10]
% ‘thresh‘ - convergence threshold [1e-4]
% ‘verbose‘ - if 1 print out loglik at every iteration [1]
% ‘obs_prior_weight‘ - weight to apply to uniform dirichlet prior on observation matrix [0]
%
% To clamp some of the parameters so learning does not change them:
% ‘adj_prior‘ - if 0 do not change prior [1]
% ‘adj_trans‘ - if 0 do not change transmat [1]
% ‘adj_obs‘ - if 0 do not change obsmat [1]
%
% Modified by Herbert Jaeger so xi are not computed individually
% but only their sum (over time) as xi_summed; this is the only way how they are used
% and it saves a lot of memory.
[max_iter thresh verbose obs_prior_weight adj_prior adj_trans adj_obs] = ...
process_options(varargin ‘max_iter‘ 10 ‘thresh‘ 1e-4 ‘verbose‘ 1 ...
‘obs_prior_weight‘ 0 ‘adj_prior‘ 1 ‘adj_trans‘ 1 ‘adj_obs‘ 1);
previous_loglik = -inf;
loglik = 0;
converged = 0;
num_iter = 1;
LL = [];
if ~iscell(data)
data = num2cell(data 2); % each row gets its own cell
end
while (num_iter <= max_iter) & ~converged
% E step
[loglik exp_num_trans exp_num_visits1 exp_num_emit] = ...
compute_ess_dhmm(prior transmat obsmat data obs_prior_weight);
% M step
if adj_prior
prior = normalise(exp_num_visits1);
end
if adj_trans & ~isempty(exp_num_trans)
transmat = mk_stochastic(exp_num_trans);
end
if adj_obs
obsmat = mk_stochastic(exp_num_emit);
end
if verbose fprintf(1 ‘iteration %d loglik = %f\n‘ num_iter loglik); end
num_iter = num_iter + 1;
converged = em_converged(loglik previous_loglik thresh);
previous_loglik = loglik;
LL = [LL loglik];
end
nrIterations = num_iter - 1;
%%%%%%%%%%%%%%%%%%%%%%%
function [loglik exp_num_trans exp_num_visits1 exp_num_emit exp_num_visitsT] = ...
compute_ess_dhmm(startprob transmat obsmat data dirichlet)
% COMPUTE_ESS_DHMM Compute the Expected Sufficient Statistics for an HMM with discrete outputs
% function [loglik exp_num_trans exp_num_visits1 exp_num_emit exp_num_visitsT] = ...
% compute_ess_dhmm(startprob transmat obsmat data dirichlet)
%
% INPUTS:
% startprob(i)
% transmat(ij)
% obsmat(io)
% data{seq}(t)
% dirichlet - weighting term for uniform dirichlet prior on expected emissions
%
% OUTPUTS:
% exp_num_trans(ij) = sum_l sum_{t=2}^T Pr(X(t-1) = i X(t) = j| Obs(l))
% exp_num_vis
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2006-07-10 21:57 HMMall\HMM\
文件 6896 2006-02-17 19:51 HMMall\HMM\#fwdback.m#
文件 5589 2006-02-16 18:49 HMMall\HMM\#mhmm_em.m#
文件 550 2005-06-08 18:22 HMMall\HMM\#README.txt#
文件 4081 2005-06-08 18:25 HMMall\HMM\dhmm_em.m
文件 687 2003-05-04 15:01 HMMall\HMM\dhmm_em_demo.m
文件 2376 2003-05-04 15:02 HMMall\HMM\dhmm_em_online.m
文件 2249 2003-05-04 15:04 HMMall\HMM\dhmm_em_online_demo.m
文件 640 2003-05-04 15:01 HMMall\HMM\dhmm_logprob.m
文件 552 2002-05-29 08:59 HMMall\HMM\dhmm_logprob_brute_force.m
文件 448 2002-05-29 08:59 HMMall\HMM\dhmm_logprob_path.m
文件 408 2004-05-31 15:19 HMMall\HMM\dhmm_sample.m
文件 622 2003-05-04 15:00 HMMall\HMM\dhmm_sample_endstate.m
文件 2096 2003-01-22 09:56 HMMall\HMM\fixed_lag_smoother.m
文件 987 2005-06-08 18:27 HMMall\HMM\fixed_lag_smoother_demo.m
文件 6896 2006-02-17 19:51 HMMall\HMM\fwdback.m
文件 6518 2006-02-16 18:30 HMMall\HMM\fwdback.m~
文件 6642 2005-12-08 23:41 HMMall\HMM\fwdback_xi.m
文件 1899 2006-02-23 14:34 HMMall\HMM\fwdprop_backsample.m
文件 1898 2006-02-22 11:15 HMMall\HMM\fwdprop_backsample.m~
文件 1561 2004-02-12 15:08 HMMall\HMM\gausshmm_train_observed.m
文件 10449 2005-05-12 09:52 HMMall\HMM\herbert.txt~
文件 442 2004-05-24 15:26 HMMall\HMM\mc_sample.m
文件 711 2003-01-22 12:32 HMMall\HMM\mc_sample_endstate.m
文件 490 2002-05-29 08:59 HMMall\HMM\mdp_sample.m
文件 1203 2004-02-13 18:06 HMMall\HMM\mhmmParzen_train_observed.m
文件 5610 2006-02-16 18:55 HMMall\HMM\mhmm_em.m
文件 5562 2004-02-07 20:52 HMMall\HMM\mhmm_em.m~
文件 1013 2003-05-13 09:11 HMMall\HMM\mhmm_em_demo.m
文件 960 2003-05-04 15:11 HMMall\HMM\mhmm_logprob.m
文件 1071 2004-05-25 17:32 HMMall\HMM\mhmm_sample.m
............此处省略468个文件信息
- 上一篇:基于dct的数字音频水印
- 下一篇:FCM聚类算法,可直接matlab运行
评论
共有 条评论