wolffd@0: function [pot, loglik] = normalize_pot(pot) wolffd@0: % NORMALIZE_POT Convert the CG potential Pr(X,E) into Pr(X|E) and return log Pr(E). wolffd@0: % [pot, loglik] = normalize_pot(pot) wolffd@0: wolffd@0: % Marginalize down to [], so that the normalizing constant becomes Pr(E) wolffd@0: temp = marginalize_pot(cg_can_to_mom(pot), []); wolffd@0: %loglik = temp.mom{1}.logp; wolffd@0: [temp2, loglik] = normalize_pot(temp.mom{1}); wolffd@0: wolffd@0: % Adjust scale factor to reflect the fact that the pot now represents Pr(X | E) instead of Pr(X,E). wolffd@0: wolffd@0: scale = -loglik; wolffd@0: if 1 wolffd@0: switch pot.subtype wolffd@0: case 'm' wolffd@0: for i=1:pot.dsize wolffd@0: pot.mom{i} = rescale_pot(pot.mom{i}, scale); wolffd@0: end wolffd@0: case 'c' wolffd@0: for i=1:pot.dsize wolffd@0: pot.can{i} = rescale_pot(pot.can{i}, scale); wolffd@0: end wolffd@0: end wolffd@0: end