【问题标题】:Curve_fit fails on Exponentiated Weibull distributionCurve_fit 在指数 Weibull 分布上失败
【发布时间】:2019-02-28 16:49:48
【问题描述】:

我正在尝试使用

scipy.optimize.curve_fit(func,xdata,ydata)

确定指数weibull分布的参数:

#define exponentiated weibull distribution
def expweib(x,k,lamda,alpha):
      return alpha*(k/lamda)*((x/lamda)**(k-1))*((1-np.exp(-(x/lamda)*k))**(alpha-1))*np.exp(-(x/lamda)*k)


 #First generate random sample of exponentiated weibull distribution using stats.exponweib.rvs
data = stats.exponweib.rvs(a = 1, c = 82.243021128368554, loc = 0,scale = 989.7422, size = 1000 )


#Then use the sample data to draw a histogram
entries_Test, bin_edges_Test, patches_Test = plt.hist(data, bins=50, range=[909.5,1010.5], normed=True)

#calculate bin middles of the histogram
bin_middles_Test = 0.5*(bin_edges_Test[1:] + bin_edges_Test[:-1])

#use bin_middles_Test as xdata, bin_edges_Test as ydata, previously defined expweib as func, call curve_fit method:
params, pcov = curve_fit(weib,bin_middles_Test, entries_Test )

然后出现错误:

OptimizeWarning: Covariance of the parameters could not be estimatedcategory=OptimizeWarning)

我无法确定哪个步骤有问题,有人可以帮忙吗?

谢谢

【问题讨论】:

  • 我猜curve_fit(weib实际上应该是curve_fit(expweib?!
  • 您可以使用exponweib.fit 方法将分布拟合到样本,而不是拟合直方图。该方法使用最大似然拟合分布。

标签: python scipy curve-fitting weibull


【解决方案1】:

在此处阅读 curve_fit 方法的文档,https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html,对于 method 参数,他们提到了 the default 'lm' method won't work if the number of observations is less than the number of variables, in which case you should use either of *'trf'* or *'dogbox'* method

此外,在“返回值”部分阅读有关 'pcov' 的内容时,他们提到如果 the Jacobian matrix at the solution does not have a full rank,条目将是 inf

我用 trfdogbox 尝试了你的代码,得到的 pconv 数组全是零

【讨论】:

    猜你喜欢
    • 2012-11-02
    • 1970-01-01
    • 2020-11-27
    • 2012-08-02
    • 2017-12-25
    • 2013-12-20
    • 2019-10-08
    • 2012-06-30
    • 2016-02-25
    相关资源
    最近更新 更多