python scipy genextreme fit从MATLAB gev fit函数返回相同数据的不同参数

yqkkidmi  于 2023-08-02  发布在  Python
关注(0)|答案(1)|浏览(133)

我试图将一些代码从MATLAB移植到PYTHON,我意识到MATLAB中的gevfit函数似乎与scipy genextreme的行为不同,所以我实现了这个最小的例子:
MATLAB

% Create the MATLAB array
x = [0.5700, 0.8621, 0.9124, 0.6730, 0.5524, 0.7608, 0.2150, 0.5787, ...
           0.7210, 0.7826, 0.8181, 0.5449, 0.7501, 1.1301, 0.7784, 0.5378, ...
           0.9550, 0.9623, 0.6865, 0.6863, 0.6153, 0.4372, 0.5485, 0.6318, ...
           0.5501, 0.8333, 0.8044, 0.9111, 0.8560, 0.6178, 1.0688, 0.7535, ...
           0.7554, 0.7123, 0.7589, 0.8415, 0.7586, 0.3865, 0.3087, 0.7067];

disp(numbers);

parmHat = gevfit(x);

disp('Estimated parameters (A, B):');
disp(parmHat);

字符串
估计参数(A,B):-0.3351 0.1962 0.6466
Python

import numpy as np
import scipy.stats as stats

x = np.array([0.5700, 0.8621, 0.9124, 0.6730, 0.5524, 0.7608, 0.2150, 0.5787,
                    0.7210, 0.7826, 0.8181, 0.5449, 0.7501, 1.1301, 0.7784, 0.5378,
                    0.9550, 0.9623, 0.6865, 0.6863, 0.6153, 0.4372, 0.5485, 0.6318,
                    0.5501, 0.8333, 0.8044, 0.9111, 0.8560, 0.6178, 1.0688, 0.7535,
                    0.7554, 0.7123, 0.7589, 0.8415, 0.7586, 0.3865, 0.3087, 0.7067])

# Fit the GEV distribution to the data
parameters3 = stats.genextreme.fit(x)

print("Estimated GEV parameters:", parameters3)


估计GEV参数:(1.0872284332032054,0.534605335200113,0.6474387313912493)
我希望参数相同,但结果完全不同。有什么帮助吗?

wwtsj6pe

wwtsj6pe1#

方法genextreme.fit无法计算正确的结果。您可以通过为数值求解器提供比genextreme.fit使用的默认值更好的初始值来帮助它生成正确的值。通过提供形状、位置和比例参数的值来设置初始值:

In [29]: from scipy.stats import genextreme

In [30]: x = np.array([0.5700, 0.8621, 0.9124, 0.6730, 0.5524, 0.7608, 0.2150, 0.5787,
    ...:                     0.7210, 0.7826, 0.8181, 0.5449, 0.7501, 1.1301, 0.7784, 0.5378,
    ...:                     0.9550, 0.9623, 0.6865, 0.6863, 0.6153, 0.4372, 0.5485, 0.6318,
    ...:                     0.5501, 0.8333, 0.8044, 0.9111, 0.8560, 0.6178, 1.0688, 0.7535,
    ...:                     0.7554, 0.7123, 0.7589, 0.8415, 0.7586, 0.3865, 0.3087, 0.7067])
    ...: 

In [31]: genextreme.fit(x, 0.34, loc=0.65, scale=0.20)  # Include initial guess of the parameters
Out[31]: (0.33513328610099824, 0.6466250071208526, 0.19615018966970216)

字符串
请注意,SciPy的genextreme使用的参数c是Matlab中参数k的负数。还要注意,SciPy中参数的顺序是 clocationscale,而在Matlab中是 kscalelocation

相关问题