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

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function pot = recursive_combine_pots(pot1, pot2)
wolffd@0 2 % RECURSIVE_COMBINE_POTS recursive combine two potentials
wolffd@0 3 % pot = recursive_combine_pots(pot1, pot2)
wolffd@0 4
wolffd@0 5 pot1 = reduce_pot(pot1);
wolffd@0 6 pot2 = reduce_pot(pot2);
wolffd@0 7 % Recursion is stopped, if recusive-combination is defined by direct combination,
wolffd@0 8 % i.e. if the domain of one potential is disjoint from the head of the other.
wolffd@0 9 if (isempty(myintersect(pot1.domain,pot2.cheaddom))|...
wolffd@0 10 isempty(myintersect(pot1.cheaddom,pot2.domain)))
wolffd@0 11 pot = direct_combine_pots(pot1,pot2);
wolffd@0 12 else
wolffd@0 13 % Test wether one of the set-differences is not empty
wolffd@0 14 % as defined in Lauritzen99 "Stable Local Computation with Conditional Gaussian Distributions"
wolffd@0 15 % on page 9
wolffd@0 16 D12 = mysetdiff(pot1.cheaddom, pot2.domain);
wolffd@0 17 D21 = mysetdiff(pot2.cheaddom, pot1.domain);
wolffd@0 18 if (isempty(D12) & isempty(D21))
wolffd@0 19 assert(0,'Recursive combination is not defined');
wolffd@0 20 end
wolffd@0 21
wolffd@0 22 if ~isempty(D12)
wolffd@0 23 % Calculate the complementary potential for the set
wolffd@0 24 % D1\D12 as defined in Lauritzen 99, page 9
wolffd@0 25 keep = mysetdiff(pot1.domain,D12);
wolffd@0 26 [margpot, comppot] = complement_pot(pot1,keep);
wolffd@0 27 margpot = reduce_pot(margpot);
wolffd@0 28 comppot = reduce_pot(comppot);
wolffd@0 29 pot = direct_combine_pots( recursive_combine_pots(margpot, pot2), comppot);
wolffd@0 30 elseif ~isempty(D21)
wolffd@0 31 keep = mysetdiff(pot2.domain,D21);
wolffd@0 32 [margpot, comppot] = complement_pot(pot2,D21);
wolffd@0 33 margpot = reduce_pot(margpot);
wolffd@0 34 comppot = reduce_pot(comppot);
wolffd@0 35 pot = direct_combine_pots( recursive_combine_pots(pot1, margpot), comppot);
wolffd@0 36 end
wolffd@0 37 end
wolffd@0 38
wolffd@0 39
wolffd@0 40