annotate toolboxes/FullBNT-1.0.7/bnt/potentials/@scgpot/recursive_combine_pots.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function pot = recursive_combine_pots(pot1, pot2)
Daniel@0 2 % RECURSIVE_COMBINE_POTS recursive combine two potentials
Daniel@0 3 % pot = recursive_combine_pots(pot1, pot2)
Daniel@0 4
Daniel@0 5 pot1 = reduce_pot(pot1);
Daniel@0 6 pot2 = reduce_pot(pot2);
Daniel@0 7 % Recursion is stopped, if recusive-combination is defined by direct combination,
Daniel@0 8 % i.e. if the domain of one potential is disjoint from the head of the other.
Daniel@0 9 if (isempty(myintersect(pot1.domain,pot2.cheaddom))|...
Daniel@0 10 isempty(myintersect(pot1.cheaddom,pot2.domain)))
Daniel@0 11 pot = direct_combine_pots(pot1,pot2);
Daniel@0 12 else
Daniel@0 13 % Test wether one of the set-differences is not empty
Daniel@0 14 % as defined in Lauritzen99 "Stable Local Computation with Conditional Gaussian Distributions"
Daniel@0 15 % on page 9
Daniel@0 16 D12 = mysetdiff(pot1.cheaddom, pot2.domain);
Daniel@0 17 D21 = mysetdiff(pot2.cheaddom, pot1.domain);
Daniel@0 18 if (isempty(D12) & isempty(D21))
Daniel@0 19 assert(0,'Recursive combination is not defined');
Daniel@0 20 end
Daniel@0 21
Daniel@0 22 if ~isempty(D12)
Daniel@0 23 % Calculate the complementary potential for the set
Daniel@0 24 % D1\D12 as defined in Lauritzen 99, page 9
Daniel@0 25 keep = mysetdiff(pot1.domain,D12);
Daniel@0 26 [margpot, comppot] = complement_pot(pot1,keep);
Daniel@0 27 margpot = reduce_pot(margpot);
Daniel@0 28 comppot = reduce_pot(comppot);
Daniel@0 29 pot = direct_combine_pots( recursive_combine_pots(margpot, pot2), comppot);
Daniel@0 30 elseif ~isempty(D21)
Daniel@0 31 keep = mysetdiff(pot2.domain,D21);
Daniel@0 32 [margpot, comppot] = complement_pot(pot2,D21);
Daniel@0 33 margpot = reduce_pot(margpot);
Daniel@0 34 comppot = reduce_pot(comppot);
Daniel@0 35 pot = direct_combine_pots( recursive_combine_pots(pot1, margpot), comppot);
Daniel@0 36 end
Daniel@0 37 end
Daniel@0 38
Daniel@0 39
Daniel@0 40