annotate toolboxes/FullBNT-1.0.7/bnt/potentials/@mpot/mpot_to_cpot.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 can = mpot_to_cpot(mom)
wolffd@0 2 % MPOT_TO_CPOT Convert a moment potential to canonical form.
wolffd@0 3 % mom = mpot_to_cpot(can)
wolffd@0 4
wolffd@0 5 [g, h, K] = moment_to_canonical(mom.logp, mom.mu, mom.Sigma);
wolffd@0 6 can = cpot(mom.domain, mom.sizes, g, h, K);
wolffd@0 7
wolffd@0 8 %%%%%%%%%%%
wolffd@0 9
wolffd@0 10 function [g, h, K] = moment_to_canonical(logp, mu, Sigma)
wolffd@0 11 % MOMENT_TO_CANONICAL Convert moment characteristics to canonical form.
wolffd@0 12 % [g, h, K] = moment_to_canonical(logp, mu, Sigma)
wolffd@0 13
wolffd@0 14 K = inv(Sigma);
wolffd@0 15 h = K*mu;
wolffd@0 16 n = length(K);
wolffd@0 17 if isempty(mu)
wolffd@0 18 g = logp + 0.5*(log(det(K)) - n*log(2*pi));
wolffd@0 19 else
wolffd@0 20 g = logp + 0.5*(log(det(K)) - n*log(2*pi) - mu'*K*mu);
wolffd@0 21 end