fixed a corner case in DiscreteDistribution::sample
parent
aec0c6a984
commit
eb423bf9f9
|
@ -124,8 +124,15 @@ public:
|
||||||
inline size_t sample(Float sampleValue) const {
|
inline size_t sample(Float sampleValue) const {
|
||||||
std::vector<Float>::const_iterator entry =
|
std::vector<Float>::const_iterator entry =
|
||||||
std::lower_bound(m_cdf.begin(), m_cdf.end(), sampleValue);
|
std::lower_bound(m_cdf.begin(), m_cdf.end(), sampleValue);
|
||||||
size_t index = (size_t) std::max((ptrdiff_t) 0, entry - m_cdf.begin() - 1);
|
size_t index = std::min(m_cdf.size()-2,
|
||||||
return std::min(index, m_cdf.size()-2);
|
(size_t) std::max((ptrdiff_t) 0, entry - m_cdf.begin() - 1));
|
||||||
|
|
||||||
|
/* Handle a rare corner-case where a entry has probability 0
|
||||||
|
but is sampled nonetheless */
|
||||||
|
while (operator[](index) == 0 && index < m_cdf.size()-1)
|
||||||
|
++index;
|
||||||
|
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -204,6 +204,7 @@ public:
|
||||||
if (suitabilities.normalize() == 0) {
|
if (suitabilities.normalize() == 0) {
|
||||||
/* No mutator can handle this path -- give up */
|
/* No mutator can handle this path -- give up */
|
||||||
accumulatedWeight += m_config.chainLength - it;
|
accumulatedWeight += m_config.chainLength - it;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mutatorIdx = (int) suitabilities.sample(m_indepSampler->next1D());
|
mutatorIdx = (int) suitabilities.sample(m_indepSampler->next1D());
|
||||||
|
|
Loading…
Reference in New Issue