我试图将一些代码从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)
我希望参数相同,但结果完全不同。有什么帮助吗?
1条答案
按热度按时间wwtsj6pe1#
方法
genextreme.fit
无法计算正确的结果。您可以通过为数值求解器提供比genextreme.fit
使用的默认值更好的初始值来帮助它生成正确的值。通过提供形状、位置和比例参数的值来设置初始值:字符串
请注意,SciPy的
genextreme
使用的参数c
是Matlab中参数k
的负数。还要注意,SciPy中参数的顺序是 c,location,scale,而在Matlab中是 k,scale,location。