不同的威布尔值 pdf
Different values weibull pdf
我想知道为什么带有预建函数 dweibull.pdf 的 weibull pdf 的值或多或少是它们应该的一半
我做了一个测试。对于同一个 x,我为 A=10 和 K=2 创建了两次 weibull pdf,一次是自己编写 formula,另一次是使用 dweibull.
的预建函数
import numpy as np
from scipy.stats import exponweib,dweibull
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
K=2.0
A=10.0
x=np.arange(0.,20.,1)
#own function
def weib(data,a,k):
return (k / a) * (data / a)**(k - 1) * np.exp(-(data / a)**k)
pdf1=weib(x,A,K)
print sum(pdf1)
#prebuilt function
dist=dweibull(K,1,A)
pdf2=dist.pdf(x)
print sum(pdf2)
f=plt.figure()
suba=f.add_subplot(121)
suba.plot(x,pdf1)
suba.set_title('pdf dweibull')
subb=f.add_subplot(122)
subb.plot(x,pdf2)
subb.set_title('pdf own function')
f.show()
似乎 dweibull 的 pdf 值是一半,但这是错误的,因为总和应该是 1,而不是 dweibull 的 0.5 左右。通过自己编写公式,总和约为 1[
scipy.stats.dweibull
implements the double Weibull distribution. Its support is the real line. Your function weib
corresponds to the PDF of scipy's weibull_min
分布.
将函数 weib
与 weibull_min.pdf
进行比较:
In [128]: from scipy.stats import weibull_min
In [129]: x = np.arange(0, 20, 1.0)
In [130]: K = 2.0
In [131]: A = 10.0
您的实施:
In [132]: weib(x, A, K)
Out[132]:
array([ 0. , 0.019801 , 0.03843158, 0.05483587, 0.0681715 ,
0.07788008, 0.08372116, 0.0857677 , 0.08436679, 0.08007445,
0.07357589, 0.0656034 , 0.05686266, 0.04797508, 0.03944036,
0.03161977, 0.02473752, 0.01889591, 0.014099 , 0.0102797 ])
scipy.stats.weibull_min.pdf
:
In [133]: weibull_min.pdf(x, K, scale=A)
Out[133]:
array([ 0. , 0.019801 , 0.03843158, 0.05483587, 0.0681715 ,
0.07788008, 0.08372116, 0.0857677 , 0.08436679, 0.08007445,
0.07357589, 0.0656034 , 0.05686266, 0.04797508, 0.03944036,
0.03161977, 0.02473752, 0.01889591, 0.014099 , 0.0102797 ])
顺便说一句,你的这行代码有一个错误:
dist=dweibull(K,1,A)
参数的顺序是 shape, location, scale
,因此您将位置参数设置为 1。这就是为什么第二个绘图中的值移动了一个。那一行应该是
dist = dweibull(K, 0, A)
我想知道为什么带有预建函数 dweibull.pdf 的 weibull pdf 的值或多或少是它们应该的一半
我做了一个测试。对于同一个 x,我为 A=10 和 K=2 创建了两次 weibull pdf,一次是自己编写 formula,另一次是使用 dweibull.
的预建函数import numpy as np
from scipy.stats import exponweib,dweibull
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
K=2.0
A=10.0
x=np.arange(0.,20.,1)
#own function
def weib(data,a,k):
return (k / a) * (data / a)**(k - 1) * np.exp(-(data / a)**k)
pdf1=weib(x,A,K)
print sum(pdf1)
#prebuilt function
dist=dweibull(K,1,A)
pdf2=dist.pdf(x)
print sum(pdf2)
f=plt.figure()
suba=f.add_subplot(121)
suba.plot(x,pdf1)
suba.set_title('pdf dweibull')
subb=f.add_subplot(122)
subb.plot(x,pdf2)
subb.set_title('pdf own function')
f.show()
似乎 dweibull 的 pdf 值是一半,但这是错误的,因为总和应该是 1,而不是 dweibull 的 0.5 左右。通过自己编写公式,总和约为 1[
scipy.stats.dweibull
implements the double Weibull distribution. Its support is the real line. Your function weib
corresponds to the PDF of scipy's weibull_min
分布.
将函数 weib
与 weibull_min.pdf
进行比较:
In [128]: from scipy.stats import weibull_min
In [129]: x = np.arange(0, 20, 1.0)
In [130]: K = 2.0
In [131]: A = 10.0
您的实施:
In [132]: weib(x, A, K)
Out[132]:
array([ 0. , 0.019801 , 0.03843158, 0.05483587, 0.0681715 ,
0.07788008, 0.08372116, 0.0857677 , 0.08436679, 0.08007445,
0.07357589, 0.0656034 , 0.05686266, 0.04797508, 0.03944036,
0.03161977, 0.02473752, 0.01889591, 0.014099 , 0.0102797 ])
scipy.stats.weibull_min.pdf
:
In [133]: weibull_min.pdf(x, K, scale=A)
Out[133]:
array([ 0. , 0.019801 , 0.03843158, 0.05483587, 0.0681715 ,
0.07788008, 0.08372116, 0.0857677 , 0.08436679, 0.08007445,
0.07357589, 0.0656034 , 0.05686266, 0.04797508, 0.03944036,
0.03161977, 0.02473752, 0.01889591, 0.014099 , 0.0102797 ])
顺便说一句,你的这行代码有一个错误:
dist=dweibull(K,1,A)
参数的顺序是 shape, location, scale
,因此您将位置参数设置为 1。这就是为什么第二个绘图中的值移动了一个。那一行应该是
dist = dweibull(K, 0, A)