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