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