commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: [math] Re: binomial random generator
Date Mon, 24 Oct 2011 04:19:07 GMT
On 10/22/11 8:40 PM, Ahmed Abdeen Hamed wrote:
> Hi Phil,
>
> Thanks very much for your quick response. I am doing some simulations that
> produce probailities which are in turn must be compared to certains rates.
> Here is an example of what I am doing:
>
>   if (randBinomial.nextBinomial(1, Simulation.MRATE)==1) {
>
> // the condition can be replaced by the following uncommented condition
>
> //randM.nextDouble() < Simulation.M_RATE;
>
>   if (gt[i] == 0) {
>
>    gt[i] = 1;
>
>   } else {
>
>    gt[i] = 0;
>
>   }
>
>   }
>
> Please let me know if I am using Binomial object and its method correctly.

As Ted pointed out, you should not be generating values from the
Binomial distribution here.   That distribution is for the number of
successes in a given number of Bernoulli trials.  The degenerate
case, where the number of trials is 1, can be much more efficiently
handled just generating a random boolean, which can be generated by
a RandomGenerator directly.  As Luc pointed out, there are better
PRNGs in [math] than the JDK-supplied generator.  To use, for
example, a Well generator, just do

RandomGenerator gen = new Well19937c();

and then

gen.nextBoolean();

to generate (pseudo-)random boolean values.

Phil
>
> Thanks again!
>
> Ahmed
>
>
> On Sat, Oct 22, 2011 at 11:29 PM, Phil Steitz <phil.steitz@gmail.com> wrote:
>
>> On 10/22/11 8:15 PM, Ahmed Abdeen Hamed wrote:
>>> Hello friends,
>>>
>>> I am using the following code in a program I am writing:
>>>     private static JDKRandomGenerator rg = new JDKRandomGenerator();
>>>     private static RandomDataImpl randBinomial = new RandomDataImpl(rg);
>>>
>>> However, it is slowing down things very much. When I replace generator
>> with
>>> a java.util.Random object it works fine without the performance issues.
>> Is
>>> that expected with this library? Is there any work around? My programs
>> are
>>> very time consuming and I have been repeatedly running them. I really
>> need
>>> some tips if there is anything I can do to enhance the performance.
>> That depends on how you are using randBinomial above.  Can you share
>> the code that uses randBinomial and what you mean by "replace
>> generator with a java.util.Random object?"  It will also help to
>> describe what exactly you are trying to accomplish with the code.
>>
>> Phil
>>> Thanks very much!
>>> Ahmed
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message