# Probability density function

Hi experts!

In a line like this:

uniforme_x=RealDistribution('uniform',[a,b])


i call a 'uniform' probability density function: f(t)=1/(b-a), a<t<b.

In addition, SAGE includes several probability density function: gaussian, log-normal, etc.

But: How can create in SAGE a probability density function created by me (F(t), DIFFERENT to gaussian, log-normal, etc...) and then create random numbers from it?

Thanks a lot.

edit retag close merge delete

Sort by » oldest newest most voted

Hi,

The answer is probabilistic and may be found in most probability or statistics book. You may also have a look at wikipedia

If m is any probability measure on [a,b], then you may associate its repartition function F(t) = m([a,t]) (which is monotone non-decreasing, takes value in [0,1] and is right-continuous). You may defined an inverse for F given by G(t) = inf {x; F(x) >= t}. Now, given a uniform distributed variable U, F^{-1}(U) is distributed as m on [a,b].

In principle, this may be used to simulate any probability measure. In practice, given a density function, you need to compute the inverse of its primitive with value 0 at a (and hence value 1 at b).

As an example with f(t) = 2*t on [0,1], you obtain a random number generator with

def random_generator():
return sqrt(random())


(because random() is uniformly distributed on [0,1] and sqrt is the inverse of t^2 = primitive(f) on [0,1]).

more

I will re-define my question:

Using scipy.stats module, i'm trying to build a new probability density function, f(x) (not include in scipy module).

I gonna call this function in similar way that other probability density function in scipy, i.e.:

from scipy.stats import new_function.

And do some math with it:

new_function.mean(loc=....., scale= -----), etc.

¿What must i do?

Thanks a lot.

more