?? online_em.m
字號:
function [transmat, obsmat, exp_num_trans, exp_num_emit, gamma, ll] = online_em(... prior, transmat, obsmat, exp_num_trans, exp_num_emit, decay, data, ... act, adj_trans, adj_obs, dirichlet, filter_only)% ONLINE_EM Adjust the parameters using a weighted combination of the old and new expected statistics%% [transmat, obsmat, exp_num_trans, exp_num_emit, gamma, ll] = online_em(...% prior, transmat, obsmat, exp_num_trans, exp_num_emit, decay, data, act, ...% adj_trans, adj_obs, dirichlet, filter_only)% % 0 < decay < 1, with smaller values meaning the past is forgotten more quickly.% (We need to decay the old ess, since they were based on out-of-date parameters.)% The other params are as in learn_hmm.% We do a single forwards-backwards pass on the provided data, initializing with the specified prior.% (If filter_only = 1, we only do a forwards pass.)if ~exist('act'), act = []; endif ~exist('adj_trans'), adj_trans = 1; endif ~exist('adj_obs'), adj_obs = 1; endif ~exist('dirichlet'), dirichlet = 0; endif ~exist('filter_only'), filter_only = 0; end% E stepolikseq = mk_dhmm_obs_lik(data, obsmat);if isempty(act) [alpha, beta, gamma, xi, ll] = forwards_backwards(prior, transmat, olikseq, filter_only);else [alpha, beta, gamma, xi, ll] = forwards_backwards(prior, transmat, olikseq, [], [], act, filter_only);end% Increment ESS[S O] = size(obsmat);if adj_obs exp_num_emit = decay*exp_num_emit + dirichlet*ones(S,O); T = length(data); if T < O for t=1:T o = data(t); exp_num_emit(:,o) = exp_num_emit(:,o) + gamma(:,t); end else for o=1:O ndx = find(data==o); if ~isempty(ndx) exp_num_emit(:,o) = exp_num_emit(:,o) + sum(gamma(:, ndx), 2); end end endendif adj_trans & (T > 1) if isempty(act) exp_num_trans = decay*exp_num_trans + sum(xi,3); else % act(2) determines Q(2), xi(:,:,1) holds P(Q(1), Q(2)) A = length(transmat); for a=1:A ndx = find(act(2:end)==a); if ~isempty(ndx) exp_num_trans{a} = decay*exp_num_trans{a} + sum(xi(:,:,ndx), 3); end end endend% M stepif adj_obs obsmat = mk_stochastic(exp_num_emit);endif adj_trans & (T>1) if isempty(act) transmat = mk_stochastic(exp_num_trans); else for a=1:A transmat{a} = mk_stochastic(exp_num_trans{a}); end endend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -