I have been looking for a good tutorial or examples of how to use rv_continuous
and I have not been able to find one.
I read:
http://docs.scipy.
Here's a tutorial: http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html
Basically, rv_continuous
is made for subclassing. Use it if you need a distribution which is not defined in scipy.stats (there are more than 70 of them).
Re how it works. In a nutshell, it uses generic code paths: if your subclass defines _pdf
and does not define _logpdf
, then 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 precise details).
Re parameters. You probably mean shape parameters, do you? They are inferred automagically by inspect
ing the signature of _pdf
or _cdf
, see https://github.com/scipy/scipy/blob/master/scipy/stats/_distn_infrastructure.py#L617.
If you want to bypass the inspection, provide shapes
parameter to 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 only applies to scipy 0.13 and above. Earlier versions were using a different mechanism and required the shapes
attribute.]