Boost logo

Boost Users :

Subject: Re: [Boost-users] [random]: several issues
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-23 21:17:38


AMDG

Thomas Mang wrote:
> Steven Watanabe wrote:
>> Thomas Mang wrote:
>>> After some time I came back to the boost random library, and several
>>> things I noticed earlier have not changed since years ago. I hereby
>>> ask what the present state of ideas regarding these ideas is.
>>>
>>> Here's my list:
>>>
>>> a) The library itself provides files for random deviates of
>>> distributions not given in the documentation (e.g. poisson, gamma)
>>> etc. I find it truly sad that implementation and documentation is
>>> that out of synchronisation
>>>
>>> b) Several distributions require the engine to return a uniform
>>> deviate between [0,1), while other's don't have this prerequisite. I
>>> find this extremely error prone and purely documented (it is
>>> documented, but it should be so clearer, and especially, louder).
>>> Worse, I find it even harder (or impossible) to find out which range
>>> the engines return. I am not sure if there is any engine returning
>>> this range per se, or if I have always to go through uniform_01.
>>> Worst of all, there is neither a compile time check nor a runtime
>>> check if that [0,1) result-requirement of the engine holds (as far
>>> as I have seen the code) - I absolutely fail to see why such a
>>> critical assert is completely missing, also given the poor state of
>>> the documentation.
>>> The poisson and gamma for example also fall in this category, but
>>> are not documented at all. I consider this highly dangerous.
>>
>> You're not supposed to use the distributions directly.
>> boost::variate_generator works with any engine and
>> any distribution.
>
> Well, in C++ there are many things one is not supposed to do, but
> that's not the point here. Does it really hurt that much to implement
> an assert in the distributions that the random draw was restricted to
> [0,1) ? (which can be done for the engines provided by boost at
> compile-time even, at least mostly I think)?

This should be easy. Patches welcome :).

However, the new standard eliminates variate_generator and requires that
every random number engine work with every distribution. Eventually,
Boost.Random needs to be brought into line with this.

> Also if I am not supposed to use the distributions directly, then the
> interface of them is too public to me.

The interface for distributions needs to be specified so that
new distributions can be created that plug into framework.

>>> c) Random numbers are tightly linked to statistical distributions,
>>> offered by the library of it's own. Wouldn't it be convenient to try
>>> to integrate the whole distribution part of the random numbers more
>>> closely into that library? Presently they are too confusingly
>>> standalone.
>>
>> Are you referring to the distributions in Boost.Math?
>
> Yes, boost.Math/Statistical Distributions.
>
> Note that, in general through the inverse of the cdf, a random draw
> can be obtained from any distribution, just for some distribution the
> draw is 'particularly' simple.
> I find it poor from a design point of view to offer random draws of
> distributions in one library, and distributions without random draws
> in another library, and have them +- separate (of course I can
> manually use the inverse of the cdf and a uniform_01 random draw to
> achieve what I want, but this is less a technical issue, but more a
> organizatorial issue).
> My out-of-the-guts intuition is to have the random library only about
> worrying generating random numbers. How to turn these random numbers
> into draws from distributions should be something the distribution
> library worries about. But of course I know the random library has
> been developed long before the distributions library.

Even for distributions for which there is no simple formula for generating
a random variate, there are algorithms that are much more efficient than
using the inverse cdf. Also, random distributions may need to maintain
state that is not needed for any other use of the distributions. There
needs
to be some integration between Boost.Random and Boost.Math, but I'm
not exactly sure how to go about it.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net