annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@hhmmQ_CPD/maximize_params.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function CPD = maximize_params(CPD, temp)
wolffd@0 2 % MAXIMIZE_PARAMS Set the params of a hhmmQ node to their ML/MAP values.
wolffd@0 3 % CPD = maximize_params(CPD, temperature)
wolffd@0 4
wolffd@0 5 Qsz = CPD.Qsz;
wolffd@0 6 Qpsz = CPD.Qpsz;
wolffd@0 7
wolffd@0 8 if ~isempty(CPD.sub_CPD_start)
wolffd@0 9 CPD.sub_CPD_start = maximize_params(CPD.sub_CPD_start, temp);
wolffd@0 10 S = struct(CPD.sub_CPD_start);
wolffd@0 11 CPD.startprob = myreshape(S.CPT, [Qpsz Qsz]);
wolffd@0 12 %CPD.startprob = S.CPT;
wolffd@0 13 end
wolffd@0 14
wolffd@0 15 if 1
wolffd@0 16 % If we are in a state that can only go the end state,
wolffd@0 17 % we will never see a transition to another (non-end) state,
wolffd@0 18 % so counts(i,k,j)=0 (and termprob(k,i)=1).
wolffd@0 19 % We set counts(i,k,i)=1 in this case.
wolffd@0 20 % This will cause remove_hhmm_end_state to return a
wolffd@0 21 % stochastic matrix, but otherwise has no effect on EM.
wolffd@0 22 counts = get_field(CPD.sub_CPD_trans, 'counts');
wolffd@0 23 counts = reshape(counts, [Qsz Qpsz Qsz]);
wolffd@0 24 for k=1:Qpsz
wolffd@0 25 for i=1:Qsz
wolffd@0 26 if sum(counts(i,k,:))==0 % never witnessed a transition out of i
wolffd@0 27 counts(i,k,i)=1; % add self loop
wolffd@0 28 %fprintf('CPDQ d=%d i=%d k=%d\n', CPD.d, i, k);
wolffd@0 29 end
wolffd@0 30 end
wolffd@0 31 end
wolffd@0 32 CPD.sub_CPD_trans = set_fields(CPD.sub_CPD_trans, 'counts', counts(:));
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 CPD.sub_CPD_trans = maximize_params(CPD.sub_CPD_trans, temp);
wolffd@0 36 S = struct(CPD.sub_CPD_trans);
wolffd@0 37 %CPD.transprob = S.CPT;
wolffd@0 38 CPD.transprob = myreshape(S.CPT, [Qsz Qpsz Qsz]);
wolffd@0 39
wolffd@0 40 CPD = update_CPT(CPD);