separate MPE method in Hybrid Bayes Net/Tree

release/4.3a0
Varun Agrawal 2025-01-20 15:19:10 -05:00
parent d5f304ef50
commit 8460452990
4 changed files with 31 additions and 6 deletions

View File

@ -124,7 +124,7 @@ GaussianBayesNet HybridBayesNet::choose(
} }
/* ************************************************************************* */ /* ************************************************************************* */
HybridValues HybridBayesNet::optimize() const { DiscreteValues HybridBayesNet::mpe() const {
// Collect all the discrete factors to compute MPE // Collect all the discrete factors to compute MPE
DiscreteFactorGraph discrete_fg; DiscreteFactorGraph discrete_fg;
@ -140,9 +140,13 @@ HybridValues HybridBayesNet::optimize() const {
} }
} }
} }
return discrete_fg.optimize();
}
/* ************************************************************************* */
HybridValues HybridBayesNet::optimize() const {
// Solve for the MPE // Solve for the MPE
DiscreteValues mpe = discrete_fg.optimize(); DiscreteValues mpe = this->mpe();
// Given the MPE, compute the optimal continuous values. // Given the MPE, compute the optimal continuous values.
return HybridValues(optimize(mpe), mpe); return HybridValues(optimize(mpe), mpe);

View File

@ -146,6 +146,14 @@ class GTSAM_EXPORT HybridBayesNet : public BayesNet<HybridConditional> {
return evaluate(values); return evaluate(values);
} }
/**
* @brief Compute the Most Probable Explanation (MPE)
* of the discrete variables.
*
* @return DiscreteValues
*/
DiscreteValues mpe() const;
/** /**
* @brief Solve the HybridBayesNet by first computing the MPE of all the * @brief Solve the HybridBayesNet by first computing the MPE of all the
* discrete variables and then optimizing the continuous variables based on * discrete variables and then optimizing the continuous variables based on

View File

@ -59,7 +59,7 @@ DiscreteValues HybridBayesTree::discreteMaxProduct(
} }
/* ************************************************************************* */ /* ************************************************************************* */
HybridValues HybridBayesTree::optimize() const { DiscreteValues HybridBayesTree::mpe() const {
DiscreteFactorGraph discrete_fg; DiscreteFactorGraph discrete_fg;
DiscreteValues mpe; DiscreteValues mpe;
@ -73,11 +73,16 @@ HybridValues HybridBayesTree::optimize() const {
discrete_fg.push_back(discrete); discrete_fg.push_back(discrete);
mpe = discreteMaxProduct(discrete_fg); mpe = discreteMaxProduct(discrete_fg);
} else { } else {
throw std::runtime_error( mpe = DiscreteValues();
"HybridBayesTree root is not discrete-only. Please check elimination "
"ordering or use continuous factor graph.");
} }
return mpe;
}
/* ************************************************************************* */
HybridValues HybridBayesTree::optimize() const {
DiscreteValues mpe = this->mpe();
VectorValues values = optimize(mpe); VectorValues values = optimize(mpe);
return HybridValues(values, mpe); return HybridValues(values, mpe);
} }

View File

@ -105,6 +105,14 @@ class GTSAM_EXPORT HybridBayesTree : public BayesTree<HybridBayesTreeClique> {
*/ */
VectorValues optimize(const DiscreteValues& assignment) const; VectorValues optimize(const DiscreteValues& assignment) const;
/**
* @brief Compute the Most Probable Explanation (MPE)
* of the discrete variables.
*
* @return DiscreteValues
*/
DiscreteValues mpe() const;
/** /**
* @brief Prune the underlying Bayes tree. * @brief Prune the underlying Bayes tree.
* *