fix up getOrdering and update to be more efficient
parent
2d7690dbb7
commit
b4020ed67b
|
|
@ -24,17 +24,14 @@
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Ordering HybridSmoother::getOrdering(
|
Ordering HybridSmoother::getOrdering(const HybridGaussianFactorGraph &factors,
|
||||||
const HybridGaussianFactorGraph &newFactors) {
|
const KeySet &newFactorKeys) {
|
||||||
HybridGaussianFactorGraph factors(hybridBayesNet());
|
|
||||||
factors.push_back(newFactors);
|
|
||||||
|
|
||||||
// Get all the discrete keys from the factors
|
// Get all the discrete keys from the factors
|
||||||
KeySet allDiscrete = factors.discreteKeySet();
|
KeySet allDiscrete = factors.discreteKeySet();
|
||||||
|
|
||||||
// Create KeyVector with continuous keys followed by discrete keys.
|
// Create KeyVector with continuous keys followed by discrete keys.
|
||||||
KeyVector newKeysDiscreteLast;
|
KeyVector newKeysDiscreteLast;
|
||||||
const KeySet newFactorKeys = newFactors.keys();
|
|
||||||
// Insert continuous keys first.
|
// Insert continuous keys first.
|
||||||
for (auto &k : newFactorKeys) {
|
for (auto &k : newFactorKeys) {
|
||||||
if (!allDiscrete.exists(k)) {
|
if (!allDiscrete.exists(k)) {
|
||||||
|
|
@ -56,22 +53,29 @@ Ordering HybridSmoother::getOrdering(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void HybridSmoother::update(HybridGaussianFactorGraph graph,
|
void HybridSmoother::update(const HybridGaussianFactorGraph &graph,
|
||||||
std::optional<size_t> maxNrLeaves,
|
std::optional<size_t> maxNrLeaves,
|
||||||
const std::optional<Ordering> given_ordering) {
|
const std::optional<Ordering> given_ordering) {
|
||||||
|
HybridGaussianFactorGraph updatedGraph;
|
||||||
|
// Add the necessary conditionals from the previous timestep(s).
|
||||||
|
std::tie(updatedGraph, hybridBayesNet_) =
|
||||||
|
addConditionals(graph, hybridBayesNet_);
|
||||||
|
|
||||||
Ordering ordering;
|
Ordering ordering;
|
||||||
// If no ordering provided, then we compute one
|
// If no ordering provided, then we compute one
|
||||||
if (!given_ordering.has_value()) {
|
if (!given_ordering.has_value()) {
|
||||||
ordering = this->getOrdering(graph);
|
// Get the keys from the new factors
|
||||||
|
const KeySet newFactorKeys = graph.keys();
|
||||||
|
|
||||||
|
// Since updatedGraph now has all the connected conditionals,
|
||||||
|
// we can get the correct ordering.
|
||||||
|
ordering = this->getOrdering(updatedGraph, newFactorKeys);
|
||||||
} else {
|
} else {
|
||||||
ordering = *given_ordering;
|
ordering = *given_ordering;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the necessary conditionals from the previous timestep(s).
|
|
||||||
std::tie(graph, hybridBayesNet_) = addConditionals(graph, hybridBayesNet_);
|
|
||||||
|
|
||||||
// Eliminate.
|
// Eliminate.
|
||||||
HybridBayesNet bayesNetFragment = *graph.eliminateSequential(ordering);
|
HybridBayesNet bayesNetFragment = *updatedGraph.eliminateSequential(ordering);
|
||||||
|
|
||||||
/// Prune
|
/// Prune
|
||||||
if (maxNrLeaves) {
|
if (maxNrLeaves) {
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,35 @@ class GTSAM_EXPORT HybridSmoother {
|
||||||
* @param given_ordering The (optional) ordering for elimination, only
|
* @param given_ordering The (optional) ordering for elimination, only
|
||||||
* continuous variables are allowed
|
* continuous variables are allowed
|
||||||
*/
|
*/
|
||||||
void update(HybridGaussianFactorGraph graph,
|
void update(const HybridGaussianFactorGraph& graph,
|
||||||
std::optional<size_t> maxNrLeaves = {},
|
std::optional<size_t> maxNrLeaves = {},
|
||||||
const std::optional<Ordering> given_ordering = {});
|
const std::optional<Ordering> given_ordering = {});
|
||||||
|
|
||||||
Ordering getOrdering(const HybridGaussianFactorGraph& newFactors);
|
/**
|
||||||
|
* @brief Get an elimination ordering which eliminates continuous and then
|
||||||
|
* discrete.
|
||||||
|
*
|
||||||
|
* Expects `newFactors` to already have the necessary conditionals connected
|
||||||
|
* to the
|
||||||
|
*
|
||||||
|
* @param factors
|
||||||
|
* @return Ordering
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get an elimination ordering which eliminates continuous
|
||||||
|
* and then discrete.
|
||||||
|
*
|
||||||
|
* Expects `factors` to already have the necessary conditionals
|
||||||
|
* which were connected to the variables in the newly added factors.
|
||||||
|
* Those variables should be in `newFactorKeys`.
|
||||||
|
*
|
||||||
|
* @param factors All the new factors and connected conditionals.
|
||||||
|
* @param newFactorKeys The keys/variables in the newly added factors.
|
||||||
|
* @return Ordering
|
||||||
|
*/
|
||||||
|
Ordering getOrdering(const HybridGaussianFactorGraph& factors,
|
||||||
|
const KeySet& newFactorKeys);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add conditionals from previous timestep as part of liquefication.
|
* @brief Add conditionals from previous timestep as part of liquefication.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue