simplify to remove DiscreteProduct static function

release/4.3a0
Varun Agrawal 2025-01-05 14:03:08 -05:00
parent 260d448887
commit 453059bd61
1 changed files with 17 additions and 27 deletions

View File

@ -65,11 +65,23 @@ namespace gtsam {
/* ************************************************************************ */
DecisionTreeFactor DiscreteFactorGraph::product() const {
DiscreteFactor::shared_ptr result = *this->begin();
// PRODUCT: multiply all factors
gttic(product);
DiscreteFactor::shared_ptr product = *this->begin();
for (auto it = this->begin() + 1; it != this->end(); ++it) {
if (*it) result = result->multiply(*it);
if (*it) product = product->multiply(*it);
}
return result->toDecisionTreeFactor();
gttoc(product);
DecisionTreeFactor = result->toDecisionTreeFactor();
// Max over all the potentials by pretending all keys are frontal:
auto denominator = product.max(product.size());
// Normalize the product factor to prevent underflow.
product = product / (*denominator);
return product;
}
/* ************************************************************************ */
@ -111,34 +123,12 @@ namespace gtsam {
// }
// }
/**
* @brief Multiply all the `factors`.
*
* @param factors The factors to multiply as a DiscreteFactorGraph.
* @return DecisionTreeFactor
*/
static DecisionTreeFactor DiscreteProduct(
const DiscreteFactorGraph& factors) {
// PRODUCT: multiply all factors
gttic(product);
DecisionTreeFactor product = factors.product();
gttoc(product);
// Max over all the potentials by pretending all keys are frontal:
auto denominator = product.max(product.size());
// Normalize the product factor to prevent underflow.
product = product / (*denominator);
return product;
}
/* ************************************************************************ */
// Alternate eliminate function for MPE
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
EliminateForMPE(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys) {
DecisionTreeFactor product = DiscreteProduct(factors);
DecisionTreeFactor product = factors.product();
// max out frontals, this is the factor on the separator
gttic(max);
@ -216,7 +206,7 @@ namespace gtsam {
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
EliminateDiscrete(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys) {
DecisionTreeFactor product = DiscreteProduct(factors);
DecisionTreeFactor product = factors.product();
// sum out frontals, this is the factor on the separator
gttic(sum);