22 #include <unordered_set> 37 const KeySet newFactorKeys = newFactors.
keys();
39 for (
auto &k : newFactorKeys) {
40 if (!allDiscrete.
exists(k)) {
41 newKeysDiscreteLast.push_back(k);
46 std::copy(allDiscrete.begin(), allDiscrete.end(),
47 std::back_inserter(newKeysDiscreteLast));
53 index,
KeyVector(newKeysDiscreteLast.begin(), newKeysDiscreteLast.end()),
60 std::optional<size_t> maxNrLeaves,
61 const std::optional<Ordering> given_ordering) {
64 if (!given_ordering.has_value()) {
67 ordering = *given_ordering;
82 bayesNetFragment->
prune(*maxNrLeaves);
84 bayesNetFragment = std::make_shared<HybridBayesNet>(prunedBayesNetFragment);
92 std::pair<HybridGaussianFactorGraph, HybridBayesNet>
100 if (!hybridBayesNet.
empty()) {
106 std::vector<HybridConditional::shared_ptr> conditionals_to_erase;
113 for (
size_t i = 0;
i < hybridBayesNet.
size();
i++) {
114 auto conditional = hybridBayesNet.
at(
i);
116 for (
auto &
key : conditional->frontals()) {
117 if (std::find(ordering.begin(), ordering.end(),
key) !=
120 conditionals_to_erase.push_back(conditional);
128 for (
auto &&conditional : conditionals_to_erase) {
129 auto it = find(hybridBayesNet.
begin(), hybridBayesNet.
end(), conditional);
130 hybridBayesNet.
erase(it);
135 return {
graph, hybridBayesNet};
140 size_t index)
const {
const gtsam::Symbol key('X', 0)
KeySet discreteKeySet() const
Get all the discrete keys in the factor graph, as a set.
An incremental smoother for hybrid factor graphs.
std::pair< HybridGaussianFactorGraph, HybridBayesNet > addConditionals(const HybridGaussianFactorGraph &graph, const HybridBayesNet &hybridBayesNet, const Ordering &ordering) const
Add conditionals from previous timestep as part of liquefication.
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
bool exists(const VALUE &e) const
const GaussianFactorGraph factors
GaussianMixture::shared_ptr gaussianMixture(size_t index) const
Get the Gaussian Mixture from the Bayes Net posterior at index.
const HybridBayesNet & hybridBayesNet() const
Return the Bayes Net posterior.
NonlinearFactorGraph graph
static enum @1107 ordering
IsDerived< DERIVEDFACTOR > add(std::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
const_iterator begin() const
HybridBayesNet hybridBayesNet_
HybridBayesNet prune(size_t maxNrLeaves)
Prune the Hybrid Bayes Net such that we have at most maxNrLeaves leaves.
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
void push_back(std::shared_ptr< HybridConditional > conditional)
Add a hybrid conditional using a shared_ptr.
const_iterator end() const
const sharedFactor at(size_t i) const
std::shared_ptr< GaussianMixture > shared_ptr
Ordering getOrdering(const HybridGaussianFactorGraph &newFactors)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
void update(HybridGaussianFactorGraph graph, std::optional< size_t > maxNrLeaves={}, const std::optional< Ordering > given_ordering={})
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
iterator erase(iterator item)