scipy.stats.weibull_min.fit 如何产生它的初始猜测?
How does scipy.stats.weibull_min.fit produce its initial guess?
我正在查看 scipy.stats.weibull_min.fit. This can be found at https://github.com/scipy/scipy/blob/v1.3.0/scipy/stats/_distn_infrastructure.py#L2157 的源代码。这个函数returns三个拟合参数。例如:
import numpy
numpy.random.seed(4)
from scipy.stats import weibull_min
samples = weibull_min.rvs(0.4, loc=0, scale=1.5, size = 10)
weibull_min.fit(samples)
(0.44243114317044474, 0.01717442938653987, 10.61124981692991)
它似乎通过调用 scipy.optimize.fmin 来找到最大似然,如下所示:
vals = optimizer(func, x0, args=(ravel(data),), disp=0)
But this requires an initial guess x0. What is this set to? This seems
to be the relevant line in the source code but it doesn't help me
answer the question.
In short, what is the full equivalent line of code using scipy.optimize.fmin that corresponds to weibull_min.fit(samples)?
似乎 fit
调用了 _fitstart(data)
, and the result of that is saved in args
which is then passed to _reduce_func
(总是在 args
列表末尾有 +- 2 个参数)。
在 _fitstart
_fit_loc_scale_support(data,...)
is called, which again calls fit_loc_scale(data,...)
中,魔法似乎发生了:基本上计算了平均值和标准偏差,它们在 "postprocessed" _fit_loc_scale_support
中。然后 1
是所有其他参数的前缀(在本例中为一个)。所以这两个参数基本上用作分布的位置和缩放参数的初始猜测,加上第一个 "shape parameter".
的 1
我正在查看 scipy.stats.weibull_min.fit. This can be found at https://github.com/scipy/scipy/blob/v1.3.0/scipy/stats/_distn_infrastructure.py#L2157 的源代码。这个函数returns三个拟合参数。例如:
import numpy
numpy.random.seed(4)
from scipy.stats import weibull_min
samples = weibull_min.rvs(0.4, loc=0, scale=1.5, size = 10)
weibull_min.fit(samples)
(0.44243114317044474, 0.01717442938653987, 10.61124981692991)
它似乎通过调用 scipy.optimize.fmin 来找到最大似然,如下所示:
vals = optimizer(func, x0, args=(ravel(data),), disp=0)
But this requires an initial guess x0. What is this set to? This seems to be the relevant line in the source code but it doesn't help me answer the question.
In short, what is the full equivalent line of code using scipy.optimize.fmin that corresponds to weibull_min.fit(samples)?
似乎 fit
调用了 _fitstart(data)
, and the result of that is saved in args
which is then passed to _reduce_func
(总是在 args
列表末尾有 +- 2 个参数)。
在 _fitstart
_fit_loc_scale_support(data,...)
is called, which again calls fit_loc_scale(data,...)
中,魔法似乎发生了:基本上计算了平均值和标准偏差,它们在 "postprocessed" _fit_loc_scale_support
中。然后 1
是所有其他参数的前缀(在本例中为一个)。所以这两个参数基本上用作分布的位置和缩放参数的初始猜测,加上第一个 "shape parameter".
1