annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@discrete_CPD/Old/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 % pots = convert_to_pot(CPD, pot_type, domain, evidence)
Daniel@0 4 %
Daniel@0 5 % pots{i} = CPD evaluated using evidence(domain(:,i))
Daniel@0 6 % If 'domains' is a single row vector, pots will be an object, not a cell array.
Daniel@0 7
Daniel@0 8 ncases = size(domain,2);
Daniel@0 9 assert(ncases==1); % not yet vectorized
Daniel@0 10
Daniel@0 11 sz = dom_sizes(CPD);
Daniel@0 12 ns = zeros(1, max(domain));
Daniel@0 13 ns(domain) = sz;
Daniel@0 14
Daniel@0 15 local_ev = evidence(domain);
Daniel@0 16 obs_bitv = ~isemptycell(local_ev);
Daniel@0 17 odom = domain(obs_bitv);
Daniel@0 18 T = convert_to_table(CPD, domain, local_ev, obs_bitv);
Daniel@0 19
Daniel@0 20 switch pot_type
Daniel@0 21 case 'u',
Daniel@0 22 pot = upot(domain, sz, T, 0*myones(sz));
Daniel@0 23 case 'd',
Daniel@0 24 ns(odom) = 1;
Daniel@0 25 pot = dpot(domain, ns(domain), T);
Daniel@0 26 case {'c','g'},
Daniel@0 27 % Since we want the output to be a Gaussian, the whole family must be observed.
Daniel@0 28 % In other words, the potential is really just a constant.
Daniel@0 29 p = T;
Daniel@0 30 %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1)));
Daniel@0 31 ns(domain) = 0;
Daniel@0 32 pot = cpot(domain, ns(domain), log(p));
Daniel@0 33 case 'cg',
Daniel@0 34 T = T(:);
Daniel@0 35 ns(odom) = 1;
Daniel@0 36 can = cell(1, length(T));
Daniel@0 37 for i=1:length(T)
Daniel@0 38 can{i} = cpot([], [], log(T(i)));
Daniel@0 39 end
Daniel@0 40 pot = cgpot(domain, [], ns, can);
Daniel@0 41 otherwise,
Daniel@0 42 error(['unrecognized pot type ' pot_type])
Daniel@0 43 end
Daniel@0 44