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