Can std::discrete_distribution be used with some zero weights, assuming that at least one positive weight was given? The items with zero weights should simply never be sampled.
The fact that it appears to work on my machine does not give me confidence that it will work on all systems.
Example:
std::discrete_distribution<> dd({1.0, 2.0, 0.0, 3.0});
Per [rand.dist.samp.discrete]/2
Unless specified otherwise, the distribution parameters are calculated as:
pk = wk / Sfork = 0, ..., n−1, in which the values wk, commonly known as the weights, shall be non-negative, non-NaN, and non-infinity. Moreover, the following relation shall hold:0 < S = w0 + ... + wn−1.
So zero weights are allowed, but not all of the weights can be zero since S must be greater than zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With