Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@varunagrawal
Copy link
Contributor

@varunagrawal varunagrawal commented Dec 23, 2022

This PR adds a sample method to the HybridBayesNet, which operates as follows:

  1. Compute the discrete bayes net.
  2. Sample discrete assignment from the discrete bayes net.
  3. Select the Gaussian bayes net corresponding to the sampled assignment.
  4. Sample continuous VectorValues from the selected Gaussian bayes net.
  5. Return both samples as HybridValues.

@varunagrawal varunagrawal self-assigned this Dec 23, 2022
Copy link
Member

@dellaert dellaert left a 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


/* ************************************************************************* */
HybridValues HybridBayesNet::sample(VectorValues given, std::mt19937_64 *rng,
SharedDiagonal model) const {
Copy link
Member

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).

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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. :)

Copy link
Member

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.

Copy link
Member

@dellaert dellaert left a 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.

}

VectorValues GaussianBayesNet::sample(VectorValues result,
VectorValues GaussianBayesNet::sample(const VectorValues& given,
Copy link
Member

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.

Copy link
Contributor Author

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.

}

VectorValues GaussianBayesNet::sample(VectorValues given) const {
VectorValues GaussianBayesNet::sample(const VectorValues& given) const {
Copy link
Member

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.

@varunagrawal varunagrawal merged commit 2abc0d9 into develop Dec 24, 2022
@varunagrawal varunagrawal deleted the hybrid/sample branch December 24, 2022 14:32
@dellaert dellaert added this to the Hybrid Inference milestone Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants