Skip to content
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

Proper Hybrid Elimination #1319

Merged
merged 63 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0839331
minor typo fixes
varunagrawal Oct 25, 2022
7dec7bb
remove if guards and add timing counters
varunagrawal Oct 25, 2022
dcdcf30
new WIP test to check the discrete probabilities after elimination
varunagrawal Oct 25, 2022
1789bb7
showing difference in computed probabilities
varunagrawal Oct 25, 2022
96afdff
Increase the number of time steps for incremental test case
varunagrawal Nov 1, 2022
5bfce89
Merge branch 'hybrid/error' into hybrid/tests
varunagrawal Nov 4, 2022
a97d27e
Merge branch 'hybrid/error' into hybrid/tests
varunagrawal Nov 7, 2022
a6d1a57
fix hybrid elimination
varunagrawal Nov 7, 2022
2f2f8c9
figured out how to get the correct continuous errors
varunagrawal Nov 7, 2022
98febf2
allow optional discrete transition probability for Switching test fix…
varunagrawal Nov 7, 2022
610a535
set up unit test to verify that the probPrimeTree has the same values…
varunagrawal Nov 7, 2022
1815433
add methods to perform correct elimination
varunagrawal Nov 7, 2022
090cc42
update HybridSmoother to use the new method
varunagrawal Nov 7, 2022
083fd21
use long sequence in HybridEstimation test
varunagrawal Nov 7, 2022
64cd7c9
add docs
varunagrawal Nov 7, 2022
3987b03
add optional ordering and fix bug
varunagrawal Nov 8, 2022
1a3b343
minor clean up and get tests to pass
varunagrawal Nov 8, 2022
1b168ce
update test in testHybridEstimation
varunagrawal Nov 8, 2022
cb55af3
separate HybridGaussianFactorGraph::error() using both continuous and…
varunagrawal Nov 8, 2022
eb94ad9
add HybridGaussianFactorGraph::probPrime method
varunagrawal Nov 8, 2022
0938159
overload multifrontal elimination
varunagrawal Nov 9, 2022
98d3186
add copy constructor for HybridBayesTreeClique
varunagrawal Nov 10, 2022
7ae4e57
fix HybridBayesTree::optimize to account for pruned nodes
varunagrawal Nov 10, 2022
d54cf48
fix creation of updatedBayesTree
varunagrawal Nov 10, 2022
318f738
fixup the final tests
varunagrawal Nov 10, 2022
6e6bbff
update docstring for Ordering::+=
varunagrawal Nov 10, 2022
5e2cdfd
make continuousProbPrimes and continuousDeltas as templates
varunagrawal Nov 13, 2022
2394129
address review comments
varunagrawal Nov 15, 2022
05b2d31
better printing
varunagrawal Dec 3, 2022
3eaf4cc
move multifrontal optimize test to testHybridBayesTree and update doc…
varunagrawal Dec 3, 2022
cd3cfa0
moved sequential elimination code to HybridEliminationTree
varunagrawal Dec 3, 2022
15fffeb
add getters to HybridEliminationTree
varunagrawal Dec 4, 2022
addbe2a
override eliminate in HybridJunctionTree
varunagrawal Dec 4, 2022
ae0b3e3
split up the eliminate method to constituent parts
varunagrawal Dec 4, 2022
bed56e0
mark helper methods as protected and add docstrings
varunagrawal Dec 4, 2022
5fc114f
more unit tests
varunagrawal Dec 4, 2022
22e4a73
Add details about the role of the HybridEliminationTree in hybrid eli…
varunagrawal Dec 4, 2022
0596b2f
remove unrequired code
varunagrawal Dec 10, 2022
62bc9f2
update hybrid elimination and corresponding tests
varunagrawal Dec 10, 2022
6beffeb
remove commented out code
varunagrawal Dec 10, 2022
da5d3a2
Merge pull request #1339 from borglab/hybrid/new-elimination
varunagrawal Dec 10, 2022
812bf52
minor cleanup
varunagrawal Dec 21, 2022
6b6731a
Merge branch 'hybrid/error' into hybrid/tests
varunagrawal Dec 21, 2022
46380ca
Merge branch 'hybrid/tests' into hybrid/multifrontal
varunagrawal Dec 21, 2022
583d121
Merge pull request #1323 from borglab/hybrid/multifrontal
varunagrawal Dec 23, 2022
ffd1802
add optional model parameter to sample method
varunagrawal Dec 23, 2022
bdb7836
sampling test
varunagrawal Dec 23, 2022
ae0df47
Merge branch 'develop' into hybrid/tests
varunagrawal Dec 24, 2022
153c12e
Merge branch 'develop' into hybrid/tests
varunagrawal Dec 24, 2022
aa86af2
Revert "add optional model parameter to sample method"
varunagrawal Dec 24, 2022
6b834db
Merge branch 'hybrid/tests' into hybrid/verification
varunagrawal Dec 24, 2022
798c51a
update sampling test to use new sample method
varunagrawal Dec 24, 2022
13d22b1
address review comments
varunagrawal Dec 24, 2022
1e17dd3
compute sampling ratio for one sample and then for multiple samples
varunagrawal Dec 24, 2022
f3c85ae
Merge pull request #1346 from borglab/hybrid/verification
varunagrawal Dec 25, 2022
76e838b
Implement printing rather than calling factor graph version
dellaert Dec 25, 2022
4ad482a
Small comments
dellaert Dec 26, 2022
a7573e8
Refactor elimination setup to not use C declaration style
dellaert Dec 26, 2022
8a319c5
Separated out NFG setup and added test.
dellaert Dec 26, 2022
db17a04
Fix print test
dellaert Dec 26, 2022
cfcbdda
Merge pull request #1349 from borglab/hybrid/two_ways
varunagrawal Dec 27, 2022
cf46c36
Merge branch 'develop' into hybrid/tests
varunagrawal Dec 30, 2022
28f349c
minor fixes
varunagrawal Dec 30, 2022
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
2 changes: 1 addition & 1 deletion gtsam/hybrid/GaussianMixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool GaussianMixture::equals(const HybridFactor &lf, double tol) const {
/* *******************************************************************************/
void GaussianMixture::print(const std::string &s,
const KeyFormatter &formatter) const {
std::cout << s;
std::cout << (s.empty() ? "" : s + "\n");
if (isContinuous()) std::cout << "Continuous ";
if (isDiscrete()) std::cout << "Discrete ";
if (isHybrid()) std::cout << "Hybrid ";
Expand Down
11 changes: 8 additions & 3 deletions gtsam/hybrid/HybridBayesNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ std::function<double(const Assignment<Key> &, double)> prunerFunc(
}

/* ************************************************************************* */
// TODO(dellaert): what is this non-const method used for? Abolish it?
void HybridBayesNet::updateDiscreteConditionals(
const DecisionTreeFactor::shared_ptr &prunedDecisionTree) {
KeyVector prunedTreeKeys = prunedDecisionTree->keys();
Expand Down Expand Up @@ -150,9 +151,7 @@ HybridBayesNet HybridBayesNet::prune(size_t maxNrLeaves) {

// Go through all the conditionals in the
// Bayes Net and prune them as per decisionTree.
for (size_t i = 0; i < this->size(); i++) {
HybridConditional::shared_ptr conditional = this->at(i);

for (auto &&conditional : *this) {
if (conditional->isHybrid()) {
GaussianMixture::shared_ptr gaussianMixture = conditional->asMixture();

Expand Down Expand Up @@ -232,6 +231,12 @@ HybridValues HybridBayesNet::optimize() const {
/* ************************************************************************* */
VectorValues HybridBayesNet::optimize(const DiscreteValues &assignment) const {
GaussianBayesNet gbn = this->choose(assignment);

// Check if there exists a nullptr in the GaussianBayesNet
// If yes, return an empty VectorValues
if (std::find(gbn.begin(), gbn.end(), nullptr) != gbn.end()) {
return VectorValues();
}
return gbn.optimize();
}

Expand Down
31 changes: 23 additions & 8 deletions gtsam/hybrid/HybridBayesTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @brief Hybrid Bayes Tree, the result of eliminating a
* HybridJunctionTree
* @date Mar 11, 2022
* @author Fan Jiang
* @author Fan Jiang, Varun Agrawal
*/

#include <gtsam/base/treeTraversal-inst.h>
Expand Down Expand Up @@ -73,6 +73,8 @@ struct HybridAssignmentData {
GaussianBayesTree::sharedNode parentClique_;
// The gaussian bayes tree that will be recursively created.
GaussianBayesTree* gaussianbayesTree_;
// Flag indicating if all the nodes are valid. Used in optimize().
bool valid_;

/**
* @brief Construct a new Hybrid Assignment Data object.
Expand All @@ -83,10 +85,13 @@ struct HybridAssignmentData {
*/
HybridAssignmentData(const DiscreteValues& assignment,
const GaussianBayesTree::sharedNode& parentClique,
GaussianBayesTree* gbt)
GaussianBayesTree* gbt, bool valid = true)
: assignment_(assignment),
parentClique_(parentClique),
gaussianbayesTree_(gbt) {}
gaussianbayesTree_(gbt),
valid_(valid) {}

bool isValid() const { return valid_; }

/**
* @brief A function used during tree traversal that operates on each node
Expand All @@ -101,6 +106,7 @@ struct HybridAssignmentData {
HybridAssignmentData& parentData) {
// Extract the gaussian conditional from the Hybrid clique
HybridConditional::shared_ptr hybrid_conditional = node->conditional();

GaussianConditional::shared_ptr conditional;
if (hybrid_conditional->isHybrid()) {
conditional = (*hybrid_conditional->asMixture())(parentData.assignment_);
Expand All @@ -111,15 +117,21 @@ struct HybridAssignmentData {
conditional = boost::make_shared<GaussianConditional>();
}

// Create the GaussianClique for the current node
auto clique = boost::make_shared<GaussianBayesTree::Node>(conditional);
// Add the current clique to the GaussianBayesTree.
parentData.gaussianbayesTree_->addClique(clique, parentData.parentClique_);
GaussianBayesTree::sharedNode clique;
if (conditional) {
// Create the GaussianClique for the current node
clique = boost::make_shared<GaussianBayesTree::Node>(conditional);
// Add the current clique to the GaussianBayesTree.
parentData.gaussianbayesTree_->addClique(clique,
parentData.parentClique_);
} else {
parentData.valid_ = false;
}

// Create new HybridAssignmentData where the current node is the parent
// This will be passed down to the children nodes
HybridAssignmentData data(parentData.assignment_, clique,
parentData.gaussianbayesTree_);
parentData.gaussianbayesTree_, parentData.valid_);
return data;
}
};
Expand All @@ -138,6 +150,9 @@ VectorValues HybridBayesTree::optimize(const DiscreteValues& assignment) const {
visitorPost);
}

if (!rootData.isValid()) {
return VectorValues();
}
VectorValues result = gbt.optimize();

// Return the optimized bayes net result.
Expand Down
5 changes: 4 additions & 1 deletion gtsam/hybrid/HybridBayesTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class GTSAM_EXPORT HybridBayesTreeClique
typedef boost::shared_ptr<This> shared_ptr;
typedef boost::weak_ptr<This> weak_ptr;
HybridBayesTreeClique() {}
virtual ~HybridBayesTreeClique() {}
HybridBayesTreeClique(const boost::shared_ptr<HybridConditional>& conditional)
: Base(conditional) {}
///< Copy constructor
HybridBayesTreeClique(const HybridBayesTreeClique& clique) : Base(clique) {}

virtual ~HybridBayesTreeClique() {}
};

/* ************************************************************************* */
Expand Down
2 changes: 1 addition & 1 deletion gtsam/hybrid/HybridEliminationTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace gtsam {

/**
* Elimination Tree type for Hybrid
* Elimination Tree type for Hybrid Factor Graphs.
*
* @ingroup hybrid
*/
Expand Down
Loading