lundi 3 juillet 2017

Geometric distribution with p = 1

I found in the standard that that std::geometric distribution requires 0 < p < 1 for its termination probability and that std::negative_binomial_distribution requires 0 < p ≤ 1. I'm not sure why the former should be misbehaving for p = 1 (it should just always return 0 with unit probability), especially in the light of the claim that

std::geometric_distribution<>(p) is exactly equivalent to std::negative_binomial_distribution<>(1, p).

Only that I did not find the latter explicitly said in the standard draft. Should I, just to be careful, always use std::negative_binomial_distribution instead of std::geometric distribution when the parameter p can (beyond my control) go as high as 1?


Interestingly, the various sources seem to be quite sloppy on the requirements. For example, www.cplusplus.com and the Boost documentation both say that for std::geometric distribution 0 ≤ p ≤ 1, while p = 0 makes no sense mathematically. (Boost also says that geometric distro is equivalent with negative binomial with r = 1, cplusplus does not.)

Aucun commentaire:

Enregistrer un commentaire