Daniel@0: function CPD = maximize_params(CPD, temp) Daniel@0: % MAXIMIZE_PARAMS Set the params of a CPD to their ML values (Gaussian) Daniel@0: % CPD = maximize_params(CPD, temperature) Daniel@0: % Daniel@0: % Temperature is currently ignored. Daniel@0: Daniel@0: if ~adjustable_CPD(CPD), return; end Daniel@0: Daniel@0: Daniel@0: if CPD.clamped_mean Daniel@0: cl_mean = CPD.mean; Daniel@0: else Daniel@0: cl_mean = []; Daniel@0: end Daniel@0: Daniel@0: if CPD.clamped_cov Daniel@0: cl_cov = CPD.cov; Daniel@0: else Daniel@0: cl_cov = []; Daniel@0: end Daniel@0: Daniel@0: if CPD.clamped_weights Daniel@0: cl_weights = CPD.weights; Daniel@0: else Daniel@0: cl_weights = []; Daniel@0: end Daniel@0: Daniel@0: [ssz psz Q] = size(CPD.weights); Daniel@0: Daniel@0: [ss cpsz dpsz] = size(CPD.weights); % ss = self size = ssz Daniel@0: if cpsz > CPD.nsamples Daniel@0: fprintf('gaussian_CPD/maximize_params: warning: input dimension (%d) > nsamples (%d)\n', ... Daniel@0: cpsz, CPD.nsamples); Daniel@0: end Daniel@0: Daniel@0: prior = repmat(CPD.cov_prior_weight*eye(ssz,ssz), [1 1 Q]); Daniel@0: Daniel@0: Daniel@0: [CPD.mean, CPD.cov, CPD.weights] = ... Daniel@0: clg_Mstep(CPD.Wsum, CPD.WYsum, CPD.WYYsum, [], CPD.WXsum, CPD.WXXsum, CPD.WXYsum, ... Daniel@0: 'cov_type', CPD.cov_type, 'clamped_mean', cl_mean, ... Daniel@0: 'clamped_cov', cl_cov, 'clamped_weights', cl_weights, ... Daniel@0: 'tied_cov', CPD.tied_cov, ... Daniel@0: 'cov_prior', prior); Daniel@0: Daniel@0: if 0 Daniel@0: CPD.mean = reshape(CPD.mean, [ss dpsz]); Daniel@0: CPD.cov = reshape(CPD.cov, [ss ss dpsz]); Daniel@0: CPD.weights = reshape(CPD.weights, [ss cpsz dpsz]); Daniel@0: end Daniel@0: Daniel@0: % Bug fix 11 May 2003 KPM Daniel@0: % clg_Mstep collapses all discrete parents into one mega-node Daniel@0: % but convert_to_CPT needs access to each parent separately Daniel@0: sz = CPD.sizes; Daniel@0: ss = sz(end); Daniel@0: Daniel@0: % Bug fix KPM 20 May 2003: Daniel@0: cpsz = sum(sz(CPD.cps)); Daniel@0: %if isempty(CPD.cps) Daniel@0: % cpsz = 0; Daniel@0: %else Daniel@0: % cpsz = sz(CPD.cps); Daniel@0: %end Daniel@0: dpsz = sz(CPD.dps); Daniel@0: CPD.mean = myreshape(CPD.mean, [ss dpsz]); Daniel@0: CPD.cov = myreshape(CPD.cov, [ss ss dpsz]); Daniel@0: CPD.weights = myreshape(CPD.weights, [ss cpsz dpsz]);