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