Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-05-20 14:24:44

Donald_Gaffney wrote:
> I've coded a Poisson distribution for possible inclusion in the
> boost random library. I've attached the gzipped patch to the
> last boost release,

Thank you for your contribution. Here are a few comments:

 - You've written that file yourself, so please replace my name
in the copyright statement with your name throughout. Personally,
I favor full names instead of abbreviations, i.e. "William" instead
of "Bill" or "Donald" instead of "Don".
 - The Poisson distribution is an integer-valued distribution.
Therefore, having a result_type template parameter named "RealType"
with a default of "double" seems inappropriate.
 - In a few places, local variables could do where you currently
use member variables, e.g. _x.
 - The initialization in the !_valid block should be in the
constructor. After all, that's what constructors are there for.
It is unlikely that anyone will construct a poisson_distribution<>
without actually calling operator() on it. This also removes the
need for the _valid variable, and avoids a conditional jump in
operator(), a potential fast path.
 - The recur() function call should be folded into the
initialization, since it has the same case distinction (j==0 or not)
than is already present in the main init code. That means that
the _poiss variable can be a local variable of the constructor.
 - You need to #include <vector>
 - Instead of using std::vector::push_back, it may be better to
initialize the vector with the number of elements _n and then
use an iterator to fill it. That may save several (potentially
expensive) reallocations.
 - mean and sigma are never used again, so when the initialization
is moved to the constructor, those are not required to be member

Please re-submit, to me privately if you wish.

> I noticed there is also a Cauchy distribution in the random
> library. Is this supposed to be the same as the Lorentzian
> distribution?

I don't know. The probability density of the Cauchy distribution is
  p(x) = sigma/(pi*(sigma**2 + (x-median)**2))
where sigma and median are parameters.

Jens Maurer

Boost list run by bdawes at, gregod at, cpdaniel at, john at