-
Notifications
You must be signed in to change notification settings - Fork 779
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
Add various tests for Hybrid #1220
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2396bca
Add GaussianMixture tests
varunagrawal fc939b0
GaussianMixtureFactor tests
varunagrawal 60e3321
some formatting and improved printing
varunagrawal 8b03eb5
move += operator inside namespace
varunagrawal f6b86fb
address review comments
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
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,92 @@ | ||
/* ---------------------------------------------------------------------------- | ||
|
||
* 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 testGaussianMixture.cpp | ||
* @brief Unit tests for GaussianMixture class | ||
* @author Varun Agrawal | ||
* @author Fan Jiang | ||
* @author Frank Dellaert | ||
* @date December 2021 | ||
*/ | ||
|
||
#include <gtsam/discrete/DiscreteValues.h> | ||
#include <gtsam/hybrid/GaussianMixture.h> | ||
#include <gtsam/inference/Symbol.h> | ||
#include <gtsam/linear/GaussianConditional.h> | ||
|
||
#include <vector> | ||
|
||
// Include for test suite | ||
#include <CppUnitLite/TestHarness.h> | ||
|
||
using namespace std; | ||
using namespace gtsam; | ||
using noiseModel::Isotropic; | ||
using symbol_shorthand::M; | ||
using symbol_shorthand::X; | ||
|
||
/* ************************************************************************* */ | ||
TEST(GaussianConditional, Equals) { | ||
// create a conditional gaussian node | ||
Matrix S1(2, 2); | ||
S1(0, 0) = 1; | ||
S1(1, 0) = 2; | ||
S1(0, 1) = 3; | ||
S1(1, 1) = 4; | ||
|
||
Matrix S2(2, 2); | ||
S2(0, 0) = 6; | ||
S2(1, 0) = 0.2; | ||
S2(0, 1) = 8; | ||
S2(1, 1) = 0.4; | ||
|
||
Matrix R1(2, 2); | ||
R1(0, 0) = 0.1; | ||
R1(1, 0) = 0.3; | ||
R1(0, 1) = 0.0; | ||
R1(1, 1) = 0.34; | ||
|
||
Matrix R2(2, 2); | ||
R2(0, 0) = 0.1; | ||
R2(1, 0) = 0.3; | ||
R2(0, 1) = 0.0; | ||
R2(1, 1) = 0.34; | ||
|
||
SharedDiagonal model = noiseModel::Diagonal::Sigmas(Vector2(1.0, 0.34)); | ||
|
||
Vector2 d1(0.2, 0.5), d2(0.5, 0.2); | ||
|
||
auto conditional0 = boost::make_shared<GaussianConditional>(X(1), d1, R1, | ||
X(2), S1, model), | ||
conditional1 = boost::make_shared<GaussianConditional>(X(1), d2, R2, | ||
X(2), S2, model); | ||
|
||
// Create decision tree | ||
DiscreteKey m1(1, 2); | ||
GaussianMixture::Conditionals conditionals( | ||
{m1}, | ||
vector<GaussianConditional::shared_ptr>{conditional0, conditional1}); | ||
GaussianMixture mixtureFactor({X(1)}, {X(2)}, {m1}, conditionals); | ||
|
||
// Let's check that this worked: | ||
DiscreteValues mode; | ||
mode[m1.first] = 1; | ||
auto actual = mixtureFactor(mode); | ||
EXPECT(actual == conditional1); | ||
} | ||
|
||
/* ************************************************************************* */ | ||
int main() { | ||
TestResult tr; | ||
return TestRegistry::runAllTests(tr); | ||
} | ||
/* ************************************************************************* */ | ||
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. newline |
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.
document the equations here (2 gaussians)