Only sample if not provided
parent
8675dc62df
commit
80a4cd1bfc
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue