wolffd@0: function pot = recursive_combine_pots(pot1, pot2) wolffd@0: % RECURSIVE_COMBINE_POTS recursive combine two potentials wolffd@0: % pot = recursive_combine_pots(pot1, pot2) wolffd@0: wolffd@0: pot1 = reduce_pot(pot1); wolffd@0: pot2 = reduce_pot(pot2); wolffd@0: % Recursion is stopped, if recusive-combination is defined by direct combination, wolffd@0: % i.e. if the domain of one potential is disjoint from the head of the other. wolffd@0: if (isempty(myintersect(pot1.domain,pot2.cheaddom))|... wolffd@0: isempty(myintersect(pot1.cheaddom,pot2.domain))) wolffd@0: pot = direct_combine_pots(pot1,pot2); wolffd@0: else wolffd@0: % Test wether one of the set-differences is not empty wolffd@0: % as defined in Lauritzen99 "Stable Local Computation with Conditional Gaussian Distributions" wolffd@0: % on page 9 wolffd@0: D12 = mysetdiff(pot1.cheaddom, pot2.domain); wolffd@0: D21 = mysetdiff(pot2.cheaddom, pot1.domain); wolffd@0: if (isempty(D12) & isempty(D21)) wolffd@0: assert(0,'Recursive combination is not defined'); wolffd@0: end wolffd@0: wolffd@0: if ~isempty(D12) wolffd@0: % Calculate the complementary potential for the set wolffd@0: % D1\D12 as defined in Lauritzen 99, page 9 wolffd@0: keep = mysetdiff(pot1.domain,D12); wolffd@0: [margpot, comppot] = complement_pot(pot1,keep); wolffd@0: margpot = reduce_pot(margpot); wolffd@0: comppot = reduce_pot(comppot); wolffd@0: pot = direct_combine_pots( recursive_combine_pots(margpot, pot2), comppot); wolffd@0: elseif ~isempty(D21) wolffd@0: keep = mysetdiff(pot2.domain,D21); wolffd@0: [margpot, comppot] = complement_pot(pot2,D21); wolffd@0: margpot = reduce_pot(margpot); wolffd@0: comppot = reduce_pot(comppot); wolffd@0: pot = direct_combine_pots( recursive_combine_pots(pot1, margpot), comppot); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: