To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / CPDs / @hhmmQ_CPD / maximize_params.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.27 KB)

1
function CPD = maximize_params(CPD, temp)
2
% MAXIMIZE_PARAMS Set the params of a hhmmQ node to their ML/MAP values.
3
% CPD = maximize_params(CPD, temperature)
4

    
5
Qsz = CPD.Qsz;
6
Qpsz = CPD.Qpsz;
7

    
8
if ~isempty(CPD.sub_CPD_start)
9
  CPD.sub_CPD_start = maximize_params(CPD.sub_CPD_start, temp);
10
  S = struct(CPD.sub_CPD_start);
11
  CPD.startprob = myreshape(S.CPT, [Qpsz Qsz]);
12
  %CPD.startprob = S.CPT;
13
end
14

    
15
if 1
16
  % If we are in a state that can only go the end state,
17
  % we will never see a transition to another (non-end) state,
18
  % so counts(i,k,j)=0 (and termprob(k,i)=1).
19
  % We set counts(i,k,i)=1 in this case.
20
  % This will cause remove_hhmm_end_state to return a
21
  % stochastic matrix, but otherwise has no effect on EM.
22
  counts = get_field(CPD.sub_CPD_trans, 'counts');
23
  counts = reshape(counts, [Qsz Qpsz Qsz]);
24
  for k=1:Qpsz
25
    for i=1:Qsz
26
      if sum(counts(i,k,:))==0 % never witnessed a transition out of i
27
	counts(i,k,i)=1; % add self loop 
28
	%fprintf('CPDQ d=%d i=%d k=%d\n', CPD.d, i, k);
29
      end
30
    end
31
  end
32
  CPD.sub_CPD_trans = set_fields(CPD.sub_CPD_trans, 'counts', counts(:)); 
33
end
34
 
35
CPD.sub_CPD_trans = maximize_params(CPD.sub_CPD_trans, temp);
36
S = struct(CPD.sub_CPD_trans);
37
%CPD.transprob = S.CPT;
38
CPD.transprob = myreshape(S.CPT, [Qsz Qpsz Qsz]);
39

    
40
CPD = update_CPT(CPD);