|
|
Subject:
Random Number Sampling
Category: Science > Math Asked by: simontrumpet-ga List Price: $10.00 |
Posted:
13 Aug 2002 05:48 PDT
Expires: 12 Sep 2002 05:48 PDT Question ID: 54001 |
what is the best algorithm to generate a random sample from a beta probability distribution? | |
| |
|
|
Subject:
Re: Random Number Sampling
Answered By: maniac-ga on 14 Aug 2002 18:30 PDT Rated: |
Hello Simontrumpet, May I suggest a quick look at the documentation for the GNU Scientific Library (GSL)? The Beta Distribution is described at... http://sources.redhat.com/gsl/ref/gsl-ref_19.html#SEC300 which has the formula listed. You may be able to use the source code, available as described at... http://www.gnu.org/software/gsl/#downloading The function is defined as gsl_ran_beta (const gsl_rng * r, double a, double b), which allows you to pass the address of the random function (your Mersenne Twister algorithm if it matches the function prototype), as well as values for A and B. If you can't comply with the license requirements of the GSL, you could have someone implement the appropriate algorithm as defined in the first link. If you need something with less restrictive licenses, please ask as a clarifiction and I will do some more digging on this problem. --Maniac | |
| |
|
simontrumpet-ga
rated this answer:
Thank you, the answer was fine ... I didn't use it in the end, as I found a better way to do it myself, but I think I could have done! Thanks agin, all the best, simon. |
|
Subject:
Re: Random Number Sampling
From: tne-ga on 14 Aug 2002 00:46 PDT |
x * (b-a) + a, 0 < a < b, 0 <= x <= 1 |
Subject:
Re: Random Number Sampling
From: simontrumpet-ga on 14 Aug 2002 03:10 PDT |
Dear tne-ga What is your x, is it my U(0,1)? In which case, your anser just gives me U(a,b), not Beta(a,b)!! Unless I misunderstood your comment? Thanks anyway! |
Subject:
Re: Random Number Sampling
From: chinaski-ga on 14 Aug 2002 15:13 PDT |
Simon, This is certainly not the best way to get random deviates with a beta distribution, but it works and is easy to code. Let f(x) be your Beta pdf (0<x<1), and let m bet the maximum value that your Beta pdf attains, which you can easily work out. Step 1: Pick the random number u from U(0,1). Step 2: Pick the random number z from U(0,m). Step 3: If z<f(u), print u. Otherwise return to step 1. The numbers u that you have printed out will have a Beta pdf. It's not optimally fast, because often you have to cycle through the steps without printing anything, but it works. chinaski |
Subject:
Re: Random Number Sampling
From: tne-ga on 15 Aug 2002 20:02 PDT |
Whoops! I answered before I read the whole question B(a, b) = integral (0, 1) (u^(a − 1) ) * ( (1 − u)^ (b−1) ) du source http://www.math.uah.edu/stat/special/special9.html |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |