Revert "simplify to remove DiscreteProduct static function"
This reverts commit 453059bd61
.
release/4.3a0
parent
a02baec011
commit
13bafb0a48
|
@ -65,23 +65,11 @@ namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
DecisionTreeFactor DiscreteFactorGraph::product() const {
|
DecisionTreeFactor DiscreteFactorGraph::product() const {
|
||||||
// PRODUCT: multiply all factors
|
DiscreteFactor::shared_ptr result = *this->begin();
|
||||||
gttic(product);
|
|
||||||
DiscreteFactor::shared_ptr product = *this->begin();
|
|
||||||
for (auto it = this->begin() + 1; it != this->end(); ++it) {
|
for (auto it = this->begin() + 1; it != this->end(); ++it) {
|
||||||
if (*it) product = product->multiply(*it);
|
if (*it) result = result->multiply(*it);
|
||||||
}
|
}
|
||||||
gttoc(product);
|
return result->toDecisionTreeFactor();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
@ -123,12 +111,34 @@ 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
|
// Alternate eliminate function for MPE
|
||||||
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
||||||
EliminateForMPE(const DiscreteFactorGraph& factors,
|
EliminateForMPE(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys) {
|
const Ordering& frontalKeys) {
|
||||||
DecisionTreeFactor product = factors.product();
|
DecisionTreeFactor product = DiscreteProduct(factors);
|
||||||
|
|
||||||
// max out frontals, this is the factor on the separator
|
// max out frontals, this is the factor on the separator
|
||||||
gttic(max);
|
gttic(max);
|
||||||
|
@ -206,7 +216,7 @@ namespace gtsam {
|
||||||
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr> //
|
||||||
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
EliminateDiscrete(const DiscreteFactorGraph& factors,
|
||||||
const Ordering& frontalKeys) {
|
const Ordering& frontalKeys) {
|
||||||
DecisionTreeFactor product = factors.product();
|
DecisionTreeFactor product = DiscreteProduct(factors);
|
||||||
|
|
||||||
// sum out frontals, this is the factor on the separator
|
// sum out frontals, this is the factor on the separator
|
||||||
gttic(sum);
|
gttic(sum);
|
||||||
|
|
Loading…
Reference in New Issue