wolffd@0
|
1 function CPD = maximize_params(CPD, temp)
|
wolffd@0
|
2 % MAXIMIZE_PARAMS Set the params of a CPD to their ML values (Gaussian)
|
wolffd@0
|
3 % CPD = maximize_params(CPD, temperature)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % Temperature is currently ignored.
|
wolffd@0
|
6
|
wolffd@0
|
7 if ~adjustable_CPD(CPD), return; end
|
wolffd@0
|
8
|
wolffd@0
|
9
|
wolffd@0
|
10 if CPD.clamped_mean
|
wolffd@0
|
11 cl_mean = CPD.mean;
|
wolffd@0
|
12 else
|
wolffd@0
|
13 cl_mean = [];
|
wolffd@0
|
14 end
|
wolffd@0
|
15
|
wolffd@0
|
16 if CPD.clamped_cov
|
wolffd@0
|
17 cl_cov = CPD.cov;
|
wolffd@0
|
18 else
|
wolffd@0
|
19 cl_cov = [];
|
wolffd@0
|
20 end
|
wolffd@0
|
21
|
wolffd@0
|
22 if CPD.clamped_weights
|
wolffd@0
|
23 cl_weights = CPD.weights;
|
wolffd@0
|
24 else
|
wolffd@0
|
25 cl_weights = [];
|
wolffd@0
|
26 end
|
wolffd@0
|
27
|
wolffd@0
|
28 [ssz psz Q] = size(CPD.weights);
|
wolffd@0
|
29
|
wolffd@0
|
30 [ss cpsz dpsz] = size(CPD.weights); % ss = self size = ssz
|
wolffd@0
|
31 if cpsz > CPD.nsamples
|
wolffd@0
|
32 fprintf('gaussian_CPD/maximize_params: warning: input dimension (%d) > nsamples (%d)\n', ...
|
wolffd@0
|
33 cpsz, CPD.nsamples);
|
wolffd@0
|
34 end
|
wolffd@0
|
35
|
wolffd@0
|
36 prior = repmat(CPD.cov_prior_weight*eye(ssz,ssz), [1 1 Q]);
|
wolffd@0
|
37
|
wolffd@0
|
38
|
wolffd@0
|
39 [CPD.mean, CPD.cov, CPD.weights] = ...
|
wolffd@0
|
40 clg_Mstep(CPD.Wsum, CPD.WYsum, CPD.WYYsum, [], CPD.WXsum, CPD.WXXsum, CPD.WXYsum, ...
|
wolffd@0
|
41 'cov_type', CPD.cov_type, 'clamped_mean', cl_mean, ...
|
wolffd@0
|
42 'clamped_cov', cl_cov, 'clamped_weights', cl_weights, ...
|
wolffd@0
|
43 'tied_cov', CPD.tied_cov, ...
|
wolffd@0
|
44 'cov_prior', prior);
|
wolffd@0
|
45
|
wolffd@0
|
46 if 0
|
wolffd@0
|
47 CPD.mean = reshape(CPD.mean, [ss dpsz]);
|
wolffd@0
|
48 CPD.cov = reshape(CPD.cov, [ss ss dpsz]);
|
wolffd@0
|
49 CPD.weights = reshape(CPD.weights, [ss cpsz dpsz]);
|
wolffd@0
|
50 end
|
wolffd@0
|
51
|
wolffd@0
|
52 % Bug fix 11 May 2003 KPM
|
wolffd@0
|
53 % clg_Mstep collapses all discrete parents into one mega-node
|
wolffd@0
|
54 % but convert_to_CPT needs access to each parent separately
|
wolffd@0
|
55 sz = CPD.sizes;
|
wolffd@0
|
56 ss = sz(end);
|
wolffd@0
|
57
|
wolffd@0
|
58 % Bug fix KPM 20 May 2003:
|
wolffd@0
|
59 cpsz = sum(sz(CPD.cps));
|
wolffd@0
|
60 %if isempty(CPD.cps)
|
wolffd@0
|
61 % cpsz = 0;
|
wolffd@0
|
62 %else
|
wolffd@0
|
63 % cpsz = sz(CPD.cps);
|
wolffd@0
|
64 %end
|
wolffd@0
|
65 dpsz = sz(CPD.dps);
|
wolffd@0
|
66 CPD.mean = myreshape(CPD.mean, [ss dpsz]);
|
wolffd@0
|
67 CPD.cov = myreshape(CPD.cov, [ss ss dpsz]);
|
wolffd@0
|
68 CPD.weights = myreshape(CPD.weights, [ss cpsz dpsz]);
|