ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 16 Jun 2013 14:28:05 +0200Probability density functionhttps://ask.sagemath.org/question/10242/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?
Waiting for your answers.
Thanks a lot.
Fri, 14 Jun 2013 20:00:45 +0200https://ask.sagemath.org/question/10242/probability-density-function/Answer by mresimulator for <p>Hi experts!</p>
<p>In a line like this:</p>
<pre><code>uniforme_x=RealDistribution('uniform',[a,b])
</code></pre>
<p>i call a 'uniform' probability density function: <code>f(t)=1/(b-a)</code>, <code>a<t<b</code>.</p>
<p>In addition, SAGE includes several probability density function: gaussian, log-normal, etc.</p>
<p>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?</p>
<p>Waiting for your answers.</p>
<p>Thanks a lot.</p>
https://ask.sagemath.org/question/10242/probability-density-function/?answer=15095#post-id-15095I 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.Sun, 16 Jun 2013 14:28:05 +0200https://ask.sagemath.org/question/10242/probability-density-function/?answer=15095#post-id-15095Answer by vdelecroix for <p>Hi experts!</p>
<p>In a line like this:</p>
<pre><code>uniforme_x=RealDistribution('uniform',[a,b])
</code></pre>
<p>i call a 'uniform' probability density function: <code>f(t)=1/(b-a)</code>, <code>a<t<b</code>.</p>
<p>In addition, SAGE includes several probability density function: gaussian, log-normal, etc.</p>
<p>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?</p>
<p>Waiting for your answers.</p>
<p>Thanks a lot.</p>
https://ask.sagemath.org/question/10242/probability-density-function/?answer=15087#post-id-15087Hi,
The answer is probabilistic and may be found in most probability or statistics book. You may also have a look at [wikipedia](http://en.wikipedia.org/wiki/Cumulative_distribution_function)
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]).Sat, 15 Jun 2013 10:05:09 +0200https://ask.sagemath.org/question/10242/probability-density-function/?answer=15087#post-id-15087