make GaussianBayesNet::sample functional

release/4.3a0
Varun Agrawal 2022-12-24 10:21:15 +05:30
parent f6a2e7cf46
commit 77b4028e47
2 changed files with 5 additions and 4 deletions

View File

@ -64,8 +64,9 @@ namespace gtsam {
return sample(result, rng); return sample(result, rng);
} }
VectorValues GaussianBayesNet::sample(VectorValues result, VectorValues GaussianBayesNet::sample(const VectorValues& given,
std::mt19937_64* rng) const { std::mt19937_64* rng) const {
VectorValues result(given);
// sample each node in reverse topological sort order (parents first) // sample each node in reverse topological sort order (parents first)
for (auto cg : boost::adaptors::reverse(*this)) { for (auto cg : boost::adaptors::reverse(*this)) {
const VectorValues sampled = cg->sample(result, rng); const VectorValues sampled = cg->sample(result, rng);
@ -79,7 +80,7 @@ namespace gtsam {
return sample(&kRandomNumberGenerator); return sample(&kRandomNumberGenerator);
} }
VectorValues GaussianBayesNet::sample(VectorValues given) const { VectorValues GaussianBayesNet::sample(const VectorValues& given) const {
return sample(given, &kRandomNumberGenerator); return sample(given, &kRandomNumberGenerator);
} }

View File

@ -110,13 +110,13 @@ namespace gtsam {
* VectorValues given = ...; * VectorValues given = ...;
* auto sample = gbn.sample(given, &rng); * auto sample = gbn.sample(given, &rng);
*/ */
VectorValues sample(VectorValues given, std::mt19937_64* rng) const; VectorValues sample(const VectorValues& given, std::mt19937_64* rng) const;
/// Sample using ancestral sampling, use default rng /// Sample using ancestral sampling, use default rng
VectorValues sample() const; VectorValues sample() const;
/// Sample from an incomplete BayesNet, use default rng /// Sample from an incomplete BayesNet, use default rng
VectorValues sample(VectorValues given) const; VectorValues sample(const VectorValues& given) const;
/** /**
* Return ordering corresponding to a topological sort. * Return ordering corresponding to a topological sort.