Fixed BayesTree joint marginals for the case of joints across disjoint trees in a forest

release/4.3a0
Richard Roberts 2013-08-16 21:24:34 +00:00
parent ce9e9b4a91
commit 5dcfa04eb1
1 changed files with 62 additions and 50 deletions

View File

@ -321,10 +321,13 @@ namespace gtsam {
++p2;
}
}
if(!B)
throw std::invalid_argument("BayesTree::jointBayesNet does not yet work for joints across a forest");
gttoc(Lowest_common_ancestor);
// Build joint on all involved variables
FactorGraphType p_BC1C2;
if(B)
{
// Compute marginal on lowest common ancestor clique
gttic(LCA_marginal);
FactorGraphType p_B = B->marginal2(function);
@ -366,8 +369,6 @@ namespace gtsam {
gttoc(Full_root_factoring);
gttic(Variable_joint);
// Build joint on all involved variables
FactorGraphType p_BC1C2;
p_BC1C2 += p_B;
p_BC1C2 += *p_C1_B;
p_BC1C2 += *p_C2_B;
@ -375,6 +376,17 @@ namespace gtsam {
p_BC1C2 += C1->conditional();
if(C2 != B)
p_BC1C2 += C2->conditional();
gttoc(Variable_joint);
}
else
{
// The nodes have no common ancestor, they're in different trees, so they're joint is just the
// product of their marginals.
gttic(Disjoint_marginals);
p_BC1C2 += C1->marginal2(function);
p_BC1C2 += C2->marginal2(function);
gttoc(Disjoint_marginals);
}
// now, marginalize out everything that is not variable j1 or j2
return p_BC1C2.marginalMultifrontalBayesNet(Ordering(cref_list_of<2,Key>(j1)(j2)), boost::none, function);