annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@gaussian_CPD/maximize_params.m @ 0:cc4b1211e677 tip

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