Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/potentials/@cpot/cpot_to_mpot.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 mom = cpot_to_mpot(can) |
wolffd@0 | 2 % CPOT_TO_MPOT Convert a canonical potential to moment form. |
wolffd@0 | 3 % mom = cpot_to_mpot(can) |
wolffd@0 | 4 |
wolffd@0 | 5 [logp, mu, Sigma] = canonical_to_moment(can.g, can.h, can.K); |
wolffd@0 | 6 mom = mpot(can.domain, can.sizes, logp, mu, Sigma); |
wolffd@0 | 7 |
wolffd@0 | 8 %%%%%%% |
wolffd@0 | 9 |
wolffd@0 | 10 function [logp, mu, Sigma] = canonical_to_moment(g, h, K) |
wolffd@0 | 11 % CANONICAL_TO_MOMENT Convert canonical characteristics to moment form. |
wolffd@0 | 12 % [logp, mu, Sigma] = canonical_to_moment(g, h, K) |
wolffd@0 | 13 |
wolffd@0 | 14 n = length(K); |
wolffd@0 | 15 if isempty(K) |
wolffd@0 | 16 logp = g - 0.5*(log(det(K)) - n*log(2*pi)); |
wolffd@0 | 17 Sigma = []; |
wolffd@0 | 18 mu = []; |
wolffd@0 | 19 else |
wolffd@0 | 20 if det(K)==0 |
wolffd@0 | 21 Sigma = inf*ones(n,n); |
wolffd@0 | 22 mu = zeros(n,1); % if the precision is zero, the mean is arbitrary |
wolffd@0 | 23 logp = g; % the scaling factor for the uniform distribution is 1 |
wolffd@0 | 24 else |
wolffd@0 | 25 Sigma = inv(K); |
wolffd@0 | 26 mu = Sigma*h; |
wolffd@0 | 27 logp = g - 0.5*(log(det(K)) - n*log(2*pi) - mu'*K*mu); |
wolffd@0 | 28 end |
wolffd@0 | 29 end |