如何找到威布尔分布的x截距

0 投票
1 回答
38 浏览
提问于 2025-04-13 01:34

我正在尝试写一段代码来绘制韦布尔概率图。我想找出一个叫做“尺度参数”的东西,这个参数是拟合的线与概率为63.2%时的交点。另外,我发现斜率非常高,这可能有点不寻常。这是数据集的问题,还是我绘制韦布尔概率分布的方法不对呢?

import numpy as np
import matplotlib.pyplot as plt

# Define the parameters
n = 8  # Sample size
i = np.arange(1, n + 1)  # Rank of observations
E = np.array([208.9, 209.0, 209.2, 209.3, 209.6, 209.8, 209.9, 210])  # Electric breakdown strength 

# Calculate the cumulative breakdown efficiency by the given formula
p = (i - 0.5) / (n + 0.25)

# variables
x_data = np.log(E)
y_data = np.log(-np.log(1 - p))

# Fit a linear regression to estimate the parameters of the Weibull distribution
slope, intercept = np.polyfit(x_data, y_data, 1)

# Calculate the shape parameter
shape = slope  

# scale parameter is the x-intercept where the fitted line intersects with p = 63.2%. How to get that?

# Generate points for the Weibull distribution
x = np.linspace(min(x_data), max(y_data), 100)
y = slope * x + intercept

# Plot the Weibull distribution
plt.plot(x_data, y_data, 'o')
plt.plot(x, y, label='Linear fit')
plt.xlabel('ln (E)')
plt.ylabel('Probability of failure :ln(-ln(1 - p))')
plt.title('Weibull Plot')
plt.legend()
plt.show()

print("Shape parameter:", slope)
# print("Scale parameter:", ?)

1 个回答

1

韦布尔分布的累积分布函数(CDF)可以用这个公式表示:F=1-exp(-(x/L)**k),其中,k代表“形状”,L代表“尺度”。

所以,如果你把左边的公式log[-log(1-F)]=k.log(x)-k.log(L)的左侧(LHS)和log(x)画在一起,你会发现斜率是k,而y轴截距是-k.log(L)。这样,你就可以通过exp(-intercept/k)来得到尺度参数L

我在下面的代码中实现了这个,并在图中用橙色的叉表示出来。

不过,韦布尔分布并不适合你当前的数据——它更适合x值在0到几倍scale之间的情况。我能理解的唯一适合韦布尔分布的方式是将其应用于E-208.8(这个偏移量是根据你的数据和需要保持为正数的要求来猜测的)。

下面是代码和输出结果:

import numpy as np
import matplotlib.pyplot as plt

# Define the parameters
E = np.array([208.9, 209.0, 209.2, 209.3, 209.6, 209.8, 209.9, 210])  # Electric breakdown strength 
E0 = 208.8               # bit of a guess!
E = E - E0
n = len( E )  # Sample size
i = np.arange(1, n + 1)  # Rank of observations

# Calculate the cumulative breakdown efficiency by the given formula
p = (i - 0.5) / (n + 0.25)

# variables
x_data = np.log(E)
y_data = np.log(-np.log(1 - p))

# Fit a linear regression to estimate the parameters of the Weibull distribution
slope, intercept = np.polyfit(x_data, y_data, 1)

# Calculate the shape parameter
shape = slope  
scale = np.exp( -intercept / shape )             # -k ln( lambda ) = intercept
print("Shape parameter:", slope)
print("Scale parameter:", scale)

# Represent the (scaled) fitted Weibull distribution
Weibull_CDF = 1.0 - np.exp( -( E / scale ) ** shape )
z = np.log( -np.log( 1.0 - Weibull_CDF ) )

# Generate points for the Weibull distribution
x = np.linspace(min(x_data), max(y_data), 100)
y = slope * x + intercept

# Plot
plt.plot(x_data, y_data, 'o')
plt.plot(x_data, z, 'x', label="Weibull" )
plt.plot(x, y, label='Linear fit')
plt.xlabel('ln (E-E0)')
plt.ylabel('Probability of failure :ln(-ln(1 - p))')
plt.title('Weibull Plot')
plt.legend()
plt.show()

enter image description here

数值:

Shape parameter: 1.3061117692466773
Scale parameter: 0.8009805959686129

撰写回答