mark helper methods as protected and add docstrings

release/4.3a0
Varun Agrawal 2022-12-04 18:21:57 +05:30
parent ae0b3e3902
commit bed56e0693
3 changed files with 59 additions and 35 deletions

View File

@ -73,6 +73,7 @@ class GTSAM_EXPORT HybridEliminationTree
/** Test whether the tree is equal to another */ /** Test whether the tree is equal to another */
bool equals(const This& other, double tol = 1e-9) const; bool equals(const This& other, double tol = 1e-9) const;
protected:
/** /**
* @brief Helper method to eliminate continuous variables. * @brief Helper method to eliminate continuous variables.
* *
@ -87,6 +88,22 @@ class GTSAM_EXPORT HybridEliminationTree
boost::shared_ptr<HybridGaussianFactorGraph>> boost::shared_ptr<HybridGaussianFactorGraph>>
eliminateContinuous(Eliminate function) const; eliminateContinuous(Eliminate function) const;
/**
* @brief Compute the unnormalized probability P'(X | M, Z)
* for the factor graph in each leaf of the discrete tree.
* The discrete decision tree formed as a result is added to the
* `discreteGraph` for discrete elimination.
*
* @param continuousBayesNet The bayes nets corresponding to
* the eliminated continuous variables.
* @param discreteGraph Factor graph consisting of factors
* on discrete variables only.
* @return boost::shared_ptr<HybridGaussianFactorGraph>
*/
boost::shared_ptr<HybridGaussianFactorGraph> addProbPrimes(
const HybridBayesNet::shared_ptr& continuousBayesNet,
const HybridGaussianFactorGraph::shared_ptr& discreteGraph) const;
/** /**
* @brief Helper method to eliminate the discrete variables after the * @brief Helper method to eliminate the discrete variables after the
* continuous variables have been eliminated. * continuous variables have been eliminated.
@ -105,6 +122,7 @@ class GTSAM_EXPORT HybridEliminationTree
Eliminate function, Eliminate function,
const HybridGaussianFactorGraph::shared_ptr& discreteGraph) const; const HybridGaussianFactorGraph::shared_ptr& discreteGraph) const;
public:
/** /**
* @brief Override the EliminationTree eliminate method * @brief Override the EliminationTree eliminate method
* so we can perform hybrid elimination correctly. * so we can perform hybrid elimination correctly.

View File

@ -252,11 +252,11 @@ HybridJunctionTree::eliminateDiscrete(
/* ************************************************************************* */ /* ************************************************************************* */
boost::shared_ptr<HybridGaussianFactorGraph> HybridJunctionTree::addProbPrimes( boost::shared_ptr<HybridGaussianFactorGraph> HybridJunctionTree::addProbPrimes(
const HybridGaussianFactorGraph& graph,
const HybridBayesTree::shared_ptr& continuousBayesTree, const HybridBayesTree::shared_ptr& continuousBayesTree,
const HybridGaussianFactorGraph::shared_ptr& discreteGraph, const HybridGaussianFactorGraph::shared_ptr& discreteGraph) const {
const Ordering& continuous_ordering, Ordering continuous_ordering = etree_.continuousOrdering();
const Ordering& discrete_ordering) const { Ordering discrete_ordering = etree_.discreteOrdering();
// If we have eliminated continuous variables // If we have eliminated continuous variables
// and have discrete variables to eliminate, // and have discrete variables to eliminate,
// then compute P(X | M, Z) // then compute P(X | M, Z)
@ -272,6 +272,8 @@ boost::shared_ptr<HybridGaussianFactorGraph> HybridJunctionTree::addProbPrimes(
std::set<DiscreteKey> dkeys_set(discrete_keys.begin(), discrete_keys.end()); std::set<DiscreteKey> dkeys_set(discrete_keys.begin(), discrete_keys.end());
discrete_keys = DiscreteKeys(dkeys_set.begin(), dkeys_set.end()); discrete_keys = DiscreteKeys(dkeys_set.begin(), dkeys_set.end());
FactorGraphType graph = etree_.graph();
// DecisionTree for P'(X|M, Z) for all mode sequences M // DecisionTree for P'(X|M, Z) for all mode sequences M
const AlgebraicDecisionTree<Key> probPrimeTree = const AlgebraicDecisionTree<Key> probPrimeTree =
graph.continuousProbPrimes(discrete_keys, continuousBayesTree); graph.continuousProbPrimes(discrete_keys, continuousBayesTree);
@ -298,8 +300,7 @@ HybridJunctionTree::eliminate(const Eliminate& function) const {
this->eliminateContinuous(function, graph, continuous_ordering); this->eliminateContinuous(function, graph, continuous_ordering);
FactorGraphType::shared_ptr updatedDiscreteGraph = FactorGraphType::shared_ptr updatedDiscreteGraph =
this->addProbPrimes(graph, continuousBayesTree, discreteGraph, this->addProbPrimes(continuousBayesTree, discreteGraph);
continuous_ordering, discrete_ordering);
// Eliminate discrete variables to get the discrete bayes tree. // Eliminate discrete variables to get the discrete bayes tree.
return this->eliminateDiscrete(function, continuousBayesTree, return this->eliminateDiscrete(function, continuousBayesTree,

View File

@ -73,12 +73,13 @@ class GTSAM_EXPORT HybridJunctionTree
*/ */
HybridJunctionTree(const HybridEliminationTree& eliminationTree); HybridJunctionTree(const HybridEliminationTree& eliminationTree);
protected:
/** /**
* @brief * @brief Eliminate all the continuous variables from the factor graph.
* *
* @param function * @param function The hybrid elimination function.
* @param graph * @param graph The factor graph to eliminate.
* @param continuous_ordering * @param continuous_ordering The ordering of continuous variables.
* @return std::pair<boost::shared_ptr<HybridBayesTree>, * @return std::pair<boost::shared_ptr<HybridBayesTree>,
* boost::shared_ptr<HybridGaussianFactorGraph>> * boost::shared_ptr<HybridGaussianFactorGraph>>
*/ */
@ -89,12 +90,15 @@ class GTSAM_EXPORT HybridJunctionTree
const Ordering& continuous_ordering) const; const Ordering& continuous_ordering) const;
/** /**
* @brief * @brief Eliminate all the discrete variables in the hybrid factor graph.
* *
* @param function * @param function The hybrid elimination function.
* @param continuousBayesTree * @param continuousBayesTree The bayes tree corresponding to
* @param discreteGraph * the eliminated continuous variables.
* @param discrete_ordering * @param discreteGraph Factor graph of factors containing
* only discrete variables.
* @param discrete_ordering The elimination ordering for
* the discrete variables.
* @return std::pair<boost::shared_ptr<HybridBayesTree>, * @return std::pair<boost::shared_ptr<HybridBayesTree>,
* boost::shared_ptr<HybridGaussianFactorGraph>> * boost::shared_ptr<HybridGaussianFactorGraph>>
*/ */
@ -106,26 +110,27 @@ class GTSAM_EXPORT HybridJunctionTree
const Ordering& discrete_ordering) const; const Ordering& discrete_ordering) const;
/** /**
* @brief * @brief Compute the unnormalized probability P'(X | M, Z)
* for the factor graph in each leaf of the discrete tree.
* The discrete decision tree formed as a result is added to the
* `discreteGraph` for discrete elimination.
* *
* @param graph * @param continuousBayesTree The bayes tree corresponding to
* @param continuousBayesTree * the eliminated continuous variables.
* @param discreteGraph * @param discreteGraph Factor graph consisting of factors
* @param continuous_ordering * on discrete variables only.
* @param discrete_ordering
* @return boost::shared_ptr<HybridGaussianFactorGraph> * @return boost::shared_ptr<HybridGaussianFactorGraph>
*/ */
boost::shared_ptr<HybridGaussianFactorGraph> addProbPrimes( boost::shared_ptr<HybridGaussianFactorGraph> addProbPrimes(
const HybridGaussianFactorGraph& graph,
const HybridBayesTree::shared_ptr& continuousBayesTree, const HybridBayesTree::shared_ptr& continuousBayesTree,
const HybridGaussianFactorGraph::shared_ptr& discreteGraph, const HybridGaussianFactorGraph::shared_ptr& discreteGraph) const;
const Ordering& continuous_ordering,
const Ordering& discrete_ordering) const;
public:
/** /**
* @brief * @brief Override the eliminate method so we can
* perform hybrid elimination correctly.
* *
* @param function * @param function The hybrid elimination function.
* @return std::pair<boost::shared_ptr<HybridBayesTree>, * @return std::pair<boost::shared_ptr<HybridBayesTree>,
* boost::shared_ptr<HybridGaussianFactorGraph>> * boost::shared_ptr<HybridGaussianFactorGraph>>
*/ */