[SciPy-user] Definition of random variable
Jonas Kahn
jonas.kahn at math.u-psud.fr
Fri Dec 8 03:03:00 CST 2006
OK, I have read the source of stats.distributions and finally understood
how to define new random variables. I have also written a convenience
function for defining random variables from the pdf only, if anyone is
interested (I know it is in French, but I wrote it for me).
One remark, however, is that we have to call explicitely the cdf before being
allowed to use the rvs..!
That is why there is this strange line "rv_generee.cdf(1)" in the code
below.
Jonas
def genere_une_rv_a_partir_de_pdf(pdf, min_domaine = None, max_domaine =
None):
class rv_gen(scipy.stats.distributions.rv_continuous):
def _pdf(self, x):
return pdf(x)
rv_generee = rv_gen(name ="Pour l'instant je remplis",
a = min_domaine, b = max_domaine)
# Pour avoir accès aux variables aléatoires, il faut d'abord générer
# la
# cdf...
rv_generee.cdf(1)
return rv_generee
On Wed, Dec 06, 2006 at 07:35:40PM +0100, Jonas Kahn wrote:
> Hi
>
> I try to create a new instance of the rv_continuous class, and the __init__
> is not very explicit...
>
> Essentially, I would like to define it from the probability distribution
> only, and I guess (totally without any ground for that) that it is
> implemented as such.
> Especially I would like to use the associated inverse survival function,
> without writing it by myself. Of course I could use the routines for solving
> equations to get it...
> Alternatively, is there any way to get the inverse function of a monotonic
> function?
>
> Thanks for the help
> Jonas
>
> PS: I think there is something wrong with the "scale" parameter in the
> package, or I have not understood how to use it. There is no change to the
> pdf when I try to give it another value as 1:
>
> In [124]: stats.binom.rvs(1,1)
> Out[124]: array([1])
>
> # No problem with loc
> In [126]: stats.binom.rvs(1,1, loc = 10)
> Out[126]: array([11])
>
> # But nothing with scale, with or without loc
> In [127]: stats.binom.rvs(1,1, loc = 10, scale =100)
> Out[127]: array([11])
>
> In [128]: stats.binom.rvs(1,1, scale =100)
> Out[128]: array([1])
>
>
>
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-user
mailing list