annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@gmux_CPD/convert_to_pot.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 pot = convert_to_pot(CPD, pot_type, domain, evidence)
wolffd@0 2 % CONVERT_TO_POT Convert a gmux CPD to a Gaussian potential
wolffd@0 3 % pot = convert_to_pot(CPD, pot_type, domain, evidence)
wolffd@0 4
wolffd@0 5 switch pot_type
wolffd@0 6 case {'d', 'u', 'cg', 'scg'},
wolffd@0 7 error(['can''t convert gmux to potential of type ' pot_type])
wolffd@0 8
wolffd@0 9 case {'c','g'},
wolffd@0 10 % We create a large weight matrix with zeros in all blocks corresponding
wolffd@0 11 % to the non-chosen parents, since they are effectively disconnected.
wolffd@0 12 % The chosen parent is determined by the value, m, of the discrete parent.
wolffd@0 13 % Thus the potential is as large as the whole family.
wolffd@0 14 ps = domain(1:end-1);
wolffd@0 15 dps = ps(CPD.dps); % CPD.dps is an index, not a node number (because of param tying)
wolffd@0 16 cps = ps(CPD.cps);
wolffd@0 17 m = evidence{dps};
wolffd@0 18 if isempty(m)
wolffd@0 19 error('gmux node must have observed discrete parent')
wolffd@0 20 end
wolffd@0 21 bs = CPD.sizes(CPD.cps);
wolffd@0 22 b = block(m, bs);
wolffd@0 23 sum_cpsz = sum(CPD.sizes(CPD.cps));
wolffd@0 24 selfsz = CPD.sizes(end);
wolffd@0 25 W = zeros(selfsz, sum_cpsz);
wolffd@0 26 W(:,b) = CPD.weights(:,:,m);
wolffd@0 27
wolffd@0 28 ns = zeros(1, max(domain));
wolffd@0 29 ns(domain) = CPD.sizes;
wolffd@0 30 self = domain(end);
wolffd@0 31 cdom = [cps(:)' self];
wolffd@0 32 pot = linear_gaussian_to_cpot(CPD.mean(:,m), CPD.cov(:,:,m), W, domain, ns, cdom, evidence);
wolffd@0 33
wolffd@0 34 otherwise,
wolffd@0 35 error(['unrecognized pot_type' pot_type])
wolffd@0 36 end
wolffd@0 37