Only sample if not provided

release/4.3a0
Frank Dellaert 2024-09-29 15:42:02 -07:00
parent 8675dc62df
commit 80a4cd1bfc
1 changed files with 6 additions and 1 deletions

View File

@ -58,7 +58,12 @@ DiscreteValues DiscreteBayesNet::sample(DiscreteValues result) const {
// sample each node in turn in topological sort order (parents first) // sample each node in turn in topological sort order (parents first)
for (auto it = std::make_reverse_iterator(end()); for (auto it = std::make_reverse_iterator(end());
it != std::make_reverse_iterator(begin()); ++it) { it != std::make_reverse_iterator(begin()); ++it) {
(*it)->sampleInPlace(&result); const DiscreteConditional::shared_ptr& conditional = *it;
// Sample the conditional only if value for j not already in result
const Key j = conditional->firstFrontalKey();
if (result.count(j) == 0) {
conditional->sampleInPlace(&result);
}
} }
return result; return result;
} }