使用 SciPy 拟合征费稳定分布 [英] Using SciPy to Fit a Levy-Stable Distribution

查看:46
本文介绍了使用 SciPy 拟合征费稳定分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 1.2 SciPy 中添加了适合 Levy-Stable 分布的能力.我有一些我想拟合的发行版,但在运行时遇到了一些问题.

In 1.2 SciPy added the ability to fit a Levy-Stable distribution. I have a few distributions I'd like to fit but I'm having some issues getting the fit to run.

这是我的测试用例:

points = 1000
jennys_constant = 8675309
alpha, beta = 1.8, -0.5

draw = levy_stable.rvs(alpha, beta, size=points, random_state=jennys_constant)
print(levy_stable.fit(draw))

我觉得如果我从 Levy-Stable 分布中抽取,我应该能够很容易地适应该抽取.但是,我收到了很多如下警告,问题在 1000 点上花费了很长时间.

I felt that if I drew from a Levy-Stable distribution that I should be able to fit that draw fairly easily. However, I'm getting a lot of warnings like the below and the problem is taking a very long time on 1000 points.

C:\anaconda3\lib\site-packages\scipy\stats\_continuous_distns.py:3857: IntegrationWarning: The integral is probably divergent, or slowly convergent.
intg = integrate.quad(f, -xi, np.pi/2, **intg_kwargs)[0]

我是否设置错误?SciPy 文档 在这个主题上有点单薄.

Have I set up the problem incorrectly? The SciPy Docs are a bit thin on the subject.

我在拟合真实世界数据时遇到了类似的问题.

I'm having similar issues fitting my real world data.

推荐答案

看来您已正确设置问题;rv_continuous文档/code> 是 levy_stable 的超类,有其所有功能的链接(例如,fit()).我的预感是运行时非常慢是 SciPy 错误.

It looks like you have set up your problem correctly; the documentation for rv_continuous, the superclass of levy_stable, has links for all its functions (e.g., fit()). My hunch is the really slow runtime is a SciPy bug.

使用 pylevyfit_levy() 似乎有效:

Using pylevy's fit_levy() seems to work:

import scipy.stats as st, levy

points = 1000
jennys_constant = 8675309
alpha, beta = 1.8, -0.5

draw = st.levy_stable.rvs(alpha, beta, size=points, random_state=jennys_constant)
print(levy.fit_levy(draw))

结果似乎相当不错(而且fit_levy() 相当快):

The result seems reasonably good (and fit_levy() is quite fast):

(par=0, alpha=1.84, beta=-0.29, mu=0.11, sigma=1.00, 1863.61502664704)

这篇关于使用 SciPy 拟合征费稳定分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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