wolffd@0: function pot = convert_to_pot(CPD, pot_type, domain, evidence) wolffd@0: % CONVERT_TO_POT Convert a tabular CPD to one or more potentials wolffd@0: % pot = convert_to_pot(CPD, pot_type, domain, evidence) wolffd@0: wolffd@0: % This is the same as discrete_CPD/convert_to_pot, wolffd@0: % except we didn't want to the kernel to inherit methods like sample_node etc. wolffd@0: wolffd@0: sz = CPD.sz; wolffd@0: ns = zeros(1, max(domain)); wolffd@0: ns(domain) = sz; wolffd@0: wolffd@0: odom = domain(~isemptycell(evidence(domain))); wolffd@0: T = convert_to_table(CPD, domain, evidence); wolffd@0: wolffd@0: switch pot_type wolffd@0: case 'u', wolffd@0: pot = upot(domain, sz, T, 0*myones(sz)); wolffd@0: case 'd', wolffd@0: ns(odom) = 1; wolffd@0: pot = dpot(domain, ns(domain), T); wolffd@0: case 'c', wolffd@0: % Since we want the output to be a Gaussian, the whole family must be observed. wolffd@0: % In other words, the potential is really just a constant. wolffd@0: p = T.p; wolffd@0: %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1))); wolffd@0: ns(domain) = 0; wolffd@0: pot = cpot(domain, ns(domain), log(p)); wolffd@0: case 'cg', wolffd@0: T = T(:); wolffd@0: ns(odom) = 1; wolffd@0: can = cell(1, length(T)); wolffd@0: for i=1:length(T) wolffd@0: can{i} = cpot([], [], log(T(i))); wolffd@0: end wolffd@0: pot = cgpot(domain, [], ns, can); wolffd@0: end wolffd@0: