-
Notifications
You must be signed in to change notification settings - Fork 768
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
Added convenience constructors and python wrappers #1353
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
356b89a
Fix to const &
dellaert 0495f81
Test for GBN::sample
dellaert d9511d6
Convenience constructors
dellaert 1de4959
Add methods in HybridBayesNet
dellaert fd12181
Cleanup
dellaert 7c91fe8
Add evaluate test
dellaert 873f5ba
remove unnecessary preamble and specializations for hybrid wrapping
varunagrawal 03baf8f
formatting and fixes to test
varunagrawal f4420f2
add mixture to bayesnet and fix double assert bug
varunagrawal cc2183a
fix wrap preamble
varunagrawal 1eb6fc7
fix formatting and other issues
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
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 |
---|---|---|
@@ -1,4 +0,0 @@ | ||
|
||
py::bind_vector<std::vector<gtsam::GaussianFactor::shared_ptr> >(m_, "GaussianFactorVector"); | ||
|
||
py::implicitly_convertible<py::list, std::vector<gtsam::GaussianFactor::shared_ptr> >(); | ||
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,69 @@ | ||
""" | ||
GTSAM Copyright 2010-2022, Georgia Tech Research Corporation, | ||
Atlanta, Georgia 30332-0415 | ||
All Rights Reserved | ||
|
||
See LICENSE for the license information | ||
|
||
Unit tests for Hybrid Values. | ||
Author: Frank Dellaert | ||
""" | ||
# pylint: disable=invalid-name, no-name-in-module, no-member | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
from gtsam.symbol_shorthand import A, X | ||
from gtsam.utils.test_case import GtsamTestCase | ||
|
||
import gtsam | ||
from gtsam import (DiscreteKeys, GaussianConditional, GaussianMixture, | ||
HybridBayesNet, HybridValues, noiseModel) | ||
|
||
|
||
class TestHybridBayesNet(GtsamTestCase): | ||
"""Unit tests for HybridValues.""" | ||
def test_evaluate(self): | ||
"""Test evaluate for a hybrid Bayes net P(X0|X1) P(X1|Asia) P(Asia).""" | ||
asiaKey = A(0) | ||
Asia = (asiaKey, 2) | ||
|
||
# Create the continuous conditional | ||
I_1x1 = np.eye(1) | ||
gc = GaussianConditional.FromMeanAndStddev(X(0), 2 * I_1x1, X(1), [-4], | ||
5.0) | ||
|
||
# Create the noise models | ||
model0 = noiseModel.Diagonal.Sigmas([2.0]) | ||
model1 = noiseModel.Diagonal.Sigmas([3.0]) | ||
|
||
# Create the conditionals | ||
conditional0 = GaussianConditional(X(1), [5], I_1x1, model0) | ||
conditional1 = GaussianConditional(X(1), [2], I_1x1, model1) | ||
dkeys = DiscreteKeys() | ||
dkeys.push_back(Asia) | ||
gm = GaussianMixture.FromConditionals([X(1)], [], dkeys, | ||
[conditional0, conditional1]) # | ||
|
||
# Create hybrid Bayes net. | ||
bayesNet = HybridBayesNet() | ||
bayesNet.addGaussian(gc) | ||
bayesNet.addMixture(gm) | ||
bayesNet.addDiscrete(Asia, "99/1") | ||
|
||
# Create values at which to evaluate. | ||
values = HybridValues() | ||
values.insert(asiaKey, 0) | ||
values.insert(X(0), [-6]) | ||
values.insert(X(1), [1]) | ||
|
||
conditionalProbability = gc.evaluate(values.continuous()) | ||
mixtureProbability = conditional0.evaluate(values.continuous()) | ||
self.assertAlmostEqual(conditionalProbability * mixtureProbability * | ||
0.99, | ||
bayesNet.evaluate(values), | ||
places=5) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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
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.
Umm why are we including this here (on HybridBayesNet) rather than before HybridBayesTree?
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.
Either way it doesn't matter because the wrapper will bubble it to the top of the generated files, but still seems like a weird thing to do (especially for wrapper noobs).