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