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