Daniel@0: function pot = convert_to_pot(CPD, pot_type, domain, evidence) Daniel@0: % CONVERT_TO_POT Convert a softmax CPD to a potential Daniel@0: % pots = convert_to_pot(CPD, pot_type, domain, evidence) Daniel@0: % Daniel@0: % pots = CPD evaluated using evidence(domain) Daniel@0: Daniel@0: ncases = size(domain,2); Daniel@0: assert(ncases==1); % not yet vectorized Daniel@0: Daniel@0: sz = dom_sizes(CPD); 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: Daniel@0: case {'c','g'}, 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; 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: 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: ps = domain(1:end-1); Daniel@0: dps = ps(CPD.dpndx); Daniel@0: cps = ps(CPD.cpndx); Daniel@0: ddom = [dps CPD.self]; Daniel@0: cdom = cps; Daniel@0: pot = cgpot(ddom, cdom, ns, can); Daniel@0: Daniel@0: case 'scg' Daniel@0: T = T(:); Daniel@0: ns(odom) = 1; Daniel@0: pot_array = cell(1, length(T)); Daniel@0: for i=1:length(T) Daniel@0: pot_array{i} = scgcpot([], [], T(i)); Daniel@0: end Daniel@0: pot = scgpot(domain, [], [], ns, pot_array); Daniel@0: Daniel@0: otherwise, Daniel@0: error(['unrecognized pot type ' pot_type]) Daniel@0: end Daniel@0: