Re: Re: More Inquiries
- To: mathgroup at smc.vnet.net
- Subject: [mg91297] Re: [mg91250] Re: [mg91163] More Inquiries
- From: Darren Glosemeyer <darreng at wolfram.com>
- Date: Thu, 14 Aug 2008 06:59:26 -0400 (EDT)
- References: <200808111007.GAA11237@smc.vnet.net>
> RandomReal > > BurrDistribution /: RandomReal[ > BurrDistribution[c_?NumericQ, k_?NumericQ]] := > > InverseCDF[BurrDistribution[c, k], RandomReal[]]; > > BurrDistribution /: RandomReal[ > BurrDistribution[c_?NumericQ, k_?NumericQ], > n_Integer?Positive] := > > > > > Table[InverseCDF[BurrDistribution[c, k], RandomReal[]], {n}]; Just wanted to add a note on efficiency of random number generation and on some available documentation and utilities that are relevant for anyone who is interested in this type of thing. When it is possible to get more than one RandomReal (or RandomInteger, RandomChoice) at a time, and/or use vector evaluation, this will typically be faster than direct one at a time evaluation. In this case, we could reduce to one RandomReal call and use vector evaluation (though most of the speed gain comes from the vector evaluation). For the generator we could use the following: In[1]:= randomBurr[c_?Positive, k_?Positive, n_Integer?Positive] := ((1 - RandomReal[1, n])^(-1/k) - 1)^(1/c) In[2]:= Timing[randomBurr[1, 2, 10^6];] Out[2]= {0.875, Null} In comparison, here is the timing for the direct one at a time evaluation approach In[3]:= BurrDistribution /: InverseCDF[BurrDistribution[c_, k_], q_] := ((1 - q)^(-1/k) - 1)^(1/c); In[4]:= Timing[Table[ InverseCDF[BurrDistribution[1, 2], RandomReal[]], {10^6}];] Out[4]= {5.906, Null} Also, there is a section in the Random Number Generation tutorial ( tutorial/RandomNumberGeneration in the Documentation Center or http://reference.wolfram.com/mathematica/tutorial/RandomNumberGeneration.html online) titled "Defining Distributions" which discusses how additional distributional generators can be defined using some built-in utilities so that they work like RandomReal|RandomInteger[builtinDistribution,...]. Darren Glosemeyer Wolfram Research
- References:
- Re: More Inquiries
- From: Bob Hanlon <hanlonr@cox.net>
- Re: More Inquiries