-
Notifications
You must be signed in to change notification settings - Fork 20
Upgrade to work with latest GTSAM #39
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
506f0c9
Use std:: instead of boost::
varunagrawal 4346729
implement required DiscreteFactor methods and get tests passing
varunagrawal 3286428
improve CMake
varunagrawal 73e0d9e
implement methods and fix warnings
varunagrawal 1b8a364
comment out extra print
varunagrawal 79fbcce
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ class DCDiscreteFactor : public gtsam::DiscreteFactor { | |
| private: | ||
| gtsam::DiscreteKeys discreteKeys_; | ||
| gtsam::KeyVector continuousKeys_; | ||
| boost::shared_ptr<DCFactor> dcfactor_; | ||
| std::shared_ptr<DCFactor> dcfactor_; | ||
| gtsam::Values continuousVals_; | ||
| DiscreteValues discreteVals_; | ||
|
|
||
|
|
@@ -52,7 +52,7 @@ class DCDiscreteFactor : public gtsam::DiscreteFactor { | |
| DCDiscreteFactor() = default; | ||
|
|
||
| DCDiscreteFactor(const gtsam::DiscreteKeys& discreteKeys, | ||
| boost::shared_ptr<DCFactor> dcfactor) | ||
| std::shared_ptr<DCFactor> dcfactor) | ||
| : discreteKeys_(discreteKeys), | ||
| continuousKeys_(dcfactor->keys()), | ||
| dcfactor_(dcfactor) { | ||
|
|
@@ -61,7 +61,7 @@ class DCDiscreteFactor : public gtsam::DiscreteFactor { | |
| for (const gtsam::DiscreteKey& k : discreteKeys_) keys_.push_back(k.first); | ||
| } | ||
|
|
||
| explicit DCDiscreteFactor(boost::shared_ptr<DCFactor> dcfactor) | ||
| explicit DCDiscreteFactor(std::shared_ptr<DCFactor> dcfactor) | ||
| : discreteKeys_(dcfactor->discreteKeys()), | ||
| continuousKeys_(dcfactor->keys()), | ||
| dcfactor_(dcfactor) { | ||
|
|
@@ -82,7 +82,7 @@ class DCDiscreteFactor : public gtsam::DiscreteFactor { | |
|
|
||
| virtual ~DCDiscreteFactor() = default; | ||
|
|
||
| bool equals(const DiscreteFactor& other, double tol = 1e-9) const override { | ||
| bool equals(const DiscreteFactor& other, [[maybe_unused]] double tol = 1e-9) const override { | ||
| if (!dynamic_cast<const DCDiscreteFactor*>(&other)) return false; | ||
| const DCDiscreteFactor& f(static_cast<const DCDiscreteFactor&>(other)); | ||
| return (dcfactor_->equals(*f.dcfactor_) && | ||
|
|
@@ -102,11 +102,79 @@ class DCDiscreteFactor : public gtsam::DiscreteFactor { | |
| return dcfactor_->conditionalTimes(f, continuousVals_, discreteVals_); | ||
| } | ||
|
|
||
| double operator()(const DiscreteValues& values) const override { | ||
| virtual DiscreteFactor::shared_ptr operator*(double s) const override { | ||
| return toDecisionTreeFactor() * s; | ||
| } | ||
|
|
||
| double operator()(const DiscreteValues& values) const { | ||
| assert(allInitialized()); | ||
| return exp(-dcfactor_->error(continuousVals_, values)); | ||
| } | ||
|
|
||
| void print(const std::string& s = "DCDiscreteFactor:\n", | ||
| const gtsam::KeyFormatter& formatter = | ||
| gtsam::DefaultKeyFormatter) const override { | ||
| toDecisionTreeFactor().print(s, formatter); | ||
| continuousVals_.print("Continuous values: ", formatter); | ||
| discreteVals_.print("Discrete values: ", formatter); | ||
| } | ||
|
|
||
| double evaluate(const gtsam::Assignment<gtsam::Key>& values) const override { | ||
| return this->operator()(DiscreteValues(values)); | ||
| } | ||
|
|
||
| virtual DiscreteFactor::shared_ptr multiply( | ||
| const DiscreteFactor::shared_ptr& df) const override { | ||
| return toDecisionTreeFactor().multiply(df); | ||
| } | ||
|
|
||
| /// divide by DiscreteFactor::shared_ptr f (safely) | ||
| virtual DiscreteFactor::shared_ptr operator/( | ||
| const DiscreteFactor::shared_ptr& df) const override { | ||
| throw toDecisionTreeFactor() / df; | ||
|
Collaborator
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. Interesting!
Contributor
Author
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. This might change in the future TBH. I want to abstract out the underlying storage mechanism. |
||
| } | ||
|
|
||
| /// Create new factor by summing all values with the same separator values | ||
| virtual DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override { | ||
| return toDecisionTreeFactor().sum(nrFrontals); | ||
| } | ||
|
|
||
| /// Create new factor by summing all values with the same separator values | ||
| virtual DiscreteFactor::shared_ptr sum( | ||
| const gtsam::Ordering& keys) const override { | ||
| return toDecisionTreeFactor().sum(keys); | ||
| } | ||
|
|
||
| /// Find the maximum value in the factor. | ||
| virtual double max() const override { | ||
| return toDecisionTreeFactor().max(); | ||
| } | ||
|
|
||
| /// Create new factor by maximizing over all values with the same separator. | ||
| virtual DiscreteFactor::shared_ptr max(size_t nrFrontals) const override { | ||
| return toDecisionTreeFactor().max(nrFrontals); | ||
| } | ||
|
|
||
| /// Create new factor by maximizing over all values with the same separator. | ||
| virtual DiscreteFactor::shared_ptr max( | ||
| const gtsam::Ordering& keys) const override { | ||
| return toDecisionTreeFactor().max(keys); | ||
| } | ||
|
|
||
| /** | ||
| * Get the number of non-zero values contained in this factor. | ||
| * It could be much smaller than `prod_{key}(cardinality(key))`. | ||
| */ | ||
| virtual uint64_t nrValues() const override { | ||
| return toDecisionTreeFactor().nrValues(); | ||
| } | ||
|
|
||
| /// Restrict the factor to the given assignment. | ||
| virtual DiscreteFactor::shared_ptr restrict( | ||
| const DiscreteValues& assignment) const override { | ||
| return toDecisionTreeFactor().restrict(assignment); | ||
| } | ||
|
|
||
| void updateContinuous(const gtsam::Values& continuousVals) { | ||
| for (const gtsam::Key& k : continuousKeys_) { | ||
| // If key `k` is not set continuousVals, skip it. | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.