annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@tabular_kernel/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 tabular CPD to one or more potentials
Daniel@0 3 % pot = convert_to_pot(CPD, pot_type, domain, evidence)
Daniel@0 4
Daniel@0 5 % This is the same as discrete_CPD/convert_to_pot,
Daniel@0 6 % except we didn't want to the kernel to inherit methods like sample_node etc.
Daniel@0 7
Daniel@0 8 sz = CPD.sz;
Daniel@0 9 ns = zeros(1, max(domain));
Daniel@0 10 ns(domain) = sz;
Daniel@0 11
Daniel@0 12 odom = domain(~isemptycell(evidence(domain)));
Daniel@0 13 T = convert_to_table(CPD, domain, evidence);
Daniel@0 14
Daniel@0 15 switch pot_type
Daniel@0 16 case 'u',
Daniel@0 17 pot = upot(domain, sz, T, 0*myones(sz));
Daniel@0 18 case 'd',
Daniel@0 19 ns(odom) = 1;
Daniel@0 20 pot = dpot(domain, ns(domain), T);
Daniel@0 21 case 'c',
Daniel@0 22 % Since we want the output to be a Gaussian, the whole family must be observed.
Daniel@0 23 % In other words, the potential is really just a constant.
Daniel@0 24 p = T.p;
Daniel@0 25 %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1)));
Daniel@0 26 ns(domain) = 0;
Daniel@0 27 pot = cpot(domain, ns(domain), log(p));
Daniel@0 28 case 'cg',
Daniel@0 29 T = T(:);
Daniel@0 30 ns(odom) = 1;
Daniel@0 31 can = cell(1, length(T));
Daniel@0 32 for i=1:length(T)
Daniel@0 33 can{i} = cpot([], [], log(T(i)));
Daniel@0 34 end
Daniel@0 35 pot = cgpot(domain, [], ns, can);
Daniel@0 36 end
Daniel@0 37