new helper constructor for DiscreteConditional

release/4.3a0
Varun Agrawal 2024-12-31 20:35:36 -05:00
parent 73f54083a7
commit a71008d7fd
2 changed files with 21 additions and 1 deletions

View File

@ -24,13 +24,13 @@
#include <gtsam/hybrid/HybridValues.h>
#include <algorithm>
#include <cassert>
#include <random>
#include <set>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
using namespace std;
using std::pair;
@ -47,6 +47,15 @@ DiscreteConditional::DiscreteConditional(const size_t nrFrontals,
const DecisionTreeFactor& f)
: BaseFactor(f / (*f.sum(nrFrontals))), BaseConditional(nrFrontals) {}
/* ************************************************************************** */
DiscreteConditional::DiscreteConditional(size_t nrFrontals,
const DecisionTreeFactor& f,
const Ordering& orderedKeys)
: BaseFactor(f), BaseConditional(nrFrontals) {
keys_.clear();
keys_.insert(keys_.end(), orderedKeys.begin(), orderedKeys.end());
}
/* ************************************************************************** */
DiscreteConditional::DiscreteConditional(size_t nrFrontals,
const DiscreteKeys& keys,

View File

@ -56,6 +56,17 @@ class GTSAM_EXPORT DiscreteConditional
/// Construct from factor, taking the first `nFrontals` keys as frontals.
DiscreteConditional(size_t nFrontals, const DecisionTreeFactor& f);
/**
* @brief Construct from DecisionTreeFactor,
* taking the first `nrFrontals` from `orderedKeys`.
*
* @param nrFrontals The number of frontal variables.
* @param f The DecisionTreeFactor to construct from.
* @param orderedKeys Ordered list of keys involved in the conditional.
*/
DiscreteConditional(size_t nrFrontals, const DecisionTreeFactor& f,
const Ordering& orderedKeys);
/**
* Construct from DiscreteKeys and AlgebraicDecisionTree, taking the first
* `nFrontals` keys as frontals, in the order given.