annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@discrete_CPD/Old/convert_to_table.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 T = convert_to_table(CPD, domain, local_ev, obs_bitv)
wolffd@0 2 % CONVERT_TO_TABLE Convert a discrete CPD to a table
wolffd@0 3 % function T = convert_to_table(CPD, domain, local_ev, obs_bitv)
wolffd@0 4 %
wolffd@0 5 % We convert the CPD to a CPT, and then lookup the evidence on the discrete parents.
wolffd@0 6 % The resulting table can easily be converted to a potential.
wolffd@0 7
wolffd@0 8
wolffd@0 9 CPT = CPD_to_CPT(CPD);
wolffd@0 10 obs_child_only = ~any(obs_bitv(1:end-1)) & obs_bitv(end);
wolffd@0 11
wolffd@0 12 if obs_child_only
wolffd@0 13 sz = size(CPT);
wolffd@0 14 CPT = reshape(CPT, prod(sz(1:end-1)), sz(end));
wolffd@0 15 o = local_ev{end};
wolffd@0 16 T = CPT(:, o);
wolffd@0 17 else
wolffd@0 18 odom = domain(obs_bitv);
wolffd@0 19 vals = cat(1, local_ev{find(obs_bitv)}); % undo cell array
wolffd@0 20 map = find_equiv_posns(odom, domain);
wolffd@0 21 index = mk_multi_index(length(domain), map, vals);
wolffd@0 22 T = CPT(index{:});
wolffd@0 23 end