-
Notifications
You must be signed in to change notification settings - Fork 765
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 logDensity and evaluate to GaussianBN and HybridBN #1352
Conversation
dellaert
commented
Dec 28, 2022
- Add logDensity and evaluate to GaussianBN and HybridBN
- Added a test to make sure pdf integrates to 1 for 1D GaussianConditionals
- Added a test of sampling to do a Monte Carlo estimate of variance
- Also:
- renamed asDiscreteConditional to asDiscrete to be consistent
- changed the static cast to a dynamic cast for more elegant code
# Conflicts: # gtsam/hybrid/HybridBayesNet.cpp # gtsam/hybrid/tests/testHybridBayesNet.cpp
boost::make_shared<GaussianMixture>(*gaussianMixture); | ||
prunedGaussianMixture->prune(*decisionTree); | ||
auto prunedGaussianMixture = boost::make_shared<GaussianMixture>(*gm); | ||
prunedGaussianMixture->prune(*decisionTree); // imperative :-( |
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.
Should make an issue for this? There may have been a reason why I (a Lisp lover) made this imperative, so it'll be good to re-examine this now.
} | ||
|
||
/* ************************************************************************* */ | ||
GaussianBayesNet HybridBayesNet::choose( | ||
const DiscreteValues &assignment) const { | ||
GaussianBayesNet gbn; | ||
for (auto &&conditional : *this) { | ||
if (conditional->isHybrid()) { | ||
if (auto gm = conditional->asMixture()) { |
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 feel this is less readable just to save 1 line of code, but okay.
} | ||
} | ||
|
||
DiscreteValues mpe = DiscreteFactorGraph(discrete_bn).optimize(); | ||
|
||
// Given the MPE, compute the optimal continuous values. | ||
GaussianBayesNet gbn = this->choose(mpe); | ||
GaussianBayesNet gbn = choose(mpe); |
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 generally like using this
because:
- Specifies this is a class method similar to
self
in python. - Auto-complete works better.
@@ -284,23 +300,20 @@ AlgebraicDecisionTree<Key> HybridBayesNet::error( | |||
|
|||
// Iterate over each conditional. | |||
for (auto &&conditional : *this) { | |||
if (conditional->isHybrid()) { | |||
if (auto gm = conditional->asMixture()) { |
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.
Again, this is more clever but sacrifices readability...
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 feel some readability has been reduced in the Hybrid*
classes but otherwise LGTM.