How do you use scipy.stats.rv_continuous?

后端 未结 1 391
栀梦
栀梦 2021-01-11 16:08

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.

1条回答
  •  不思量自难忘°
    2021-01-11 16:54

    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 inspecting 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.]

    0 讨论(0)
提交回复
热议问题