|
Boost Users : |
Subject: Re: [Boost-users] [Math/Statistical Distributions+Random] Random number generation
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2009-04-17 17:31:42
On Fri, Apr 17, 2009 at 9:24 PM, er <erwann.rogard_at_[hidden]> wrote:
>
> Maybe automate the stated requirement?
>
> (not tested):
>
> template<typename D>
> struct math_to_random{};
>
> template<typename T,typename P>
> struct math_to_random<math::exponential_distribution<T,P> >{
> typedef exponential_distribution<T> type;
> };
>
>
> etc.
>
> template<typename G,typename T,typename P>
> variate_generator<
> G&,
> math_to_random<math::exponential_distribution<T,P> >::type
>>
> make_variate_generator(
> G& rng,
> const math::exponential_distribution<T,P>& dist0
> ){
> typedef typename math_to_random<exponential_distribution<T,P> >::type rd_t;
> typename variate_generator<
> G&,
> rd_t
>> vg_t;
>
> rd_t rd(dist0.lambda());
> return vg_t(rng,dist)
> }
>
Thanks er!
This would be a good starting point, even if the resulting code might
be penalized in performance and resource consumption (e.g., for the
(math::) exponential distribution it is needed to instantiate another
(random::) exponential distribution -- and duplicating state
information like the distribution parameters -- only for the random
generation function).
The point is that, from the point of view of a "user" of the lib, I
think that writing the "gateway" function "make_variate_generator" for
every distribution of interest may result in overwork.
I think that (always from a point of view of a user) the use of the
"rand" function (as the one I suggested above), "stoling" the random
generation from the boost::random::*_distribution classes would take
less time and may result in faster code.
Maybe this integration can be done by the library developers if they
think it would be useful to provide to library users a simplified
"rand" function facility for generating random number generators
distributed according to a given distribution.
Thank you very much!!
Cheers
-- Marco
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