-
Notifications
You must be signed in to change notification settings - Fork 793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HybridFactorGraph base class and other niceties #1221
Merged
Merged
Changes from 22 commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
2927d92
add HybridNonlinearFactor and nonlinear HybridFactorGraph
varunagrawal 78ea90b
Add MixtureFactor for nonlinear factor types
varunagrawal e91a354
convert to cpp
varunagrawal 9cbd2ef
Base Hybrid Factor Graph
varunagrawal 01b9a65
make GaussianMixtureFactor a subclass of HybridGaussianFactor
varunagrawal fe0d666
HybridFactorGraph fixes
varunagrawal cdd030b
Make MixtureFactor only work with NonlinearFactors and make some impr…
varunagrawal 08fab8a
HybridNonlinearFactor linearize method
varunagrawal 9279bd6
push_back for GaussianHybridFactor
varunagrawal 3274cb1
clean up testHybridFactorGraph, need to add more tests
varunagrawal 6c36b2c
GaussianHybridFactorGraph inherits from HybridFactorGraph
varunagrawal 85f4b48
Improvements to GaussianHybridFactorGraph, make MixtureFactor a subcl…
varunagrawal 53e8c32
Add NonlinearHybridFactorGraph class
varunagrawal 7e18277
fix base class
varunagrawal 119679a
linearize returns object instead of pointer
varunagrawal 3212dde
remove unneeded method
varunagrawal 0c16799
GaussianMixtureFactor inherits from HybridFactor
varunagrawal e711a62
More tests working
varunagrawal 9e737db
initial pruning method
varunagrawal 89768cf
record continuous keys separately
varunagrawal ad77a45
formatting and docs update
varunagrawal c2e5061
add pruning to HybridBayesNet
varunagrawal e25b0c8
Merge branch 'develop' into hybrid/pruning
varunagrawal 28db8b2
use KeyVector and iterator constructor
varunagrawal 5c5c053
Add HybridFactorGraph base class and more methods for adding gaussian…
varunagrawal 44079d1
refactor testGaussianHybridFactorGraph to include comments and valid …
varunagrawal 374e3cb
Improved hybrid bayes net and tests
varunagrawal 8d6a225
fix printing
varunagrawal 00be610
Add Switching class and make it linear
varunagrawal 26e0cef
fixes
varunagrawal 5bf5d03
local include
varunagrawal 8d35925
make makeBinaryOrdering inline to prevent multiple definition error
varunagrawal 622ebdd
makeSwitchingChain is also inline
varunagrawal 09d512a
add docstring for makeBinaryOrdering
varunagrawal 7496f2f
address review comments
varunagrawal f1a1f1c
Merge branch 'develop' into hybrid/pruning
varunagrawal dfbfca9
Merge branch 'develop' into hybrid/hybrid-factor-graph
varunagrawal 91da520
add new lines
varunagrawal 34298c4
Merge branch 'hybrid/hybrid-factor-graph' into hybrid/pruning
varunagrawal 3780b8c
Merge branch 'develop' into feature/nonlinear-hybrid
varunagrawal 8ddc2ea
rename to HybridNonlinearFactorGraph
varunagrawal 7a55341
add IsGaussian template check
varunagrawal 43c28e7
renaming fixes
varunagrawal 987448f
remove derived push_back in HybridNonlinearFactorGraph and HybridFact…
varunagrawal 8471c97
add nonlinear switching system tests
varunagrawal 8907922
get more nonlinear tests to work and make some updates
varunagrawal 16124f3
get all but 2 tests passing
varunagrawal ee124c3
fix discrete only elimination (use EliminateForMPE)
varunagrawal b39c231
all tests pass!!!
varunagrawal 0f732d7
fix discrete conditional test
varunagrawal 6670779
Wrap DiscreteLookupTable
varunagrawal f124ccc
Merge branch 'develop' into hybrid/hybrid-factor-graph
varunagrawal 2fb11db
Merge branch 'develop' into hybrid/pruning
varunagrawal 92a5868
Merge branch 'develop' into feature/nonlinear-hybrid
varunagrawal db56909
Merge branch 'hybrid/pruning' into feature/nonlinear-hybrid
varunagrawal 5965d8f
change discrete key variable from C to M
varunagrawal f5e046f
split HybridNonlinearFactorGraph to .h and .cpp
varunagrawal 51d2f07
fix printing and key bug in MixtureFactor linearize
varunagrawal a3eacaa
fix adding priors in Switching
varunagrawal 588f56e
HybridGaussianISAM unit tests
varunagrawal 4ee23cf
Merge branch 'hybrid/hybrid-factor-graph' into hybrid/pruning
varunagrawal 60c88e3
fix print tests
varunagrawal 4ea897c
cleaner printing
varunagrawal fbceda3
got some more tests working
varunagrawal 0e4db30
use templetized constructor for MixtureFactor
varunagrawal aa48658
more tests running
varunagrawal 77bea31
one more test passing
varunagrawal 5806850
HybridValues and optimize() method for hybrid gaussian bayes net
xsj01 36d6097
Merge branch 'hybrid/hybrid-factor-graph' into hybrid/hybrid-optimize
xsj01 9564e32
Merge branch 'hybrid/hybrid-factor-graph' into hybrid/hybrid-optimize
xsj01 7d36a9e
add some comments
xsj01 2a974a4
Address review comments
varunagrawal ac20cff
add incremental pruning to HybridGaussianISAM
varunagrawal 379a65f
Address review comments
xsj01 83b8103
last test to get running
varunagrawal 746ca78
Address review comments
xsj01 c4184e1
fix error in python unit test
xsj01 7977f77
Merge pull request #1263 from borglab/feature/nonlinear-hybrid
varunagrawal 07f0101
check subset rather than equality for GaussianISAM pruning
varunagrawal 29c19ee
handle HybridConditional and explicitly set Gaussian Factor Graphs to…
varunagrawal f6df641
remove custom orderings, let it happen automatically
varunagrawal 6b792c0
add note about sumFrontals
varunagrawal 893c5f7
cast to only HybridGaussianFactor
varunagrawal ef066a0
Merge pull request #1270 from borglab/hybrid/hybrid-optimize
xsj01 4c9c106
Merge pull request #1271 from borglab/feature/nonlinear-incremental
varunagrawal 84456f4
Merge pull request #1273 from borglab/hybrid-incremental
varunagrawal 05b1174
Merge pull request #1277 from borglab/feature/nonlinear-hybrid
varunagrawal 8fd6091
add new line
varunagrawal b07964b
name file correctly in doc string
varunagrawal 7227965
Merge branch 'develop' into hybrid/pruning
varunagrawal 89cdf4f
Merge pull request #1215 from borglab/hybrid/pruning
varunagrawal aa52b39
fix docstring
varunagrawal df64982
add extra tests
varunagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* ---------------------------------------------------------------------------- | ||
|
||
* GTSAM Copyright 2010, Georgia Tech Research Corporation, | ||
* Atlanta, Georgia 30332-0415 | ||
* All Rights Reserved | ||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list) | ||
|
||
* See LICENSE for the license information | ||
|
||
* -------------------------------------------------------------------------- */ | ||
|
||
/** | ||
* @file HybridFactorGraph.h | ||
* @brief Hybrid factor graph base class that uses type erasure | ||
* @author Varun Agrawal | ||
* @date May 28, 2022 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <gtsam/discrete/DiscreteFactor.h> | ||
#include <gtsam/hybrid/HybridDiscreteFactor.h> | ||
#include <gtsam/hybrid/HybridFactor.h> | ||
#include <gtsam/inference/FactorGraph.h> | ||
#include <gtsam/inference/Ordering.h> | ||
|
||
#include <boost/format.hpp> | ||
namespace gtsam { | ||
|
||
using SharedFactor = boost::shared_ptr<Factor>; | ||
|
||
/** | ||
* Hybrid Factor Graph | ||
* ----------------------- | ||
* This is the base hybrid factor graph. | ||
* Everything inside needs to be hybrid factor or hybrid conditional. | ||
*/ | ||
class HybridFactorGraph : public FactorGraph<HybridFactor> { | ||
public: | ||
using Base = FactorGraph<HybridFactor>; | ||
using This = HybridFactorGraph; ///< this class | ||
using shared_ptr = boost::shared_ptr<This>; ///< shared_ptr to This | ||
|
||
using Values = gtsam::Values; ///< backwards compatibility | ||
using Indices = KeyVector; ///> map from keys to values | ||
|
||
protected: | ||
/// Check if FACTOR type is derived from DiscreteFactor. | ||
template <typename FACTOR> | ||
using IsDiscrete = typename std::enable_if< | ||
std::is_base_of<DiscreteFactor, FACTOR>::value>::type; | ||
|
||
/// Check if FACTOR type is derived from HybridFactor. | ||
template <typename FACTOR> | ||
using IsHybrid = typename std::enable_if< | ||
std::is_base_of<HybridFactor, FACTOR>::value>::type; | ||
|
||
public: | ||
/// @name Constructors | ||
/// @{ | ||
|
||
/// Default constructor | ||
HybridFactorGraph() = default; | ||
|
||
/** | ||
* Implicit copy/downcast constructor to override explicit template container | ||
* constructor. In BayesTree this is used for: | ||
* `cachedSeparatorMarginal_.reset(*separatorMarginal)` | ||
* */ | ||
template <class DERIVEDFACTOR> | ||
HybridFactorGraph(const FactorGraph<DERIVEDFACTOR>& graph) : Base(graph) {} | ||
|
||
/// @} | ||
|
||
// Allow use of selected FactorGraph methods: | ||
using Base::empty; | ||
using Base::reserve; | ||
using Base::size; | ||
using Base::operator[]; | ||
using Base::add; | ||
using Base::push_back; | ||
using Base::resize; | ||
|
||
/** | ||
* Add a discrete factor *pointer* to the internal discrete graph | ||
* @param discreteFactor - boost::shared_ptr to the factor to add | ||
*/ | ||
template <typename FACTOR> | ||
IsDiscrete<FACTOR> push_discrete( | ||
const boost::shared_ptr<FACTOR>& discreteFactor) { | ||
Base::push_back(boost::make_shared<HybridDiscreteFactor>(discreteFactor)); | ||
} | ||
|
||
/** | ||
* Add a discrete-continuous (Hybrid) factor *pointer* to the graph | ||
* @param hybridFactor - boost::shared_ptr to the factor to add | ||
*/ | ||
template <typename FACTOR> | ||
IsHybrid<FACTOR> push_hybrid(const boost::shared_ptr<FACTOR>& hybridFactor) { | ||
Base::push_back(hybridFactor); | ||
} | ||
|
||
/// delete emplace_shared. | ||
template <class FACTOR, class... Args> | ||
void emplace_shared(Args&&... args) = delete; | ||
|
||
/// Construct a factor and add (shared pointer to it) to factor graph. | ||
template <class FACTOR, class... Args> | ||
IsDiscrete<FACTOR> emplace_discrete(Args&&... args) { | ||
auto factor = boost::allocate_shared<FACTOR>( | ||
Eigen::aligned_allocator<FACTOR>(), std::forward<Args>(args)...); | ||
push_discrete(factor); | ||
} | ||
|
||
/// Construct a factor and add (shared pointer to it) to factor graph. | ||
template <class FACTOR, class... Args> | ||
IsHybrid<FACTOR> emplace_hybrid(Args&&... args) { | ||
auto factor = boost::allocate_shared<FACTOR>( | ||
Eigen::aligned_allocator<FACTOR>(), std::forward<Args>(args)...); | ||
push_hybrid(factor); | ||
} | ||
|
||
/** | ||
* @brief Add a single factor shared pointer to the hybrid factor graph. | ||
* Dynamically handles the factor type and assigns it to the correct | ||
* underlying container. | ||
* | ||
* @param sharedFactor The factor to add to this factor graph. | ||
*/ | ||
void push_back(const SharedFactor& sharedFactor) { | ||
if (auto p = boost::dynamic_pointer_cast<DiscreteFactor>(sharedFactor)) { | ||
push_discrete(p); | ||
} | ||
if (auto p = boost::dynamic_pointer_cast<HybridFactor>(sharedFactor)) { | ||
push_hybrid(p); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace gtsam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
#pragma once | ||
|
||
#include <gtsam/hybrid/HybridFactor.h> | ||
#include <gtsam/hybrid/HybridFactorGraph.h> | ||
#include <gtsam/hybrid/HybridGaussianFactor.h> | ||
#include <gtsam/inference/EliminateableFactorGraph.h> | ||
#include <gtsam/inference/FactorGraph.h> | ||
#include <gtsam/inference/Ordering.h> | ||
|
@@ -53,10 +55,9 @@ struct EliminationTraits<HybridGaussianFactorGraph> { | |
typedef HybridBayesNet | ||
BayesNetType; ///< Type of Bayes net from sequential elimination | ||
typedef HybridEliminationTree | ||
EliminationTreeType; ///< Type of elimination tree | ||
typedef HybridBayesTree BayesTreeType; ///< Type of Bayes tree | ||
typedef HybridJunctionTree | ||
JunctionTreeType; ///< Type of Junction tree | ||
EliminationTreeType; ///< Type of elimination tree | ||
typedef HybridBayesTree BayesTreeType; ///< Type of Bayes tree | ||
typedef HybridJunctionTree JunctionTreeType; ///< Type of Junction tree | ||
/// The default dense elimination function | ||
static std::pair<boost::shared_ptr<ConditionalType>, | ||
boost::shared_ptr<FactorType> > | ||
|
@@ -72,10 +73,16 @@ struct EliminationTraits<HybridGaussianFactorGraph> { | |
* Everything inside needs to be hybrid factor or hybrid conditional. | ||
*/ | ||
class GTSAM_EXPORT HybridGaussianFactorGraph | ||
: public FactorGraph<HybridFactor>, | ||
: public HybridFactorGraph, | ||
public EliminateableFactorGraph<HybridGaussianFactorGraph> { | ||
protected: | ||
/// Check if FACTOR type is derived from GaussianFactor. | ||
template <typename FACTOR> | ||
using IsGaussian = typename std::enable_if< | ||
std::is_base_of<GaussianFactor, FACTOR>::value>::type; | ||
|
||
public: | ||
using Base = FactorGraph<HybridFactor>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this makes adding |
||
using Base = HybridFactorGraph; | ||
using This = HybridGaussianFactorGraph; ///< this class | ||
using BaseEliminateable = | ||
EliminateableFactorGraph<This>; ///< for elimination | ||
|
@@ -100,7 +107,13 @@ class GTSAM_EXPORT HybridGaussianFactorGraph | |
|
||
/// @} | ||
|
||
using FactorGraph::add; | ||
using Base::empty; | ||
using Base::reserve; | ||
using Base::size; | ||
using Base::operator[]; | ||
using Base::add; | ||
using Base::push_back; | ||
using Base::resize; | ||
|
||
/// Add a Jacobian factor to the factor graph. | ||
void add(JacobianFactor&& factor); | ||
|
@@ -113,6 +126,39 @@ class GTSAM_EXPORT HybridGaussianFactorGraph | |
|
||
/// Add a DecisionTreeFactor as a shared ptr. | ||
void add(boost::shared_ptr<DecisionTreeFactor> factor); | ||
|
||
/** | ||
* Add a gaussian factor *pointer* to the internal gaussian factor graph | ||
* @param gaussianFactor - boost::shared_ptr to the factor to add | ||
*/ | ||
template <typename FACTOR> | ||
IsGaussian<FACTOR> push_gaussian( | ||
const boost::shared_ptr<FACTOR>& gaussianFactor) { | ||
Base::push_back(boost::make_shared<HybridGaussianFactor>(gaussianFactor)); | ||
} | ||
|
||
/// Construct a factor and add (shared pointer to it) to factor graph. | ||
template <class FACTOR, class... Args> | ||
IsGaussian<FACTOR> emplace_gaussian(Args&&... args) { | ||
auto factor = boost::allocate_shared<FACTOR>( | ||
Eigen::aligned_allocator<FACTOR>(), std::forward<Args>(args)...); | ||
push_gaussian(factor); | ||
} | ||
|
||
/** | ||
* @brief Add a single factor shared pointer to the hybrid factor graph. | ||
* Dynamically handles the factor type and assigns it to the correct | ||
* underlying container. | ||
* | ||
* @param sharedFactor The factor to add to this factor graph. | ||
*/ | ||
void push_back(const SharedFactor& sharedFactor) { | ||
if (auto p = boost::dynamic_pointer_cast<GaussianFactor>(sharedFactor)) { | ||
push_gaussian(p); | ||
} else { | ||
Base::push_back(sharedFactor); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace gtsam |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not in favor of more helpers, do we have similar stuff in
DiscreteBayesNet
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need this since we need to wrap the
DiscreteConditional
into aHybridConditional
.