custom path for empty separator
parent
e49b40b4c4
commit
bb4ee207b8
|
@ -341,41 +341,40 @@ discreteElimination(const HybridGaussianFactorGraph &factors,
|
||||||
#if GTSAM_HYBRID_TIMING
|
#if GTSAM_HYBRID_TIMING
|
||||||
gttic_(EliminateDiscrete);
|
gttic_(EliminateDiscrete);
|
||||||
#endif
|
#endif
|
||||||
/**** NOTE: This does sum-product. ****/
|
// Check if separator is empty
|
||||||
// Get product factor
|
Ordering allKeys(dfg.keyVector());
|
||||||
TableFactor product = ProductAndNormalize(dfg);
|
Ordering separator;
|
||||||
|
std::set_difference(allKeys.begin(), allKeys.end(), frontalKeys.begin(),
|
||||||
|
frontalKeys.end(),
|
||||||
|
std::inserter(separator, separator.begin()));
|
||||||
|
|
||||||
|
// If the separator is empty, we have a clique of all the discrete variables
|
||||||
|
// so we can use the TableFactor for efficiency.
|
||||||
|
if (separator.size() == 0) {
|
||||||
|
// Get product factor
|
||||||
|
TableFactor product = ProductAndNormalize(dfg);
|
||||||
|
|
||||||
#if GTSAM_HYBRID_TIMING
|
#if GTSAM_HYBRID_TIMING
|
||||||
gttic_(EliminateDiscreteSum);
|
gttic_(EliminateDiscreteFormDiscreteConditional);
|
||||||
#endif
|
#endif
|
||||||
// All the discrete variables should form a single clique,
|
auto conditional = std::make_shared<DiscreteConditional>(
|
||||||
// so we can sum out on all the variables as frontals.
|
frontalKeys.size(), product.toDecisionTreeFactor());
|
||||||
// This should give an empty separator.
|
|
||||||
TableFactor::shared_ptr sum = product.sum(frontalKeys);
|
|
||||||
#if GTSAM_HYBRID_TIMING
|
#if GTSAM_HYBRID_TIMING
|
||||||
gttoc_(EliminateDiscreteSum);
|
gttoc_(EliminateDiscreteFormDiscreteConditional);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Ordering keys for the conditional so that frontalKeys are really in front
|
TableFactor::shared_ptr sum = product.sum(frontalKeys);
|
||||||
Ordering orderedKeys;
|
|
||||||
orderedKeys.insert(orderedKeys.end(), frontalKeys.begin(), frontalKeys.end());
|
|
||||||
orderedKeys.insert(orderedKeys.end(), sum->keys().begin(), sum->keys().end());
|
|
||||||
|
|
||||||
#if GTSAM_HYBRID_TIMING
|
#if GTSAM_HYBRID_TIMING
|
||||||
gttic_(EliminateDiscreteFormDiscreteConditional);
|
gttoc_(EliminateDiscrete);
|
||||||
#endif
|
|
||||||
auto c = product / (*sum);
|
|
||||||
auto conditional = std::make_shared<DiscreteConditional>(
|
|
||||||
frontalKeys.size(), c.toDecisionTreeFactor(), orderedKeys);
|
|
||||||
#if GTSAM_HYBRID_TIMING
|
|
||||||
gttoc_(EliminateDiscreteFormDiscreteConditional);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GTSAM_HYBRID_TIMING
|
return {std::make_shared<HybridConditional>(conditional), sum};
|
||||||
gttoc_(EliminateDiscrete);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return {std::make_shared<HybridConditional>(conditional), sum};
|
} else {
|
||||||
|
// Perform sum-product.
|
||||||
|
auto result = EliminateDiscrete(dfg, frontalKeys);
|
||||||
|
return {std::make_shared<HybridConditional>(result.first), result.second};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
Loading…
Reference in New Issue