-
Notifications
You must be signed in to change notification settings - Fork 767
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
Hybrid Bayes Net sampling #1347
Conversation
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.
Two comments:
- given should be HybridValues
- Model should not be needed
gtsam/hybrid/HybridBayesNet.cpp
Outdated
@@ -232,6 +235,43 @@ VectorValues HybridBayesNet::optimize(const DiscreteValues &assignment) const { | |||
return gbn.optimize(); | |||
} | |||
|
|||
/* ************************************************************************* */ | |||
HybridValues HybridBayesNet::sample(VectorValues given, std::mt19937_64 *rng, | |||
SharedDiagonal model) const { |
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.
Given should be const&, and model should not be there I think (per my email to you).
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.
Interesting. I followed the signature in the other sample methods, so maybe update there as well?
Also it can't be const
since DiscreteBayesNet does a sampleInPlace(&given)
and GaussianBayesNet
has the line given.insert(sampled);
. Would you like me to update those to make them functional?
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.
Oh, now I remember! It is passed by value deliberately, to allow for updating it in-place.
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 add that in comment so we don’t forget again
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 updated GaussianBayesNet::sample
to be functional. So instead of given.insert(sampled)
, it is now result.insert(sampled)
with result
initialized as VectorValues result(given);
.
Perfectly backwards compatible. :)
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.
Yeah, not really :-) the argument was passed by value which makes a copy, functionally equivalent to what you changed it to. Modulo possible compiler optimizations that might do something different - no idea which one is best.
This reverts commit 4fc02a6.
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.
Ok, I think one of your changes in GC was not strictly needed, but I think it does not make a performance difference, so let’s go with it.
@@ -64,8 +64,9 @@ namespace gtsam { | |||
return sample(result, rng); | |||
} | |||
|
|||
VectorValues GaussianBayesNet::sample(VectorValues result, | |||
VectorValues GaussianBayesNet::sample(const VectorValues& given, |
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.
Ok, for this case, the question is whether it should be value (which will automatically make the copy you inserted below) or by const&, which you modified this code to. I chose by value when implementing this so I would get the automatic copy, but maybe it does not make a difference and it is more “clever than smart”. The code that was here was correct, though.
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 agree it was correct. I felt this made it clearer to read that you're given
some VectorValues and you're getting back the result
of sampling.
I can undo this if you'd like.
@@ -79,7 +80,7 @@ namespace gtsam { | |||
return sample(&kRandomNumberGenerator); | |||
} | |||
|
|||
VectorValues GaussianBayesNet::sample(VectorValues given) const { | |||
VectorValues GaussianBayesNet::sample(const VectorValues& given) const { |
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.
This, for sure, is a positive change.
This PR adds a
sample
method to theHybridBayesNet
, which operates as follows:VectorValues
from the selected Gaussian bayes net.HybridValues
.