Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gtsam/nonlinear/FixedLagSmoother.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class GTSAM_EXPORT FixedLagSmoother {
size_t nonlinearVariables; ///< The number of variables that can be relinearized
size_t linearVariables; ///< The number of variables that must keep a constant linearization point
double error; ///< The final factor graph error
FactorIndices marginalFactorIndices; ///< Indices added during the marginalizeLeaves step
FactorIndices deletedFactorIndices; ///< Indices removed during the marginalizeLeaves step
KeySet keysOfDeletedNodes; ///< Keys of nodes removed during the marginalizeLeaves step
Result() : iterations(0), intermediateSteps(0), nonlinearVariables(0), linearVariables(0), error(0) {}

/// Getter methods
Expand All @@ -59,6 +62,9 @@ class GTSAM_EXPORT FixedLagSmoother {
size_t getNonlinearVariables() const { return nonlinearVariables; }
size_t getLinearVariables() const { return linearVariables; }
double getError() const { return error; }
FactorIndices getMarginalFactorIndices() const { return marginalFactorIndices; }
FactorIndices getDeletedFactorIndices() const { return deletedFactorIndices; }
KeySet getKeysOfDeletedNodes() const { return keysOfDeletedNodes; }
void print() const;
};

Expand Down Expand Up @@ -86,6 +92,11 @@ class GTSAM_EXPORT FixedLagSmoother {
return smootherLag_;
}

/** Write to the current smoother lag. Made for python bindings. */
void setSmootherLag(double smootherLag) {
smootherLag_ = smootherLag;
}

/** Access the current set of timestamps associated with each variable */
const KeyTimestampMap& timestamps() const {
return keyTimestampMap_;
Expand Down
16 changes: 16 additions & 0 deletions gtsam/nonlinear/ISAM2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,22 @@ void ISAM2::marginalizeLeaves(
}
}

/** An added function specifically to return the marginalFactorIndices
* and deletedFactorIndices. Made for the python wrapping
* of marginalizeLeaves
*/
std::pair<FactorIndices, FactorIndices> ISAM2::marginalizeLeavesWithIndices(const FastList<Key>& leafKeys) {
FactorIndices marginal;
FactorIndices deleted;

marginalizeLeaves(
leafKeys,
&marginal,
&deleted);

return {marginal, deleted};
}

/* ************************************************************************* */
// Marked const but actually changes mutable delta
void ISAM2::updateDelta(bool forceFullSolve) const {
Expand Down
6 changes: 6 additions & 0 deletions gtsam/nonlinear/ISAM2.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ class GTSAM_EXPORT ISAM2 : public BayesTree<ISAM2Clique> {
marginalizeLeaves(leafKeys, (&optArgs)...);
}

/** An added function specifically to return the marginalFactorIndices
* and deletedFactorIndices. Made for the python wrapping
* of marginalizeLeaves
*/
std::pair<FactorIndices, FactorIndices> marginalizeLeavesWithIndices(const FastList<Key>& leafKeys);

/// Access the current linearization point
const Values& getLinearizationPoint() const { return theta_; }

Expand Down
7 changes: 6 additions & 1 deletion gtsam/nonlinear/IncrementalFixedLagSmoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ FixedLagSmoother::Result IncrementalFixedLagSmoother::update(
}

// Marginalize out any needed variables
FactorIndices marginalFactorsIndices;
FactorIndices deletedFactorsIndices;
if (marginalizableKeys.size() > 0) {
FastList<Key> leafKeys(marginalizableKeys.begin(),
marginalizableKeys.end());
isam_.marginalizeLeaves(leafKeys);
isam_.marginalizeLeaves(leafKeys, &marginalFactorsIndices, &deletedFactorsIndices);
}

// Remove marginalized keys from the KeyTimestampMap
Expand All @@ -158,6 +160,9 @@ FixedLagSmoother::Result IncrementalFixedLagSmoother::update(
result.linearVariables = 0;
result.nonlinearVariables = 0;
result.error = 0;
result.marginalFactorIndices = marginalFactorsIndices;
result.deletedFactorIndices = deletedFactorsIndices;
result.keysOfDeletedNodes = KeySet(marginalizableKeys);

if (debug)
std::cout << "IncrementalFixedLagSmoother::update() Finish" << std::endl;
Expand Down
9 changes: 9 additions & 0 deletions gtsam/nonlinear/nonlinear.i
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ class ISAM2 {
gtsam::DefaultKeyFormatter) const;
void saveGraph(string s, const gtsam::KeyFormatter& keyFormatter =
gtsam::DefaultKeyFormatter) const;
void marginalizeLeaves(const gtsam::FastList<gtsam::Key>& leafKeys);
std::pair<gtsam::FactorIndices, gtsam::FactorIndices>
marginalizeLeavesWithIndices(const gtsam::FastList<gtsam::Key>& leafKeys);
};

#include <gtsam/nonlinear/NonlinearISAM.h>
Expand Down Expand Up @@ -963,6 +966,10 @@ class FixedLagSmootherResult {
size_t getNonlinearVariables() const;
size_t getLinearVariables() const;
double getError() const;
FactorIndices getMarginalFactorIndices() const;
FactorIndices getDeletedFactorIndices() const;
KeySet getKeysOfDeletedNodes() const;
void print() const;
};

virtual class FixedLagSmoother {
Expand All @@ -971,6 +978,7 @@ virtual class FixedLagSmoother {

gtsam::FixedLagSmootherKeyTimestampMap timestamps() const;
double smootherLag() const;
void setSmootherLag(double smootherLag);

gtsam::FixedLagSmootherResult update(
const gtsam::NonlinearFactorGraph& newFactors,
Expand Down Expand Up @@ -1018,6 +1026,7 @@ virtual class IncrementalFixedLagSmoother : gtsam::FixedLagSmoother {

gtsam::NonlinearFactorGraph getFactors() const;
gtsam::ISAM2 getISAM2() const;
ISAM2Result& getISAM2Result() const;
};

#include <gtsam/nonlinear/ExtendedKalmanFilter.h>
Expand Down