您如何使用scipy.stats.rv_continuous? [英] How do you use scipy.stats.rv_continuous?

查看:346
本文介绍了您如何使用scipy.stats.rv_continuous?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找很好的教程或使用rv_continuous的示例,但找不到.

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.

我读到

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

但这并不是真正有用的东西(并且它没有任何使用方法的示例).

but it was not really all that helpful (and it lacked any examples of how to use it).

我想做的事情的一个例子是,指定任何概率分布并能够调用fit,然后只需简单地拥有我想要的pdf并能够调用expect并获得期望的期望值.

An example of something that I wanted to be able to do is to, specify any probability distributions and being able to call fit and then just simply having the pdf that I wanted and be able to call expect and get the desired expected value.

到目前为止,我了解的是要创建任何可能的发行版,我们需要为其创建自己的类,然后再子类.然后,通过指定自定义_pdf_cdf,我们应该能够简单地使用rv_continuous为我们提供的每种方法.像expectfit这样应该现在可用.

The thing I understand so far is that to create any probably distribution, we need to create our own class for it and then subclass rv_continuous. Then by specifying a custom _pdf or _cdf we should be able to simply use every method that rv_continuous would provide for us. Like expect and fit should be available now.

但是,对我而言真正神秘的是,如果我们不明确地告诉rv_continuous,哪些参数指定了概率分布,那么它真的能够正确地完成所有这些方法吗?甚至使用_pdf或_cdf怎么做?

However, the thing that is really mysterious for me is, if we don't tell rv_continuous explicitly what the parameters are that specify the probability distribution, is it really able to do all those methods correctly? How does it even do it just with _pdf or _cdf?

还是我只是误解了它的工作原理?

Or did I just misunderstand how it works?

此外,如果您可以提供一个简单的示例,说明其工作方式以及如何使用expect和/或fit,那就太棒了!或者,也许更好的教程或链接会很酷.

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

预先感谢.

推荐答案

以下是教程: http ://docs.scipy.org/doc/scipy/reference/tutorial/stats.html

基本上,rv_continuous用于子类化.如果您需要scipy.stats中未定义的发行版(其中有70多个),请使用它.

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).

重新运作.简而言之,它使用通用的代码路径:如果您的子类定义了_pdf而没有定义_logpdf,则它继承了

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))

和其他类似方法(请参见 https://github.com/scipy /scipy/blob/master/scipy/stats/_distn_infrastructure.py 了解详细信息).

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

重新参数.您可能是指形状参数,对吗?通过inspect标记_pdf_cdf可以自动推断出它们,请参见

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')

[严格来说,这仅适用于scipy 0.13及更高版本.早期版本使用了不同的机制,并且需要shapes属性.]

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

这篇关于您如何使用scipy.stats.rv_continuous?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆