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