How do you use scipy.stats.rv_continuous?

I was looking for a good tutorial or examples of using rv_continuous and I could not find it.

I read:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html#scipy.stats.rv_continuous

but in fact it was not very useful (and there were no examples of how to use it).

An example of something that I would like to do is to indicate any probability distributions and the ability to call fit , and then just just have the pdf file I wanted, and be able to call expect and get the desired expected value.

Until now, I understand that to create any possible distribution, we need to create our own class for it, and then a subclass of rv_continuous . Then, specifying a custom _pdf or _cdf , we should just use every method that rv_continuous will provide us with. For example, expect and fit should be available.

However, for me, the really mysterious thing is, if we do not say rv_continy explicitly, what parameters determine the probability distribution, can it really use all these methods correctly? How to do this even with _pdf or _cdf?

Or did I just misunderstand how this works?

Also, if you can provide a simple example of how it works and how to use expect and / or fit , that would be great! Or maybe the best tutorial or link, it will be cool.

Thanks at Advance.

+8
python numpy scipy
source share
1 answer

Here is a tutorial: http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html

Basically, rv_continuous is done for a subclass. Use it if you need a distribution that is not defined in scipy.stats (there are more than 70 of them).

How does he work. In a nutshell, it uses common code codes: if your subclass defines _pdf and does not define _logpdf , it inherits

 def _logpdf(self, x, *args): return log(self._pdf(x, *args)) 

and a bunch of similar methods (see https://github.com/scipy/scipy/blob/master/scipy/stats/_distn_infrastructure.py for exact details).

Options

Re. You probably mean form parameters, right? They are automatically output using inspect with the signature _pdf or _cdf , see https://github.com/scipy/scipy/blob/master/scipy/stats/_distn_infrastructure.py#L617 . If you want to bypass the check, specify shapes for the constructor of your instance:

 class Mydist(stats.rv_continuous): def _pdf(self, x, a, b, c, d): return 42 mydist = Mydist(shapes='a, b, c, d') 

[Strictly speaking, this applies only to scipy 0.13 and higher. Earlier versions used a different mechanism and required the shapes attribute.]

+8
source share

All Articles