Daniel@0: function pot = convert_to_pot(CPD, pot_type, domain, evidence) Daniel@0: % CONVERT_TO_POT Convert a gmux CPD to a Gaussian potential Daniel@0: % pot = convert_to_pot(CPD, pot_type, domain, evidence) Daniel@0: Daniel@0: switch pot_type Daniel@0: case {'d', 'u', 'cg', 'scg'}, Daniel@0: error(['can''t convert gmux to potential of type ' pot_type]) Daniel@0: Daniel@0: case {'c','g'}, Daniel@0: % We create a large weight matrix with zeros in all blocks corresponding Daniel@0: % to the non-chosen parents, since they are effectively disconnected. Daniel@0: % The chosen parent is determined by the value, m, of the discrete parent. Daniel@0: % Thus the potential is as large as the whole family. Daniel@0: ps = domain(1:end-1); Daniel@0: dps = ps(CPD.dps); % CPD.dps is an index, not a node number (because of param tying) Daniel@0: cps = ps(CPD.cps); Daniel@0: m = evidence{dps}; Daniel@0: if isempty(m) Daniel@0: error('gmux node must have observed discrete parent') Daniel@0: end Daniel@0: bs = CPD.sizes(CPD.cps); Daniel@0: b = block(m, bs); Daniel@0: sum_cpsz = sum(CPD.sizes(CPD.cps)); Daniel@0: selfsz = CPD.sizes(end); Daniel@0: W = zeros(selfsz, sum_cpsz); Daniel@0: W(:,b) = CPD.weights(:,:,m); Daniel@0: Daniel@0: ns = zeros(1, max(domain)); Daniel@0: ns(domain) = CPD.sizes; Daniel@0: self = domain(end); Daniel@0: cdom = [cps(:)' self]; Daniel@0: pot = linear_gaussian_to_cpot(CPD.mean(:,m), CPD.cov(:,:,m), W, domain, ns, cdom, evidence); Daniel@0: Daniel@0: otherwise, Daniel@0: error(['unrecognized pot_type' pot_type]) Daniel@0: end Daniel@0: