commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mikkel Meyer Andersen <m...@mikl.dk>
Subject Re: [math] Generate random data using the Inverse CDF Method?
Date Tue, 27 Oct 2009 11:08:15 GMT
I've attached a prototype diff-proposal where I've changed
AbstractContinuousDistribution and AbstractIntegerDistribution, and
implemented the nextExponential on the ExponentialDistribution as an
example of overwriting the nextSample-method from the
Abstract-distributions.

Only AbstractContinuousDistribution and AbstractIntegerDistribution
extends AbstractDistribution, and both AbstractIntegerDistribution and
AbstractContinuousDistribution has an
inverseCumulativeProbability-function. But in
AbstractContinuousDistribution the inverse cdf returns a double, and
at AbstractIntegerDistribution it - naturally - returns an integer.
Therefor the nextSample is not put on AbstractDistribution, but on
each extension with different return types.

RandomGenerator as parameter instead of getting a RNG inside the
nextSample, because one typically wants to use the same RNG because
often several random samples are wanted. Another option is to have a
RNG as a field in the class, but that would be more ugly and also
result in several RNGs at runtime.

I found an error as well. In RandomDataImpl, mean < 0 throws
exception, whereas in the distribution implementation an exception is
thrown if mean <= 0. RandomDataImpl is corrected to <= in because that
is the correct definition.

The function nextExponential couldn't - without further notice - be
removed from RandomDataImpl, because nextPoisson and the ValueServer
uses the function directly. So here is an issue. nextPoisson can
create a ExponentialDistribution and sample from that. ValueServer
could do the same, but what to you think about it?

As mentioned, the diff is only a prototype hence no formal patch
submitted. And no tests has been made neither. But should I report a
bug or supply a separate patch on the small mean-problem in
nextExponential in RandomDataImpl?

Cheers, Mikkel.


Mime
View raw message