![]() ![]() Max_iterations - maximum number of 'tries' to find a combination of random numbers (rand_x, rand_y) located below the function value calc_y = pdf(rand_x). Integers - boolean, indicating if the result is desired as integer Pdfmax - the maximum of the probability density function Interval - the resulting random number is restricted to this interval Pdf - the function pointer to a probability density function of form P = pdf(x) """ĭraws a random number from given probability density function. Of course n random numbers can be generated by calling this function n times. This is my function to retrieve a single random number distributed according to the given probability density function. Numerical methods may be useful, as numerical integration can be used to create the CDF and interpolation can be used to invert it. It really depends on your distribution, sometimes you may have an analytical function, sometimes you may want to resort to interpolation. Of course, the difficult part is obtaining the inverse cumulative density function. At 0 it is 10, at 12 it is 1, and changes linearly between the values Inverse cumulative distribution function is only defined between 0 and 1. Probability distribution function is 0.5 between 10 and 12, zero elsewhereĬumulative distribution function is 0 below 10 (no samples below 10), 1 above 12 (no samples above 12) and increases linearly between the values (integral of the PDF) ![]() To illustrate the nature of icdf, we'll take a simple uniform distribution between values 10 and 12 as an example: In both cases icdf is the inverse cumulative distribution function which accepts a value between 0 and 1 and outputs the corresponding value from the distribution. Once you have that, then generating the random numbers along the distribution is simple: import random In general, you want to have the inverse cumulative probability density function. ![]()
0 Comments
Leave a Reply. |