python scipy.stats.powerlaw负指数 [英] python scipy.stats.powerlaw negative exponent

查看:162
本文介绍了python scipy.stats.powerlaw负指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为scipy.stats.powerlaw例程提供一个负指数,例如a = -1.5,以便抽取随机样本:

I want to supply a negative exponent for the scipy.stats.powerlaw routine, e.g. a=-1.5, in order to draw random samples:

"""
powerlaw.pdf(x, a) = a * x**(a-1)
"""

from scipy.stats import powerlaw
R = powerlaw.rvs(a, size=100)

为什么需要> 0,如何提供负数a以生成随机样本,以及如何提供归一化系数/变换,即

Why is a > 0 required, how can I supply a negative a in order to generate the random samples, and how can I supply a normalization coefficient/transform, i.e.

PDF(x,C,a) = C * x**a

文档在这里

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

谢谢!

我应该补充一点,我正在尝试复制IDL的RANDOMP函数:

I should add that I'm trying to replicate IDL's RANDOMP function:

http://idlastro.gsfc.nasa.gov/ftp/pro/math/randomp.pro

推荐答案

在其域中集成的PDF必须等于1.换句话说,概率密度函数曲线下的面积必须等于1.

A PDF, integrated over its domain, must equal one. In other words, the area under a probability density function's curve must equal one.

In [36]: import scipy.integrate as integrate
In [40]: y, err = integrate.quad(lambda x: 0.5*x**(-0.5), 0, 1)

In [41]: y
Out[41]: 0.9999999999999998  # The integral is close to 1

幂律密度函数的取值范围为0< = x< =1.在这个域上,x**b的积分对于任何b> -1是有限的.当b较小时,x**bx = 0附近爆炸过快.因此,当b <= -1时,它不是有效的概率密度函数.

The powerlaw density function has a domain from 0 <= x <= 1. On this domain, the integral of x**b is finite for any b > -1. When b is smaller, x**b blows up too rapidly near x = 0. So it is not a valid probability density function when b <= -1.

In [38]: integrate.quad(lambda x: x**(-1), 0, 1)
UserWarning: The maximum number of subdivisions (50) has been achieved...
# The integral blows up

因此,对于x**(a-1)a,必须满足a-1 > -1或等效的a > 0.

Thus for x**(a-1), a must satisfy a-1 > -1 or equivalently, a > 0.

a * x**(a-1)中的第一个常数a是归一化常数,该常数使a * x**(a-1)在域[0,1]上的积分等于1.因此,您不必依赖于a.

The first constant a in a * x**(a-1) is the normalizing constant which makes the integral of a * x**(a-1) over the domain [0,1] equal to 1. So you don't get to choose this constant independent of a.

现在,如果将域更改为距0的可测量距离,那么可以,您可以为负数a定义格式为C * x**a的PDF.但是您必须声明所需的域,而且我认为scipy.stats中还没有可用的PDF.

Now if you change the domain to be a measurable distance away from 0, then yes, you could define a PDF of the form C * x**a for negative a. But you'd have to state what domain you want, and I don't think there is (yet) a PDF available in scipy.stats for this.

这篇关于python scipy.stats.powerlaw负指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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