From e875695e9bb4c162b33636a8a6d3f68fff90d182 Mon Sep 17 00:00:00 2001 From: Le Roux Erwan <erwan.le-roux@irstea.fr> Date: Wed, 16 Oct 2019 15:52:57 +0200 Subject: [PATCH] [EXTREME ESTIMATOR] refactor margin_fits folder. extreme estimator folder. and extreme_models folder --- .../meteo_france_data/plot}/__init__.py | 0 .../plot/create_shifted_cmap.py | 6 +- .../meteo_france_data}/plot/mask_poly.py | 0 .../plot/shifted_color_map.py | 0 .../scm_models_data/abstract_study.py | 5 +- .../altitude_hypercube_visualizer.py | 1 - .../study_visualization/study_visualizer.py | 22 ++--- .../stations_data/comparison_analysis.py | 6 +- .../stations_data/main_spatial_comparison.py | 2 +- .../regression_margin/regression_margin.py | 12 +-- .../max_stable_process_plot.py | 6 +- .../spatial_robustness/alps_msp_robustness.py | 2 +- .../unidimensional_robustness.py | 2 +- experiment/robustness_plot/single_plot.py | 2 +- experiment/simulation/abstract_simulation.py | 10 +- .../simulation/lin_space2_simulation.py | 10 +- experiment/simulation/lin_space_simulation.py | 6 +- .../trend_analysis/non_stationary_trends.py | 14 +-- ...bstract_comparison_non_stationary_model.py | 2 +- .../abstract_gev_trend_test.py | 10 +- .../gev_trend_test_one_parameter.py | 4 +- .../gev_trend_test_two_parameters.py | 4 +- .../trend_analysis/univariate_test/utils.py | 2 +- .../margin_fits/extreme_params.py | 21 ----- extreme_estimator/margin_fits/gev/fevd.py | 23 ----- .../margin_fits/gev/gevmle_fit.py | 19 ---- .../margin_fits/gev/ismev_gev_fit.py | 25 ----- .../margin_fits/gpd/gpdmle_fit.py | 15 --- .../margin_fits/margin_fits_utils.py | 51 ---------- .../estimator => extreme_fit}/__init__.py | 0 .../distribution}/__init__.py | 0 .../distribution}/abstract_params.py | 16 +++- .../distribution/gev}/__init__.py | 0 .../distribution}/gev/fevd_fixed.R | 13 ++- .../distribution}/gev/gev_fit.py | 3 +- .../distribution}/gev/gev_params.py | 10 +- .../distribution}/gev/gevmle_fit.R | 0 extreme_fit/distribution/gev/gevmle_fit.py | 29 ++++++ extreme_fit/distribution/gev/ismev_gev_fit.py | 49 ++++++++++ .../distribution}/gev/main_fevd_fixed.R | 21 ++--- .../distribution}/gev/wrapper_ismev_gev_fit.R | 0 .../distribution/gpd}/__init__.py | 0 .../distribution}/gpd/gpd_params.py | 10 +- extreme_fit/distribution/gpd/gpdmle_fit.py | 26 ++++++ .../estimator}/__init__.py | 0 .../estimator/abstract_estimator.py | 4 +- .../estimator/full_estimator}/__init__.py | 0 .../full_estimator/abstract_full_estimator.py | 16 ++-- .../full_estimator_for_simulation.py | 6 +- .../estimator/margin_estimator}/__init__.py | 0 .../abstract_margin_estimator.py | 10 +- .../margin_estimator_for_simulation.py | 4 +- .../max_stable_estimator}/__init__.py | 0 .../abstract_max_stable_estimator.py | 4 +- .../estimator/utils.py | 6 +- .../model}/__init__.py | 0 .../model}/abstract_model.py | 0 .../model/margin_model}/__init__.py | 0 .../margin_model/abstract_margin_model.py | 10 +- .../model}/margin_model/fitspatgev.R | 0 .../linear_margin_model}/__init__.py | 0 .../abstract_temporal_linear_margin_model.py | 12 +-- .../linear_margin_model.py | 8 +- .../temporal_linear_margin_models.py | 6 +- .../margin_model/margin_function}/__init__.py | 0 .../abstract_margin_function.py | 6 +- .../combined_margin_function.py | 4 +- .../independent_margin_function.py | 6 +- .../margin_function/linear_margin_function.py | 20 ++-- .../parametric_margin_function.py | 8 +- .../margin_function/spline_margin_function.py | 8 +- .../margin_model/margin_function/utils.py | 4 +- .../margin_model/param_function}/__init__.py | 0 .../param_function/abstract_coef.py | 0 .../param_function/linear_coef.py | 2 +- .../param_function/param_function.py | 4 +- .../param_function/spline_coef.py | 2 +- .../margin_model/parametric_margin_model.py | 8 +- .../margin_model/spline_margin_model.py | 10 +- .../model/max_stable_model}/__init__.py | 0 .../abstract_max_stable_model.py | 6 +- .../model}/max_stable_model/max_stable_fit.R | 0 .../max_stable_model/max_stable_models.py | 2 +- .../max_stable_model/max_stable_with_spline.R | 0 .../model}/max_stable_model/test.R | 0 .../model/result_from_model_fit}/__init__.py | 0 .../abstract_result_from_model_fit.py | 0 .../result_from_extremes.py | 2 +- .../result_from_ismev.py | 8 +- .../result_from_spatial_extreme.py | 4 +- .../model}/result_from_model_fit/utils.py | 0 .../model}/utils.py | 2 +- .../dataset/simulation_dataset.py | 4 +- .../annual_maxima_observations.py | 4 +- test/test_experiment/test_hypercube.py | 2 +- .../test_estimator/test_margin_estimators.py | 2 +- .../test_max_stable_estimators.py | 2 +- .../test_margin_function.py | 6 +- .../test_extreme_models/test_margin_model.py | 6 +- .../test_margin_temporal.py | 6 +- .../test_margin_temporal_transformed.py | 6 +- .../test_max_stable_temporal.py | 6 +- .../test_safe_run_r_estimator.py | 2 +- .../test_gev/test_gev_params.py | 2 +- .../test_gev/test_gev_temporal.py | 6 +- .../test_gev/test_gev_temporal_bayesian.py | 92 +++++++++++++++++++ .../test_gev/test_gevmle_fit.py | 8 +- .../test_coordinates.py | 2 +- .../test_dataset.py | 4 +- .../test_slicer.py | 4 +- .../test_fitmaxstab_with_margin.py | 10 +- .../test_fitmaxstab_without_margin.py | 8 +- .../test_rmaxstab_with_margin.py | 6 +- .../test_rmaxstab_without_margin.py | 6 +- test/test_unitary/test_unitary_abstract.py | 2 +- test/test_utils.py | 12 +-- thesis_report/gev_plot.py | 2 +- thesis_report/simulation_for_quantile_gap.py | 2 +- thesis_report/slides.py | 2 +- 119 files changed, 459 insertions(+), 406 deletions(-) rename {extreme_estimator => experiment/meteo_france_data/plot}/__init__.py (100%) rename {extreme_estimator/margin_fits => experiment/meteo_france_data}/plot/create_shifted_cmap.py (92%) rename {extreme_estimator/margin_fits => experiment/meteo_france_data}/plot/mask_poly.py (100%) rename {extreme_estimator/margin_fits => experiment/meteo_france_data}/plot/shifted_color_map.py (100%) delete mode 100644 extreme_estimator/margin_fits/extreme_params.py delete mode 100644 extreme_estimator/margin_fits/gev/fevd.py delete mode 100644 extreme_estimator/margin_fits/gev/gevmle_fit.py delete mode 100644 extreme_estimator/margin_fits/gev/ismev_gev_fit.py delete mode 100644 extreme_estimator/margin_fits/gpd/gpdmle_fit.py delete mode 100644 extreme_estimator/margin_fits/margin_fits_utils.py rename {extreme_estimator/estimator => extreme_fit}/__init__.py (100%) rename {extreme_estimator/estimator/full_estimator => extreme_fit/distribution}/__init__.py (100%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/abstract_params.py (72%) rename {extreme_estimator/estimator/margin_estimator => extreme_fit/distribution/gev}/__init__.py (100%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/fevd_fixed.R (99%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/gev_fit.py (57%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/gev_params.py (92%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/gevmle_fit.R (100%) create mode 100644 extreme_fit/distribution/gev/gevmle_fit.py create mode 100644 extreme_fit/distribution/gev/ismev_gev_fit.py rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/main_fevd_fixed.R (76%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gev/wrapper_ismev_gev_fit.R (100%) rename {extreme_estimator/estimator/max_stable_estimator => extreme_fit/distribution/gpd}/__init__.py (100%) rename {extreme_estimator/margin_fits => extreme_fit/distribution}/gpd/gpd_params.py (67%) create mode 100644 extreme_fit/distribution/gpd/gpdmle_fit.py rename {extreme_estimator/extreme_models => extreme_fit/estimator}/__init__.py (100%) rename {extreme_estimator => extreme_fit}/estimator/abstract_estimator.py (83%) rename {extreme_estimator/extreme_models/margin_model => extreme_fit/estimator/full_estimator}/__init__.py (100%) rename {extreme_estimator => extreme_fit}/estimator/full_estimator/abstract_full_estimator.py (83%) rename {extreme_estimator => extreme_fit}/estimator/full_estimator/full_estimator_for_simulation.py (76%) rename {extreme_estimator/extreme_models/margin_model/linear_margin_model => extreme_fit/estimator/margin_estimator}/__init__.py (100%) rename {extreme_estimator => extreme_fit}/estimator/margin_estimator/abstract_margin_estimator.py (76%) rename {extreme_estimator => extreme_fit}/estimator/margin_estimator/margin_estimator_for_simulation.py (73%) rename {extreme_estimator/extreme_models/margin_model/margin_function => extreme_fit/estimator/max_stable_estimator}/__init__.py (100%) rename {extreme_estimator => extreme_fit}/estimator/max_stable_estimator/abstract_max_stable_estimator.py (83%) rename {extreme_estimator => extreme_fit}/estimator/utils.py (64%) rename {extreme_estimator/extreme_models/margin_model/param_function => extreme_fit/model}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/abstract_model.py (100%) rename {extreme_estimator/extreme_models/max_stable_model => extreme_fit/model/margin_model}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/abstract_margin_model.py (90%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/fitspatgev.R (100%) rename {extreme_estimator/extreme_models/result_from_model_fit => extreme_fit/model/margin_model/linear_margin_model}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py (83%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/linear_margin_model/linear_margin_model.py (94%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/linear_margin_model/temporal_linear_margin_models.py (87%) rename {extreme_estimator/margin_fits => extreme_fit/model/margin_model/margin_function}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/abstract_margin_function.py (97%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/combined_margin_function.py (89%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/independent_margin_function.py (85%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/linear_margin_function.py (81%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/parametric_margin_function.py (92%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/spline_margin_function.py (84%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/margin_function/utils.py (86%) rename {extreme_estimator/margin_fits/gev => extreme_fit/model/margin_model/param_function}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/param_function/abstract_coef.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/param_function/linear_coef.py (97%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/param_function/param_function.py (93%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/param_function/spline_coef.py (91%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/parametric_margin_model.py (80%) rename {extreme_estimator/extreme_models => extreme_fit/model}/margin_model/spline_margin_model.py (88%) rename {extreme_estimator/margin_fits/gpd => extreme_fit/model/max_stable_model}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/max_stable_model/abstract_max_stable_model.py (94%) rename {extreme_estimator/extreme_models => extreme_fit/model}/max_stable_model/max_stable_fit.R (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/max_stable_model/max_stable_models.py (95%) rename {extreme_estimator/extreme_models => extreme_fit/model}/max_stable_model/max_stable_with_spline.R (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/max_stable_model/test.R (100%) rename {extreme_estimator/margin_fits/plot => extreme_fit/model/result_from_model_fit}/__init__.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/result_from_model_fit/abstract_result_from_model_fit.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/result_from_model_fit/result_from_extremes.py (94%) rename {extreme_estimator/extreme_models => extreme_fit/model}/result_from_model_fit/result_from_ismev.py (82%) rename {extreme_estimator/extreme_models => extreme_fit/model}/result_from_model_fit/result_from_spatial_extreme.py (85%) rename {extreme_estimator/extreme_models => extreme_fit/model}/result_from_model_fit/utils.py (100%) rename {extreme_estimator/extreme_models => extreme_fit/model}/utils.py (97%) create mode 100644 test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal_bayesian.py diff --git a/extreme_estimator/__init__.py b/experiment/meteo_france_data/plot/__init__.py similarity index 100% rename from extreme_estimator/__init__.py rename to experiment/meteo_france_data/plot/__init__.py diff --git a/extreme_estimator/margin_fits/plot/create_shifted_cmap.py b/experiment/meteo_france_data/plot/create_shifted_cmap.py similarity index 92% rename from extreme_estimator/margin_fits/plot/create_shifted_cmap.py rename to experiment/meteo_france_data/plot/create_shifted_cmap.py index 6936b3fc..8edc0375 100644 --- a/extreme_estimator/margin_fits/plot/create_shifted_cmap.py +++ b/experiment/meteo_france_data/plot/create_shifted_cmap.py @@ -5,8 +5,8 @@ import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.axes_grid1 import make_axes_locatable -from extreme_estimator.margin_fits.extreme_params import ExtremeParams -from extreme_estimator.margin_fits.plot.shifted_color_map import shiftedColorMap +from experiment.meteo_france_data.plot.shifted_color_map import shiftedColorMap +from extreme_fit.distribution.abstract_params import AbstractParams def get_shifted_map(vmin, vmax): @@ -56,7 +56,7 @@ def imshow_shifted(ax, gev_param_name, values, visualization_extend, mask_2D=Non norm = get_norm(vmin, vmax) create_colorbase_axis(ax, gev_param_name, shifted_cmap, norm) shifted_cmap.set_bad(color='white') - if gev_param_name != ExtremeParams.SHAPE: + if gev_param_name != AbstractParams.SHAPE: epsilon = 1e-2 * (np.max(values) - np.min(values)) value = np.min(values) # The right blue corner will be blue (but most of the time, another display will be on top) diff --git a/extreme_estimator/margin_fits/plot/mask_poly.py b/experiment/meteo_france_data/plot/mask_poly.py similarity index 100% rename from extreme_estimator/margin_fits/plot/mask_poly.py rename to experiment/meteo_france_data/plot/mask_poly.py diff --git a/extreme_estimator/margin_fits/plot/shifted_color_map.py b/experiment/meteo_france_data/plot/shifted_color_map.py similarity index 100% rename from extreme_estimator/margin_fits/plot/shifted_color_map.py rename to experiment/meteo_france_data/plot/shifted_color_map.py diff --git a/experiment/meteo_france_data/scm_models_data/abstract_study.py b/experiment/meteo_france_data/scm_models_data/abstract_study.py index 248de3d6..a10ac33e 100644 --- a/experiment/meteo_france_data/scm_models_data/abstract_study.py +++ b/experiment/meteo_france_data/scm_models_data/abstract_study.py @@ -14,7 +14,6 @@ import numpy as np import pandas as pd from PIL import Image from PIL import ImageDraw -from matplotlib import cm from matplotlib.colors import Normalize from netCDF4 import Dataset @@ -23,9 +22,9 @@ from experiment.meteo_france_data.scm_models_data.scm_constants import ALTITUDES LATITUDES, ORIENTATIONS, SLOPES, ORDERED_ALLSLOPES_ALTITUDES, ORDERED_ALLSLOPES_ORIENTATIONS, \ ORDERED_ALLSLOPES_SLOPES, ORDERED_ALLSLOPES_MASSIFNUM from experiment.meteo_france_data.scm_models_data.visualization.utils import get_km_formatter -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.margin_fits.plot.create_shifted_cmap import create_colorbase_axis, \ +from experiment.meteo_france_data.plot.create_shifted_cmap import create_colorbase_axis, \ get_shifted_map, get_colors from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatial_coordinates.abstract_spatial_coordinates import \ diff --git a/experiment/meteo_france_data/scm_models_data/visualization/hypercube_visualization/altitude_hypercube_visualizer.py b/experiment/meteo_france_data/scm_models_data/visualization/hypercube_visualization/altitude_hypercube_visualizer.py index fc92b91c..dc3fd797 100644 --- a/experiment/meteo_france_data/scm_models_data/visualization/hypercube_visualization/altitude_hypercube_visualizer.py +++ b/experiment/meteo_france_data/scm_models_data/visualization/hypercube_visualization/altitude_hypercube_visualizer.py @@ -12,7 +12,6 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat StudyVisualizer from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest -from extreme_estimator.margin_fits.gev.gev_params import GevParams from utils import get_display_name_from_object_type ALTITUDES_XLABEL = 'altitudes' diff --git a/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/study_visualizer.py b/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/study_visualizer.py index 80016f96..7263aa3d 100644 --- a/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/study_visualizer.py +++ b/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/study_visualizer.py @@ -19,20 +19,20 @@ from experiment.trend_analysis.non_stationary_trends import \ from experiment.meteo_france_data.scm_models_data.visualization.utils import create_adjusted_axes from experiment.trend_analysis.univariate_test.utils import compute_gev_change_point_test_results from experiment.utils import average_smoothing_with_sliding_window -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.distribution.abstract_params import AbstractParams +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ LinearStationaryMarginModel -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.param_function import AbstractParamFunction -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import CovarianceFunction -from extreme_estimator.margin_fits.abstract_params import AbstractParams -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.gev.ismev_gev_fit import IsmevGevFit -from extreme_estimator.margin_fits.gpd.gpd_params import GpdParams -from extreme_estimator.margin_fits.gpd.gpdmle_fit import GpdMleFit +from extreme_fit.model.margin_model.param_function.param_function import AbstractParamFunction +from extreme_fit.model.max_stable_model.abstract_max_stable_model import CovarianceFunction +from extreme_fit.distribution.gev.gev_params import GevParams +from extreme_fit.distribution.gev.ismev_gev_fit import IsmevGevFit +from extreme_fit.distribution.gpd.gpd_params import GpdParams +from extreme_fit.distribution.gpd.gpdmle_fit import GpdMleFit from spatio_temporal_dataset.coordinates.spatial_coordinates.abstract_spatial_coordinates import \ AbstractSpatialCoordinates from spatio_temporal_dataset.coordinates.spatio_temporal_coordinates.abstract_spatio_temporal_coordinates import \ diff --git a/experiment/meteo_france_data/stations_data/comparison_analysis.py b/experiment/meteo_france_data/stations_data/comparison_analysis.py index 78bdff75..c85b1cdc 100644 --- a/experiment/meteo_france_data/stations_data/comparison_analysis.py +++ b/experiment/meteo_france_data/stations_data/comparison_analysis.py @@ -7,10 +7,10 @@ from cached_property import cached_property from experiment.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \ ALL_ALTITUDES -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import CovarianceFunction -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import ExtremalT, BrownResnick +from extreme_fit.model.max_stable_model.abstract_max_stable_model import CovarianceFunction +from extreme_fit.model.max_stable_model.max_stable_models import ExtremalT, BrownResnick from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatial_coordinates.abstract_spatial_coordinates import \ AbstractSpatialCoordinates diff --git a/experiment/meteo_france_data/stations_data/main_spatial_comparison.py b/experiment/meteo_france_data/stations_data/main_spatial_comparison.py index 36f6dc46..80374664 100644 --- a/experiment/meteo_france_data/stations_data/main_spatial_comparison.py +++ b/experiment/meteo_france_data/stations_data/main_spatial_comparison.py @@ -1,5 +1,5 @@ from experiment.meteo_france_data.stations_data.comparison_analysis import ComparisonAnalysis -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \ BetweenZeroAndOneNormalization from utils import get_display_name_from_object_type diff --git a/experiment/regression_margin/regression_margin.py b/experiment/regression_margin/regression_margin.py index b16bd28a..6d4d1813 100644 --- a/experiment/regression_margin/regression_margin.py +++ b/experiment/regression_margin/regression_margin.py @@ -1,11 +1,11 @@ import numpy as np -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import FullEstimatorInASingleStepWithSmoothMargin +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ ConstantMarginModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.max_stable_model.max_stable_models import Smith +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_1D import LinSpaceSpatialCoordinates import matplotlib.pyplot as plt @@ -44,7 +44,7 @@ for i in range(nb_estimator): max_stable_model=max_stable_model) if show and i == 0: - # Plot a realization from the maxima margin_fits (i.e the maxima obtained just by simulating the marginal law) + # Plot a realization from the maxima distribution (i.e the maxima obtained just by simulating the marginal law) for maxima in np.transpose(dataset.maxima_frech()): plt.plot(coordinates.coordinates_values(), maxima, 'o') plt.show() diff --git a/experiment/robustness_plot/estimation_robustness/max_stable_process_plot.py b/experiment/robustness_plot/estimation_robustness/max_stable_process_plot.py index 3be6ef87..33b9e34c 100644 --- a/experiment/robustness_plot/estimation_robustness/max_stable_process_plot.py +++ b/experiment/robustness_plot/estimation_robustness/max_stable_process_plot.py @@ -1,6 +1,6 @@ -from extreme_estimator.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith +from extreme_fit.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel +from extreme_fit.model.max_stable_model.max_stable_models import Smith from experiment.robustness_plot.display_item import DisplayItem from experiment.robustness_plot.multiple_plot import MultiplePlot from experiment.robustness_plot.single_plot import SinglePlot diff --git a/experiment/robustness_plot/estimation_robustness/spatial_robustness/alps_msp_robustness.py b/experiment/robustness_plot/estimation_robustness/spatial_robustness/alps_msp_robustness.py index e8a7e84b..26b98dc4 100644 --- a/experiment/robustness_plot/estimation_robustness/spatial_robustness/alps_msp_robustness.py +++ b/experiment/robustness_plot/estimation_robustness/spatial_robustness/alps_msp_robustness.py @@ -1,4 +1,4 @@ -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith, BrownResnick +from extreme_fit.model.max_stable_model.max_stable_models import Smith, BrownResnick from experiment.robustness_plot.estimation_robustness.max_stable_process_plot import MultipleMaxStableProcessPlot, MaxStableProcessPlot from experiment.robustness_plot.single_plot import SinglePlot from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_2D_coordinates import \ diff --git a/experiment/robustness_plot/estimation_robustness/unidimensional_robustness/unidimensional_robustness.py b/experiment/robustness_plot/estimation_robustness/unidimensional_robustness/unidimensional_robustness.py index ad55216a..e2d77b0f 100644 --- a/experiment/robustness_plot/estimation_robustness/unidimensional_robustness/unidimensional_robustness.py +++ b/experiment/robustness_plot/estimation_robustness/unidimensional_robustness/unidimensional_robustness.py @@ -1,4 +1,4 @@ -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith, BrownResnick +from extreme_fit.model.max_stable_model.max_stable_models import Smith, BrownResnick from experiment.robustness_plot.estimation_robustness.max_stable_process_plot import MultipleMaxStableProcessPlot, MaxStableProcessPlot from experiment.robustness_plot.single_plot import SinglePlot from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_2D_coordinates import \ diff --git a/experiment/robustness_plot/single_plot.py b/experiment/robustness_plot/single_plot.py index 9dee3b78..70f68923 100644 --- a/experiment/robustness_plot/single_plot.py +++ b/experiment/robustness_plot/single_plot.py @@ -5,7 +5,7 @@ import matplotlib.pyplot as plt import numpy as np from itertools import product -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.estimator.abstract_estimator import AbstractEstimator from experiment.robustness_plot.display_item import DisplayItem from utils import get_full_path diff --git a/experiment/simulation/abstract_simulation.py b/experiment/simulation/abstract_simulation.py index 8cd1c03c..9e7370c5 100644 --- a/experiment/simulation/abstract_simulation.py +++ b/experiment/simulation/abstract_simulation.py @@ -13,13 +13,13 @@ import numpy as np import seaborn as sns from numpy.linalg import LinAlgError -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.extreme_models.margin_model.margin_function.combined_margin_function import \ +from extreme_fit.model.margin_model.margin_function.combined_margin_function import \ CombinedMarginFunction -from extreme_estimator.extreme_models.margin_model.margin_function.utils import error_dict_between_margin_functions -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.margin_function.utils import error_dict_between_margin_functions +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.dataset.abstract_dataset import get_subset_dataset from spatio_temporal_dataset.dataset.simulation_dataset import SimulatedDataset from spatio_temporal_dataset.slicer.split import split_to_display_kwargs diff --git a/experiment/simulation/lin_space2_simulation.py b/experiment/simulation/lin_space2_simulation.py index 271501de..5503c8de 100644 --- a/experiment/simulation/lin_space2_simulation.py +++ b/experiment/simulation/lin_space2_simulation.py @@ -1,10 +1,10 @@ from experiment.simulation.abstract_simulation import AbstractSimulation -from extreme_estimator.estimator.full_estimator.full_estimator_for_simulation import FULL_ESTIMATORS_FOR_SIMULATION -from extreme_estimator.estimator.margin_estimator.margin_estimator_for_simulation import \ +from extreme_fit.estimator.full_estimator.full_estimator_for_simulation import FULL_ESTIMATORS_FOR_SIMULATION +from extreme_fit.estimator.margin_estimator.margin_estimator_for_simulation import \ MARGIN_ESTIMATORS_FOR_SIMULATION -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel +from extreme_fit.model.max_stable_model.max_stable_models import Smith +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_1D import LinSpaceSpatialCoordinates from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset diff --git a/experiment/simulation/lin_space_simulation.py b/experiment/simulation/lin_space_simulation.py index 4a30b96e..290701a2 100644 --- a/experiment/simulation/lin_space_simulation.py +++ b/experiment/simulation/lin_space_simulation.py @@ -1,7 +1,7 @@ from experiment.simulation.abstract_simulation import AbstractSimulation -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel +from extreme_fit.model.max_stable_model.max_stable_models import Smith +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_1D import LinSpaceSpatialCoordinates from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset diff --git a/experiment/trend_analysis/non_stationary_trends.py b/experiment/trend_analysis/non_stationary_trends.py index 6f532ed2..3b6a362e 100644 --- a/experiment/trend_analysis/non_stationary_trends.py +++ b/experiment/trend_analysis/non_stationary_trends.py @@ -4,18 +4,18 @@ from typing import Union import pandas as pd -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.estimator.abstract_estimator import AbstractEstimator from scipy.stats import chi2 -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin, AbstractFullEstimator -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator, \ AbstractMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import \ LinearStationaryMarginModel, LinearNonStationaryLocationMarginModel -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ StationaryStationModel, NonStationaryLocationStationModel -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction -from extreme_estimator.extreme_models.utils import OptimizationConstants +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.utils import OptimizationConstants from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset from utils import get_display_name_from_object_type diff --git a/experiment/trend_analysis/univariate_test/abstract_comparison_non_stationary_model.py b/experiment/trend_analysis/univariate_test/abstract_comparison_non_stationary_model.py index 9bff527b..e7a64a34 100644 --- a/experiment/trend_analysis/univariate_test/abstract_comparison_non_stationary_model.py +++ b/experiment/trend_analysis/univariate_test/abstract_comparison_non_stationary_model.py @@ -1,6 +1,6 @@ from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest from experiment.trend_analysis.univariate_test.gev_trend_test_two_parameters import GevLocationAndScaleTrendTest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ NonStationaryLocationStationModel, NonStationaryScaleStationModel import numpy as np diff --git a/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py b/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py index edea9fdd..af9ae899 100644 --- a/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py +++ b/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py @@ -4,12 +4,12 @@ from cached_property import cached_property from scipy.stats import chi2 from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import AbstractTemporalLinearMarginModel -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import AbstractTemporalLinearMarginModel +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ StationaryStationModel -from extreme_estimator.extreme_models.utils import SafeRunException -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.utils import SafeRunException +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_coordinates import \ AbstractTemporalCoordinates diff --git a/experiment/trend_analysis/univariate_test/gev_trend_test_one_parameter.py b/experiment/trend_analysis/univariate_test/gev_trend_test_one_parameter.py index f2628318..27e2322b 100644 --- a/experiment/trend_analysis/univariate_test/gev_trend_test_one_parameter.py +++ b/experiment/trend_analysis/univariate_test/gev_trend_test_one_parameter.py @@ -1,7 +1,7 @@ from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ NonStationaryLocationStationModel, NonStationaryScaleStationModel, NonStationaryShapeStationModel -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams class GevTrendTestOneParameter(AbstractGevTrendTest): diff --git a/experiment/trend_analysis/univariate_test/gev_trend_test_two_parameters.py b/experiment/trend_analysis/univariate_test/gev_trend_test_two_parameters.py index 84db815a..be3671df 100644 --- a/experiment/trend_analysis/univariate_test/gev_trend_test_two_parameters.py +++ b/experiment/trend_analysis/univariate_test/gev_trend_test_two_parameters.py @@ -1,7 +1,7 @@ from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ NonStationaryLocationAndScaleModel, StationaryStationModel -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams class GevTrendTestTwoParameters(AbstractGevTrendTest): diff --git a/experiment/trend_analysis/univariate_test/utils.py b/experiment/trend_analysis/univariate_test/utils.py index 4574992d..8c208ec2 100644 --- a/experiment/trend_analysis/univariate_test/utils.py +++ b/experiment/trend_analysis/univariate_test/utils.py @@ -3,7 +3,7 @@ from multiprocessing.pool import Pool import numpy as np from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import AbstractGevTrendTest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ +from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ AbstractTemporalLinearMarginModel from utils import NB_CORES diff --git a/extreme_estimator/margin_fits/extreme_params.py b/extreme_estimator/margin_fits/extreme_params.py deleted file mode 100644 index 026c4040..00000000 --- a/extreme_estimator/margin_fits/extreme_params.py +++ /dev/null @@ -1,21 +0,0 @@ -from abc import ABC -import numpy as np - -from extreme_estimator.margin_fits.abstract_params import AbstractParams - - -class ExtremeParams(AbstractParams, ABC): - # Extreme parameters - SCALE = 'scale' - LOC = 'loc' - SHAPE = 'shape' - - def __init__(self, loc: float, scale: float, shape: float): - self.location = loc - self.scale = scale - self.shape = shape - # By default, scale cannot be negative - # (sometimes it happens, when we want to find a quantile for every point of a 2D map - # then it can happen that a corner point that was not used for fitting correspond to a negative scale, - # in the case we set all the parameters as equal to np.nan, and we will not display those points) - self.has_undefined_parameters = self.scale <= 0 \ No newline at end of file diff --git a/extreme_estimator/margin_fits/gev/fevd.py b/extreme_estimator/margin_fits/gev/fevd.py deleted file mode 100644 index 8089836e..00000000 --- a/extreme_estimator/margin_fits/gev/fevd.py +++ /dev/null @@ -1,23 +0,0 @@ -import numpy as np - -from extreme_estimator.margin_fits.gev.gev_fit import GevFit -from extreme_estimator.margin_fits.gev.gev_params import GevParams - - -class IsmevGevFit(GevFit): - - def __init__(self, x_gev: np.ndarray, y=None, mul=None): - super().__init__(x_gev) - self.y = y - self.mul = mul - self.res = fevd_gev_fit(x_gev, y, mul) - - # @property - # def gev_params(self) -> GevParams: - # assert self.y is None - # gev_params_dict = dict(zip(GevParams.PARAM_NAMES, self.res['mle'])) - # return GevParams.from_dict(gev_params_dict) - - -def fevd_gev_fit(x, y, mul): - pass \ No newline at end of file diff --git a/extreme_estimator/margin_fits/gev/gevmle_fit.py b/extreme_estimator/margin_fits/gev/gevmle_fit.py deleted file mode 100644 index 81513e2c..00000000 --- a/extreme_estimator/margin_fits/gev/gevmle_fit.py +++ /dev/null @@ -1,19 +0,0 @@ -import numpy as np - -from extreme_estimator.margin_fits.gev.gev_fit import GevFit -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.margin_fits_utils import spatial_extreme_gevmle_fit - - -class GevMleFit(GevFit): - - def __init__(self, x_gev: np.ndarray, block_size=None): - super().__init__(x_gev, block_size) - self._gev_params = spatial_extreme_gevmle_fit(x_gev) - self.gev_params_object = GevParams.from_dict({**self._gev_params, 'block_size': block_size}) - - @property - def gev_params(self) -> GevParams: - return self.gev_params_object - - diff --git a/extreme_estimator/margin_fits/gev/ismev_gev_fit.py b/extreme_estimator/margin_fits/gev/ismev_gev_fit.py deleted file mode 100644 index b214cc23..00000000 --- a/extreme_estimator/margin_fits/gev/ismev_gev_fit.py +++ /dev/null @@ -1,25 +0,0 @@ -import numpy as np - -from extreme_estimator.margin_fits.gev.gev_fit import GevFit -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.margin_fits_utils import spatial_extreme_gevmle_fit, ismev_gev_fit - - -class IsmevGevFit(GevFit): - # todo: this could be modeled with a margin_function depending only on time - # todo: I should remove the call to this object, in order to centralize all the calls - - def __init__(self, x_gev: np.ndarray, y=None, mul=None): - super().__init__(x_gev) - self.y = y - self.mul = mul - self.res = ismev_gev_fit(x_gev, y, mul) - - @property - def gev_params(self) -> GevParams: - assert self.y is None - gev_params_dict = dict(zip(GevParams.PARAM_NAMES, self.res['mle'])) - return GevParams.from_dict(gev_params_dict) - - - diff --git a/extreme_estimator/margin_fits/gpd/gpdmle_fit.py b/extreme_estimator/margin_fits/gpd/gpdmle_fit.py deleted file mode 100644 index c26d924e..00000000 --- a/extreme_estimator/margin_fits/gpd/gpdmle_fit.py +++ /dev/null @@ -1,15 +0,0 @@ -import numpy as np - -from extreme_estimator.margin_fits.gpd.gpd_params import GpdParams -from extreme_estimator.margin_fits.margin_fits_utils import spatial_extreme_gpdmle_fit - - -class GpdMleFit(object): - - def __init__(self, x_gev: np.ndarray, threshold): - assert np.ndim(x_gev) == 1 - assert len(x_gev) > 1 - self.x_gev = x_gev - self.threshold = threshold - self.mle_params = spatial_extreme_gpdmle_fit(x_gev, threshold) - self.gpd_params = GpdParams.from_dict({**self.mle_params, 'threshold': threshold}) \ No newline at end of file diff --git a/extreme_estimator/margin_fits/margin_fits_utils.py b/extreme_estimator/margin_fits/margin_fits_utils.py deleted file mode 100644 index 182ff557..00000000 --- a/extreme_estimator/margin_fits/margin_fits_utils.py +++ /dev/null @@ -1,51 +0,0 @@ -import rpy2.robjects as ro - -from extreme_estimator.extreme_models.utils import r, get_null - -""" -These two functions are “extremely light†functions to fit the GEV/GPD. These functions are mainlyuseful -to compute starting values for the Schlather and Smith mode -If more refined (univariate) analysis have to be performed, users should use more specialised pack-ages - - e.g. POT, evd, ismev, . . . . -""" - - -def spatial_extreme_gevmle_fit(x_gev): - res = r.gevmle(x_gev, method="Nelder") - return dict(zip(res.names, res)) - - -def spatial_extreme_gpdmle_fit(x_gev, threshold): - res = r.gpdmle(x_gev, threshold, method="Nelder") - return dict(zip(res.names, res)) - - -# todo: define more robust function gevmle_fit/gpdmle_fit - -""" -IsMev fit functions -""" - - -def ismev_gev_fit(x_gev, y, mul): - """ - For non-stationary fitting it is recommended that the covariates within the generalized linear models are - (at least approximately) centered and scaled (i.e.the columns of ydat should be approximately centered and scaled). - """ - xdat = ro.FloatVector(x_gev) - gev_fit = r('gev.fit') - y = y if y is not None else get_null() - mul = mul if mul is not None else get_null() - res = gev_fit(xdat, y, mul) - - # r.assign('python_wrapping', True) - # r.source(file="""/home/erwan/Documents/projects/spatiotemporalextremes/extreme_estimator/margin_fits/gev/wrapper_ismev_gev_fit.R""") - # y = np.arange(1, len(x_gev), 1).reshape((-11, 1)) - # res = r.gev_fit(data=xdat, y=y, trend=1) - return dict(zip(res.names, res)) - -# if __name__ == '__main__': -# a = np.array([2, 2]) -# v = ro.vectors.FloatVector((1, 2, 3, 4, 5)) -# ro.globalenv['a'] = a -# print(r('class(a)')) diff --git a/extreme_estimator/estimator/__init__.py b/extreme_fit/__init__.py similarity index 100% rename from extreme_estimator/estimator/__init__.py rename to extreme_fit/__init__.py diff --git a/extreme_estimator/estimator/full_estimator/__init__.py b/extreme_fit/distribution/__init__.py similarity index 100% rename from extreme_estimator/estimator/full_estimator/__init__.py rename to extreme_fit/distribution/__init__.py diff --git a/extreme_estimator/margin_fits/abstract_params.py b/extreme_fit/distribution/abstract_params.py similarity index 72% rename from extreme_estimator/margin_fits/abstract_params.py rename to extreme_fit/distribution/abstract_params.py index 5858afb3..f367a820 100644 --- a/extreme_estimator/margin_fits/abstract_params.py +++ b/extreme_fit/distribution/abstract_params.py @@ -1,3 +1,4 @@ +from abc import ABC from typing import List import numpy as np @@ -16,6 +17,20 @@ class AbstractParams(object): QUANTILE_COLORS = ['orange', 'red', 'darkviolet'] # Summary SUMMARY_NAMES = PARAM_NAMES + QUANTILE_NAMES + # Extreme parameters + SCALE = 'scale' + LOC = 'loc' + SHAPE = 'shape' + + def __init__(self, loc: float, scale: float, shape: float): + self.location = loc + self.scale = scale + self.shape = shape + # By default, scale cannot be negative + # (sometimes it happens, when we want to find a quantile for every point of a 2D map + # then it can happen that a corner point that was not used for fitting correspond to a negative scale, + # in the case we set all the parameters as equal to np.nan, and we will not display those points) + self.has_undefined_parameters = self.scale <= 0 @classmethod def from_dict(cls, params: dict): @@ -61,4 +76,3 @@ class AbstractParams(object): return pd.Series(self.summary_dict, index=self.SUMMARY_NAMES) # Estimators - diff --git a/extreme_estimator/estimator/margin_estimator/__init__.py b/extreme_fit/distribution/gev/__init__.py similarity index 100% rename from extreme_estimator/estimator/margin_estimator/__init__.py rename to extreme_fit/distribution/gev/__init__.py diff --git a/extreme_estimator/margin_fits/gev/fevd_fixed.R b/extreme_fit/distribution/gev/fevd_fixed.R similarity index 99% rename from extreme_estimator/margin_fits/gev/fevd_fixed.R rename to extreme_fit/distribution/gev/fevd_fixed.R index 22e932f2..30ee10bc 100644 --- a/extreme_estimator/margin_fits/gev/fevd_fixed.R +++ b/extreme_fit/distribution/gev/fevd_fixed.R @@ -3,6 +3,16 @@ library(extRemes) library(stats4) library(SpatialExtremes) +# Define a custom Prior function +fevdPriorCustom <- function (theta, q, p, log = FALSE){ + # Select the shape parameter (which is the last parameter) + shape = theta[length(theta)] + # + 0.5 enables to shift the Beta law in the interval [-0.5, 0.5] + res = dbeta(shape + 0.5, q, p, log = TRUE) + return(res) +} + +# Define a fixed version (that works for use.phi = FALSE for the Bayesian method) # TODO: send bug report on CRAN fevd_fixed <- function (x, data, threshold = NULL, threshold.fun = ~1, location.fun = ~1, scale.fun = ~1, shape.fun = ~1, use.phi = FALSE, type = c("GEV", @@ -93,7 +103,6 @@ fevd_fixed <- function (x, data, threshold = NULL, threshold.fun = ~1, location. blocks <- NULL } } - cat('here1') out$x <- x if (!missing(data)) out$cov.data <- data @@ -879,8 +888,6 @@ fevd_fixed <- function (x, data, threshold = NULL, threshold.fun = ~1, location. out$proposalFun <- proposalFun out$proposalParams <- proposalParams chain.info <- matrix(NA, iter, np + 2) - print(dim(chain.info)) - print(c(loc.names, sc.names, sh.names, "loglik", "prior")) colnames(chain.info) <- c(loc.names, sc.names, sh.names, "loglik", "prior") chain.info[2:iter, 1:np] <- 0 diff --git a/extreme_estimator/margin_fits/gev/gev_fit.py b/extreme_fit/distribution/gev/gev_fit.py similarity index 57% rename from extreme_estimator/margin_fits/gev/gev_fit.py rename to extreme_fit/distribution/gev/gev_fit.py index 5b3600da..ef81d978 100644 --- a/extreme_estimator/margin_fits/gev/gev_fit.py +++ b/extreme_fit/distribution/gev/gev_fit.py @@ -1,7 +1,6 @@ import numpy as np -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.margin_fits_utils import spatial_extreme_gevmle_fit +from extreme_fit.distribution.gev.gev_params import GevParams class GevFit(object): diff --git a/extreme_estimator/margin_fits/gev/gev_params.py b/extreme_fit/distribution/gev/gev_params.py similarity index 92% rename from extreme_estimator/margin_fits/gev/gev_params.py rename to extreme_fit/distribution/gev/gev_params.py index 65c12f79..bcaa537f 100644 --- a/extreme_estimator/margin_fits/gev/gev_params.py +++ b/extreme_fit/distribution/gev/gev_params.py @@ -4,17 +4,17 @@ from typing import List from cached_property import cached_property from mpmath import euler, pi -from extreme_estimator.extreme_models.utils import r -from extreme_estimator.margin_fits.extreme_params import ExtremeParams +from extreme_fit.distribution.abstract_params import AbstractParams +from extreme_fit.model.utils import r import numpy as np from scipy.special import gamma -class GevParams(ExtremeParams): +class GevParams(AbstractParams): # Parameters - PARAM_NAMES = [ExtremeParams.LOC, ExtremeParams.SCALE, ExtremeParams.SHAPE] + PARAM_NAMES = [AbstractParams.LOC, AbstractParams.SCALE, AbstractParams.SHAPE] # Summary - SUMMARY_NAMES = PARAM_NAMES + ExtremeParams.QUANTILE_NAMES + SUMMARY_NAMES = PARAM_NAMES + AbstractParams.QUANTILE_NAMES NB_SUMMARY_NAMES = len(SUMMARY_NAMES) def __init__(self, loc: float, scale: float, shape: float, block_size: int = None, accept_zero_scale_parameter=False): diff --git a/extreme_estimator/margin_fits/gev/gevmle_fit.R b/extreme_fit/distribution/gev/gevmle_fit.R similarity index 100% rename from extreme_estimator/margin_fits/gev/gevmle_fit.R rename to extreme_fit/distribution/gev/gevmle_fit.R diff --git a/extreme_fit/distribution/gev/gevmle_fit.py b/extreme_fit/distribution/gev/gevmle_fit.py new file mode 100644 index 00000000..41288004 --- /dev/null +++ b/extreme_fit/distribution/gev/gevmle_fit.py @@ -0,0 +1,29 @@ +import numpy as np + +from extreme_fit.distribution.gev.gev_fit import GevFit +from extreme_fit.distribution.gev.gev_params import GevParams +from extreme_fit.model.utils import r + +""" +These two functions are “extremely light†functions to fit the GEV/GPD. These functions are mainlyuseful +to compute starting values for the Schlather and Smith mode +If more refined (univariate) analysis have to be performed, users should use more specialised pack-ages + - e.g. POT, evd, ismev, . . . . +""" + + +def spatial_extreme_gevmle_fit(x_gev): + res = r.gevmle(x_gev, method="Nelder") + return dict(zip(res.names, res)) + + +class GevMleFit(GevFit): + + def __init__(self, x_gev: np.ndarray, block_size=None): + super().__init__(x_gev, block_size) + self._gev_params = spatial_extreme_gevmle_fit(x_gev) + self.gev_params_object = GevParams.from_dict({**self._gev_params, 'block_size': block_size}) + + @property + def gev_params(self) -> GevParams: + return self.gev_params_object diff --git a/extreme_fit/distribution/gev/ismev_gev_fit.py b/extreme_fit/distribution/gev/ismev_gev_fit.py new file mode 100644 index 00000000..ca7997aa --- /dev/null +++ b/extreme_fit/distribution/gev/ismev_gev_fit.py @@ -0,0 +1,49 @@ +import numpy as np + +from extreme_fit.distribution.gev.gev_fit import GevFit +from extreme_fit.distribution.gev.gev_params import GevParams +import rpy2.robjects as ro + +from extreme_fit.model.utils import r, get_null + + +""" +IsMev fit functions +""" + + +def ismev_gev_fit(x_gev, y, mul): + """ + For non-stationary fitting it is recommended that the covariates within the generalized linear models are + (at least approximately) centered and scaled (i.e.the columns of ydat should be approximately centered and scaled). + """ + xdat = ro.FloatVector(x_gev) + gev_fit = r('gev.fit') + y = y if y is not None else get_null() + mul = mul if mul is not None else get_null() + res = gev_fit(xdat, y, mul) + + # r.assign('python_wrapping', True) + # r.source(file="""/home/erwan/Documents/projects/spatiotemporalextremes/extreme_fit/distribution/gev/wrapper_ismev_gev_fit.R""") + # y = np.arange(1, len(x_gev), 1).reshape((-11, 1)) + # res = r.gev_fit(data=xdat, y=y, trend=1) + return dict(zip(res.names, res)) + +class IsmevGevFit(GevFit): + # todo: this could be modeled with a margin_function depending only on time + # todo: I should remove the call to this object, in order to centralize all the calls + + def __init__(self, x_gev: np.ndarray, y=None, mul=None): + super().__init__(x_gev) + self.y = y + self.mul = mul + self.res = ismev_gev_fit(x_gev, y, mul) + + @property + def gev_params(self) -> GevParams: + assert self.y is None + gev_params_dict = dict(zip(GevParams.PARAM_NAMES, self.res['mle'])) + return GevParams.from_dict(gev_params_dict) + + + diff --git a/extreme_estimator/margin_fits/gev/main_fevd_fixed.R b/extreme_fit/distribution/gev/main_fevd_fixed.R similarity index 76% rename from extreme_estimator/margin_fits/gev/main_fevd_fixed.R rename to extreme_fit/distribution/gev/main_fevd_fixed.R index 9ed5d7e9..6ecf87bb 100644 --- a/extreme_estimator/margin_fits/gev/main_fevd_fixed.R +++ b/extreme_fit/distribution/gev/main_fevd_fixed.R @@ -5,7 +5,7 @@ library(extRemes) library(stats4) library(SpatialExtremes) -source('myfevd.R') +source('fevd_fixed.R') # Sample from a GEV set.seed(42) N <- 1000 @@ -26,35 +26,28 @@ x_gev <- rgev(N, loc = loc, scale = scale, shape = shape) # return(prod(res)) # } -fevdPriorMyMy <- function (theta, q, p, log = FALSE){ - # print(theta) - # print(q) - # print(p) - x = theta[length(theta)] - # + 0.5 enables to shift the Beta law in the interval [-0.5, 0.5] - res = dbeta(x + 0.5, q, p, log = TRUE) - return(res) -} + print(pbeta(1.0, 1, 1)) print(pbeta(0.5, 1, 1)) -print(fevdPriorMyMy(2.0, 0.0, 0.0)) +print(fevdPriorCustom(2.0, 0.0, 0.0)) # res = fevd(x_gev, method='Bayesian', priorFun="fevdPriorMyMy", priorParams=list(q=c(6), p=c(9)), iter=5000, verbose=TRUE, use.phi=FALSE) -res = fevd_fixed(x_gev, method='Bayesian', priorFun="fevdPriorMyMy", priorParams=list(q=c(6), p=c(9)), iter=5000, verbose=TRUE, use.phi=FALSE) +res = fevd_fixed(x_gev, method='Bayesian', priorFun="fevdPriorCustom", priorParams=list(q=c(6), p=c(9)), iter=5000, verbose=TRUE, use.phi=FALSE) # res = fevd(x_gev, method='GMLE', iter=5000, verbose=TRUE, use.phi=FALSE) print(res) - +print('here') +print(res$constant.loc) +print('here2') print(res$method) print(res$priorFun) print(res$priorParams) m = res$results print(dim(m)) -print(m) print(m[1,]) print(m[1,1]) diff --git a/extreme_estimator/margin_fits/gev/wrapper_ismev_gev_fit.R b/extreme_fit/distribution/gev/wrapper_ismev_gev_fit.R similarity index 100% rename from extreme_estimator/margin_fits/gev/wrapper_ismev_gev_fit.R rename to extreme_fit/distribution/gev/wrapper_ismev_gev_fit.R diff --git a/extreme_estimator/estimator/max_stable_estimator/__init__.py b/extreme_fit/distribution/gpd/__init__.py similarity index 100% rename from extreme_estimator/estimator/max_stable_estimator/__init__.py rename to extreme_fit/distribution/gpd/__init__.py diff --git a/extreme_estimator/margin_fits/gpd/gpd_params.py b/extreme_fit/distribution/gpd/gpd_params.py similarity index 67% rename from extreme_estimator/margin_fits/gpd/gpd_params.py rename to extreme_fit/distribution/gpd/gpd_params.py index 0c8cc815..c440415f 100644 --- a/extreme_estimator/margin_fits/gpd/gpd_params.py +++ b/extreme_fit/distribution/gpd/gpd_params.py @@ -1,14 +1,14 @@ -from extreme_estimator.extreme_models.utils import r -from extreme_estimator.margin_fits.extreme_params import ExtremeParams +from extreme_fit.distribution.abstract_params import AbstractParams +from extreme_fit.model.utils import r -class GpdParams(ExtremeParams): +class GpdParams(AbstractParams): # TODO: understand better why the gpdfit return 2 parameters, alors que d'un autre cote d autres definitions de la distribution parlent d un parametre location # Parameters - PARAM_NAMES = [ExtremeParams.SCALE, ExtremeParams.SHAPE] + PARAM_NAMES = [AbstractParams.SCALE, AbstractParams.SHAPE] # Summary - SUMMARY_NAMES = PARAM_NAMES + ExtremeParams.QUANTILE_NAMES + SUMMARY_NAMES = PARAM_NAMES + AbstractParams.QUANTILE_NAMES def __init__(self, scale: float, shape: float, threshold: float = None): super().__init__(loc=0.0, scale=scale, shape=shape) diff --git a/extreme_fit/distribution/gpd/gpdmle_fit.py b/extreme_fit/distribution/gpd/gpdmle_fit.py new file mode 100644 index 00000000..ef88352f --- /dev/null +++ b/extreme_fit/distribution/gpd/gpdmle_fit.py @@ -0,0 +1,26 @@ +import numpy as np + +from extreme_fit.distribution.gpd.gpd_params import GpdParams +from extreme_fit.model.utils import r + +""" +These two functions are “extremely light†functions to fit the GEV/GPD. These functions are mainlyuseful +to compute starting values for the Schlather and Smith mode +If more refined (univariate) analysis have to be performed, users should use more specialised pack-ages + - e.g. POT, evd, ismev, . . . . +""" + + +def spatial_extreme_gpdmle_fit(x_gev, threshold): + res = r.gpdmle(x_gev, threshold, method="Nelder") + return dict(zip(res.names, res)) + +class GpdMleFit(object): + + def __init__(self, x_gev: np.ndarray, threshold): + assert np.ndim(x_gev) == 1 + assert len(x_gev) > 1 + self.x_gev = x_gev + self.threshold = threshold + self.mle_params = spatial_extreme_gpdmle_fit(x_gev, threshold) + self.gpd_params = GpdParams.from_dict({**self.mle_params, 'threshold': threshold}) \ No newline at end of file diff --git a/extreme_estimator/extreme_models/__init__.py b/extreme_fit/estimator/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/__init__.py rename to extreme_fit/estimator/__init__.py diff --git a/extreme_estimator/estimator/abstract_estimator.py b/extreme_fit/estimator/abstract_estimator.py similarity index 83% rename from extreme_estimator/estimator/abstract_estimator.py rename to extreme_fit/estimator/abstract_estimator.py index 8d13038b..5e8b880e 100644 --- a/extreme_estimator/estimator/abstract_estimator.py +++ b/extreme_fit/estimator/abstract_estimator.py @@ -2,8 +2,8 @@ from typing import Union from cached_property import cached_property -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/extreme_models/margin_model/__init__.py b/extreme_fit/estimator/full_estimator/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/margin_model/__init__.py rename to extreme_fit/estimator/full_estimator/__init__.py diff --git a/extreme_estimator/estimator/full_estimator/abstract_full_estimator.py b/extreme_fit/estimator/full_estimator/abstract_full_estimator.py similarity index 83% rename from extreme_estimator/estimator/full_estimator/abstract_full_estimator.py rename to extreme_fit/estimator/full_estimator/abstract_full_estimator.py index 8185ba10..754054f3 100644 --- a/extreme_estimator/estimator/full_estimator/abstract_full_estimator.py +++ b/extreme_fit/estimator/full_estimator/abstract_full_estimator.py @@ -1,13 +1,13 @@ from cached_property import cached_property -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator -from extreme_estimator.estimator.utils import load_margin_function -from extreme_estimator.extreme_models.margin_model.abstract_margin_model import AbstractMarginModel -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel +from extreme_fit.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator +from extreme_fit.estimator.utils import load_margin_function +from extreme_fit.model.margin_model.abstract_margin_model import AbstractMarginModel +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/estimator/full_estimator/full_estimator_for_simulation.py b/extreme_fit/estimator/full_estimator/full_estimator_for_simulation.py similarity index 76% rename from extreme_estimator/estimator/full_estimator/full_estimator_for_simulation.py rename to extreme_fit/estimator/full_estimator/full_estimator_for_simulation.py index 811db6d3..1fe18a1c 100644 --- a/extreme_estimator/estimator/full_estimator/full_estimator_for_simulation.py +++ b/extreme_fit/estimator/full_estimator/full_estimator_for_simulation.py @@ -1,8 +1,8 @@ -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ ConstantMarginModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith +from extreme_fit.model.max_stable_model.max_stable_models import Smith from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/extreme_models/margin_model/linear_margin_model/__init__.py b/extreme_fit/estimator/margin_estimator/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/margin_model/linear_margin_model/__init__.py rename to extreme_fit/estimator/margin_estimator/__init__.py diff --git a/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py b/extreme_fit/estimator/margin_estimator/abstract_margin_estimator.py similarity index 76% rename from extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py rename to extreme_fit/estimator/margin_estimator/abstract_margin_estimator.py index be13d011..da993d39 100644 --- a/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py +++ b/extreme_fit/estimator/margin_estimator/abstract_margin_estimator.py @@ -2,11 +2,11 @@ from abc import ABC from cached_property import cached_property -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator -from extreme_estimator.estimator.utils import load_margin_function -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit +from extreme_fit.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.estimator.utils import load_margin_function +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/estimator/margin_estimator/margin_estimator_for_simulation.py b/extreme_fit/estimator/margin_estimator/margin_estimator_for_simulation.py similarity index 73% rename from extreme_estimator/estimator/margin_estimator/margin_estimator_for_simulation.py rename to extreme_fit/estimator/margin_estimator/margin_estimator_for_simulation.py index 311fba79..70f6a7b6 100644 --- a/extreme_estimator/estimator/margin_estimator/margin_estimator_for_simulation.py +++ b/extreme_fit/estimator/margin_estimator/margin_estimator_for_simulation.py @@ -1,5 +1,5 @@ -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ ConstantMarginModel from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/__init__.py b/extreme_fit/estimator/max_stable_estimator/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/margin_model/margin_function/__init__.py rename to extreme_fit/estimator/max_stable_estimator/__init__.py diff --git a/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py b/extreme_fit/estimator/max_stable_estimator/abstract_max_stable_estimator.py similarity index 83% rename from extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py rename to extreme_fit/estimator/max_stable_estimator/abstract_max_stable_estimator.py index a824b422..837082fa 100644 --- a/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py +++ b/extreme_fit/estimator/max_stable_estimator/abstract_max_stable_estimator.py @@ -1,7 +1,7 @@ import numpy as np -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel +from extreme_fit.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset diff --git a/extreme_estimator/estimator/utils.py b/extreme_fit/estimator/utils.py similarity index 64% rename from extreme_estimator/estimator/utils.py rename to extreme_fit/estimator/utils.py index f14fd7f4..4f27e949 100644 --- a/extreme_estimator/estimator/utils.py +++ b/extreme_fit/estimator/utils.py @@ -1,6 +1,6 @@ -from extreme_estimator.estimator.abstract_estimator import AbstractEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.estimator.abstract_estimator import AbstractEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction def load_margin_function(estimator: AbstractEstimator, margin_model: LinearMarginModel, margin_function_class=LinearMarginFunction): diff --git a/extreme_estimator/extreme_models/margin_model/param_function/__init__.py b/extreme_fit/model/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/margin_model/param_function/__init__.py rename to extreme_fit/model/__init__.py diff --git a/extreme_estimator/extreme_models/abstract_model.py b/extreme_fit/model/abstract_model.py similarity index 100% rename from extreme_estimator/extreme_models/abstract_model.py rename to extreme_fit/model/abstract_model.py diff --git a/extreme_estimator/extreme_models/max_stable_model/__init__.py b/extreme_fit/model/margin_model/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/max_stable_model/__init__.py rename to extreme_fit/model/margin_model/__init__.py diff --git a/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py b/extreme_fit/model/margin_model/abstract_margin_model.py similarity index 90% rename from extreme_estimator/extreme_models/margin_model/abstract_margin_model.py rename to extreme_fit/model/margin_model/abstract_margin_model.py index 7db9d3d8..a9436f6b 100644 --- a/extreme_estimator/extreme_models/margin_model/abstract_margin_model.py +++ b/extreme_fit/model/margin_model/abstract_margin_model.py @@ -3,12 +3,12 @@ from abc import ABC import numpy as np import pandas as pd -from extreme_estimator.extreme_models.abstract_model import AbstractModel -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function \ +from extreme_fit.model.abstract_model import AbstractModel +from extreme_fit.model.margin_model.margin_function.abstract_margin_function \ import AbstractMarginFunction -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit -from extreme_estimator.extreme_models.utils import r -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit +from extreme_fit.model.utils import r +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/fitspatgev.R b/extreme_fit/model/margin_model/fitspatgev.R similarity index 100% rename from extreme_estimator/extreme_models/margin_model/fitspatgev.R rename to extreme_fit/model/margin_model/fitspatgev.R diff --git a/extreme_estimator/extreme_models/result_from_model_fit/__init__.py b/extreme_fit/model/margin_model/linear_margin_model/__init__.py similarity index 100% rename from extreme_estimator/extreme_models/result_from_model_fit/__init__.py rename to extreme_fit/model/margin_model/linear_margin_model/__init__.py diff --git a/extreme_estimator/extreme_models/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py similarity index 83% rename from extreme_estimator/extreme_models/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py rename to extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py index 67c2ffea..f67a5b85 100644 --- a/extreme_estimator/extreme_models/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py +++ b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py @@ -1,12 +1,12 @@ import numpy as np import pandas as pd -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit -from extreme_estimator.extreme_models.result_from_model_fit.result_from_extremes import ResultFromExtremes -from extreme_estimator.extreme_models.result_from_model_fit.result_from_ismev import ResultFromIsmev -from extreme_estimator.extreme_models.utils import r, ro, get_null -from extreme_estimator.extreme_models.utils import safe_run_r_estimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearMarginModel +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import AbstractResultFromModelFit +from extreme_fit.model.result_from_model_fit.result_from_extremes import ResultFromExtremes +from extreme_fit.model.result_from_model_fit.result_from_ismev import ResultFromIsmev +from extreme_fit.model.utils import r, ro, get_null +from extreme_fit.model.utils import safe_run_r_estimator from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/linear_margin_model/linear_margin_model.py b/extreme_fit/model/margin_model/linear_margin_model/linear_margin_model.py similarity index 94% rename from extreme_estimator/extreme_models/margin_model/linear_margin_model/linear_margin_model.py rename to extreme_fit/model/margin_model/linear_margin_model/linear_margin_model.py index 1cf924de..f84b50c5 100644 --- a/extreme_estimator/extreme_models/margin_model/linear_margin_model/linear_margin_model.py +++ b/extreme_fit/model/margin_model/linear_margin_model/linear_margin_model.py @@ -1,7 +1,7 @@ -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.linear_coef import LinearCoef -from extreme_estimator.extreme_models.margin_model.parametric_margin_model import ParametricMarginModel -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.margin_model.param_function.linear_coef import LinearCoef +from extreme_fit.model.margin_model.parametric_margin_model import ParametricMarginModel +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/linear_margin_model/temporal_linear_margin_models.py b/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py similarity index 87% rename from extreme_estimator/extreme_models/margin_model/linear_margin_model/temporal_linear_margin_models.py rename to extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py index fb7eaf39..1efcf41a 100644 --- a/extreme_estimator/extreme_models/margin_model/linear_margin_model/temporal_linear_margin_models.py +++ b/extreme_fit/model/margin_model/linear_margin_model/temporal_linear_margin_models.py @@ -1,7 +1,7 @@ -from extreme_estimator.extreme_models.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ +from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ AbstractTemporalLinearMarginModel -from extreme_estimator.extreme_models.utils import r -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.utils import r +from extreme_fit.distribution.gev.gev_params import GevParams class StationaryStationModel(AbstractTemporalLinearMarginModel): diff --git a/extreme_estimator/margin_fits/__init__.py b/extreme_fit/model/margin_model/margin_function/__init__.py similarity index 100% rename from extreme_estimator/margin_fits/__init__.py rename to extreme_fit/model/margin_model/margin_function/__init__.py diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py b/extreme_fit/model/margin_model/margin_function/abstract_margin_function.py similarity index 97% rename from extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py rename to extreme_fit/model/margin_model/margin_function/abstract_margin_function.py index 2115b173..9dd671bc 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/abstract_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/abstract_margin_function.py @@ -5,8 +5,8 @@ import numpy as np import pandas as pd from experiment.meteo_france_data.scm_models_data.visualization.utils import create_adjusted_axes -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.plot.create_shifted_cmap import imshow_shifted +from extreme_fit.distribution.gev.gev_params import GevParams +from experiment.meteo_france_data.plot.create_shifted_cmap import imshow_shifted from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.slicer.split import Split from utils import cached_property @@ -58,7 +58,7 @@ class AbstractMarginFunction(object): def gev_value_name_to_serie(self) -> Dict[str, pd.Series]: # Load the gev_params gev_params = [self.get_gev_params(coordinate) for coordinate in self.coordinates.coordinates_values()] - # Load the dictionary of values (margin_fits parameters + the quantiles) + # Load the dictionary of values (distribution parameters + the quantiles) value_dicts = [gev_param.summary_dict for gev_param in gev_params] gev_value_name_to_serie = {} for value_name in GevParams.SUMMARY_NAMES: diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/combined_margin_function.py b/extreme_fit/model/margin_model/margin_function/combined_margin_function.py similarity index 89% rename from extreme_estimator/extreme_models/margin_model/margin_function/combined_margin_function.py rename to extreme_fit/model/margin_model/margin_function/combined_margin_function.py index 59019cca..ef3b683b 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/combined_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/combined_margin_function.py @@ -3,9 +3,9 @@ from itertools import combinations import numpy as np -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py b/extreme_fit/model/margin_model/margin_function/independent_margin_function.py similarity index 85% rename from extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py rename to extreme_fit/model/margin_model/margin_function/independent_margin_function.py index 281b40c8..49dd3329 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/independent_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/independent_margin_function.py @@ -2,9 +2,9 @@ from typing import Dict, Union import numpy as np -from extreme_estimator.extreme_models.margin_model.param_function.param_function import AbstractParamFunction -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.param_function.param_function import AbstractParamFunction +from extreme_fit.distribution.gev.gev_params import GevParams +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/linear_margin_function.py b/extreme_fit/model/margin_model/margin_function/linear_margin_function.py similarity index 81% rename from extreme_estimator/extreme_models/margin_model/margin_function/linear_margin_function.py rename to extreme_fit/model/margin_model/margin_function/linear_margin_function.py index ac760eb6..157a62b9 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/linear_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/linear_margin_function.py @@ -1,13 +1,13 @@ from typing import Dict, List, Union -from extreme_estimator.extreme_models.margin_model.margin_function.parametric_margin_function import \ +from extreme_fit.distribution.abstract_params import AbstractParams +from extreme_fit.model.margin_model.margin_function.parametric_margin_function import \ ParametricMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef -from extreme_estimator.extreme_models.margin_model.param_function.linear_coef import LinearCoef -from extreme_estimator.extreme_models.margin_model.param_function.param_function import AbstractParamFunction, \ +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.linear_coef import LinearCoef +from extreme_fit.model.margin_model.param_function.param_function import AbstractParamFunction, \ LinearParamFunction -from extreme_estimator.margin_fits.extreme_params import ExtremeParams -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates @@ -89,16 +89,16 @@ class LinearMarginFunction(ParametricMarginFunction): @property def mu1_temporal_trend(self): - return self.coef_dict[LinearCoef.coef_template_str(ExtremeParams.LOC, AbstractCoordinates.COORDINATE_T).format(1)] + return self.coef_dict[LinearCoef.coef_template_str(AbstractParams.LOC, AbstractCoordinates.COORDINATE_T).format(1)] @property def mu_intercept(self): - return self.coef_dict[LinearCoef.coef_template_str(ExtremeParams.LOC, LinearCoef.INTERCEPT_NAME).format(1)] + return self.coef_dict[LinearCoef.coef_template_str(AbstractParams.LOC, LinearCoef.INTERCEPT_NAME).format(1)] @property def mu_longitude_trend(self): - return self.coef_dict[LinearCoef.coef_template_str(ExtremeParams.LOC, AbstractCoordinates.COORDINATE_X).format(2)] + return self.coef_dict[LinearCoef.coef_template_str(AbstractParams.LOC, AbstractCoordinates.COORDINATE_X).format(2)] @property def mu_latitude_trend(self): - return self.coef_dict[LinearCoef.coef_template_str(ExtremeParams.LOC, AbstractCoordinates.COORDINATE_Y).format(3)] \ No newline at end of file + return self.coef_dict[LinearCoef.coef_template_str(AbstractParams.LOC, AbstractCoordinates.COORDINATE_Y).format(3)] \ No newline at end of file diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/parametric_margin_function.py b/extreme_fit/model/margin_model/margin_function/parametric_margin_function.py similarity index 92% rename from extreme_estimator/extreme_models/margin_model/margin_function/parametric_margin_function.py rename to extreme_fit/model/margin_model/margin_function/parametric_margin_function.py index de427079..89a26baa 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/parametric_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/parametric_margin_function.py @@ -2,12 +2,12 @@ from typing import Dict, List, Union import numpy as np -from extreme_estimator.extreme_models.margin_model.margin_function.independent_margin_function import \ +from extreme_fit.model.margin_model.margin_function.independent_margin_function import \ IndependentMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef -from extreme_estimator.extreme_models.margin_model.param_function.param_function import AbstractParamFunction, \ +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.param_function import AbstractParamFunction, \ ConstantParamFunction -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/spline_margin_function.py b/extreme_fit/model/margin_model/margin_function/spline_margin_function.py similarity index 84% rename from extreme_estimator/extreme_models/margin_model/margin_function/spline_margin_function.py rename to extreme_fit/model/margin_model/margin_function/spline_margin_function.py index d7560ea6..ef8af6af 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/spline_margin_function.py +++ b/extreme_fit/model/margin_model/margin_function/spline_margin_function.py @@ -2,12 +2,12 @@ from typing import Dict, List import numpy as np -from extreme_estimator.extreme_models.margin_model.margin_function.parametric_margin_function import \ +from extreme_fit.model.margin_model.margin_function.parametric_margin_function import \ ParametricMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef -from extreme_estimator.extreme_models.margin_model.param_function.param_function import AbstractParamFunction, \ +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.param_function import AbstractParamFunction, \ SplineParamFunction -from extreme_estimator.extreme_models.margin_model.param_function.spline_coef import SplineCoef +from extreme_fit.model.margin_model.param_function.spline_coef import SplineCoef from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/margin_function/utils.py b/extreme_fit/model/margin_model/margin_function/utils.py similarity index 86% rename from extreme_estimator/extreme_models/margin_model/margin_function/utils.py rename to extreme_fit/model/margin_model/margin_function/utils.py index d2e0e1c2..bc3aec46 100644 --- a/extreme_estimator/extreme_models/margin_model/margin_function/utils.py +++ b/extreme_fit/model/margin_model/margin_function/utils.py @@ -1,6 +1,6 @@ -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams def relative_abs_error(reference_value, fitted_value): diff --git a/extreme_estimator/margin_fits/gev/__init__.py b/extreme_fit/model/margin_model/param_function/__init__.py similarity index 100% rename from extreme_estimator/margin_fits/gev/__init__.py rename to extreme_fit/model/margin_model/param_function/__init__.py diff --git a/extreme_estimator/extreme_models/margin_model/param_function/abstract_coef.py b/extreme_fit/model/margin_model/param_function/abstract_coef.py similarity index 100% rename from extreme_estimator/extreme_models/margin_model/param_function/abstract_coef.py rename to extreme_fit/model/margin_model/param_function/abstract_coef.py diff --git a/extreme_estimator/extreme_models/margin_model/param_function/linear_coef.py b/extreme_fit/model/margin_model/param_function/linear_coef.py similarity index 97% rename from extreme_estimator/extreme_models/margin_model/param_function/linear_coef.py rename to extreme_fit/model/margin_model/param_function/linear_coef.py index 6270d0cf..85755931 100644 --- a/extreme_estimator/extreme_models/margin_model/param_function/linear_coef.py +++ b/extreme_fit/model/margin_model/param_function/linear_coef.py @@ -1,6 +1,6 @@ from typing import Dict, List -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/param_function/param_function.py b/extreme_fit/model/margin_model/param_function/param_function.py similarity index 93% rename from extreme_estimator/extreme_models/margin_model/param_function/param_function.py rename to extreme_fit/model/margin_model/param_function/param_function.py index 42620d71..61cb890d 100644 --- a/extreme_estimator/extreme_models/margin_model/param_function/param_function.py +++ b/extreme_fit/model/margin_model/param_function/param_function.py @@ -1,7 +1,7 @@ from typing import List import numpy as np -from extreme_estimator.extreme_models.margin_model.param_function.linear_coef import LinearCoef -from extreme_estimator.extreme_models.margin_model.param_function.spline_coef import SplineCoef +from extreme_fit.model.margin_model.param_function.linear_coef import LinearCoef +from extreme_fit.model.margin_model.param_function.spline_coef import SplineCoef class AbstractParamFunction(object): diff --git a/extreme_estimator/extreme_models/margin_model/param_function/spline_coef.py b/extreme_fit/model/margin_model/param_function/spline_coef.py similarity index 91% rename from extreme_estimator/extreme_models/margin_model/param_function/spline_coef.py rename to extreme_fit/model/margin_model/param_function/spline_coef.py index 2e3f86e5..c3564d8f 100644 --- a/extreme_estimator/extreme_models/margin_model/param_function/spline_coef.py +++ b/extreme_fit/model/margin_model/param_function/spline_coef.py @@ -1,6 +1,6 @@ from typing import Dict -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef class PolynomialCoef(AbstractCoef): diff --git a/extreme_estimator/extreme_models/margin_model/parametric_margin_model.py b/extreme_fit/model/margin_model/parametric_margin_model.py similarity index 80% rename from extreme_estimator/extreme_models/margin_model/parametric_margin_model.py rename to extreme_fit/model/margin_model/parametric_margin_model.py index be503f03..9a762b14 100644 --- a/extreme_estimator/extreme_models/margin_model/parametric_margin_model.py +++ b/extreme_fit/model/margin_model/parametric_margin_model.py @@ -3,11 +3,11 @@ from abc import ABC import numpy as np import pandas as pd -from extreme_estimator.extreme_models.margin_model.margin_function.parametric_margin_function import \ +from extreme_fit.model.margin_model.margin_function.parametric_margin_function import \ ParametricMarginFunction -from extreme_estimator.extreme_models.result_from_model_fit.result_from_spatial_extreme import ResultFromSpatialExtreme -from extreme_estimator.extreme_models.margin_model.abstract_margin_model import AbstractMarginModel -from extreme_estimator.extreme_models.utils import safe_run_r_estimator, r, get_coord, \ +from extreme_fit.model.result_from_model_fit.result_from_spatial_extreme import ResultFromSpatialExtreme +from extreme_fit.model.margin_model.abstract_margin_model import AbstractMarginModel +from extreme_fit.model.utils import safe_run_r_estimator, r, get_coord, \ get_margin_formula from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/margin_model/spline_margin_model.py b/extreme_fit/model/margin_model/spline_margin_model.py similarity index 88% rename from extreme_estimator/extreme_models/margin_model/spline_margin_model.py rename to extreme_fit/model/margin_model/spline_margin_model.py index e7777b6f..50af051c 100644 --- a/extreme_estimator/extreme_models/margin_model/spline_margin_model.py +++ b/extreme_fit/model/margin_model/spline_margin_model.py @@ -1,11 +1,11 @@ from typing import Dict, List -from extreme_estimator.extreme_models.margin_model.margin_function.spline_margin_function import SplineMarginFunction -from extreme_estimator.extreme_models.margin_model.param_function.abstract_coef import AbstractCoef -from extreme_estimator.extreme_models.margin_model.param_function.spline_coef import SplineCoef, KnotCoef, \ +from extreme_fit.model.margin_model.margin_function.spline_margin_function import SplineMarginFunction +from extreme_fit.model.margin_model.param_function.abstract_coef import AbstractCoef +from extreme_fit.model.margin_model.param_function.spline_coef import SplineCoef, KnotCoef, \ PolynomialCoef -from extreme_estimator.extreme_models.margin_model.parametric_margin_model import ParametricMarginModel -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.parametric_margin_model import ParametricMarginModel +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/margin_fits/gpd/__init__.py b/extreme_fit/model/max_stable_model/__init__.py similarity index 100% rename from extreme_estimator/margin_fits/gpd/__init__.py rename to extreme_fit/model/max_stable_model/__init__.py diff --git a/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py b/extreme_fit/model/max_stable_model/abstract_max_stable_model.py similarity index 94% rename from extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py rename to extreme_fit/model/max_stable_model/abstract_max_stable_model.py index b1fc374d..b2daca59 100644 --- a/extreme_estimator/extreme_models/max_stable_model/abstract_max_stable_model.py +++ b/extreme_fit/model/max_stable_model/abstract_max_stable_model.py @@ -5,9 +5,9 @@ import pandas as pd from rpy2.rinterface import RRuntimeWarning from rpy2.rinterface._rinterface import RRuntimeError -from extreme_estimator.extreme_models.abstract_model import AbstractModel -from extreme_estimator.extreme_models.result_from_model_fit.result_from_spatial_extreme import ResultFromSpatialExtreme -from extreme_estimator.extreme_models.utils import r, safe_run_r_estimator, get_coord, \ +from extreme_fit.model.abstract_model import AbstractModel +from extreme_fit.model.result_from_model_fit.result_from_spatial_extreme import ResultFromSpatialExtreme +from extreme_fit.model.utils import r, safe_run_r_estimator, get_coord, \ get_margin_formula, SafeRunException from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/max_stable_model/max_stable_fit.R b/extreme_fit/model/max_stable_model/max_stable_fit.R similarity index 100% rename from extreme_estimator/extreme_models/max_stable_model/max_stable_fit.R rename to extreme_fit/model/max_stable_model/max_stable_fit.R diff --git a/extreme_estimator/extreme_models/max_stable_model/max_stable_models.py b/extreme_fit/model/max_stable_model/max_stable_models.py similarity index 95% rename from extreme_estimator/extreme_models/max_stable_model/max_stable_models.py rename to extreme_fit/model/max_stable_model/max_stable_models.py index 0e4c7191..410f9d3f 100644 --- a/extreme_estimator/extreme_models/max_stable_model/max_stable_models.py +++ b/extreme_fit/model/max_stable_model/max_stable_models.py @@ -1,6 +1,6 @@ from enum import Enum -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel, \ +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel, \ AbstractMaxStableModelWithCovarianceFunction, CovarianceFunction diff --git a/extreme_estimator/extreme_models/max_stable_model/max_stable_with_spline.R b/extreme_fit/model/max_stable_model/max_stable_with_spline.R similarity index 100% rename from extreme_estimator/extreme_models/max_stable_model/max_stable_with_spline.R rename to extreme_fit/model/max_stable_model/max_stable_with_spline.R diff --git a/extreme_estimator/extreme_models/max_stable_model/test.R b/extreme_fit/model/max_stable_model/test.R similarity index 100% rename from extreme_estimator/extreme_models/max_stable_model/test.R rename to extreme_fit/model/max_stable_model/test.R diff --git a/extreme_estimator/margin_fits/plot/__init__.py b/extreme_fit/model/result_from_model_fit/__init__.py similarity index 100% rename from extreme_estimator/margin_fits/plot/__init__.py rename to extreme_fit/model/result_from_model_fit/__init__.py diff --git a/extreme_estimator/extreme_models/result_from_model_fit/abstract_result_from_model_fit.py b/extreme_fit/model/result_from_model_fit/abstract_result_from_model_fit.py similarity index 100% rename from extreme_estimator/extreme_models/result_from_model_fit/abstract_result_from_model_fit.py rename to extreme_fit/model/result_from_model_fit/abstract_result_from_model_fit.py diff --git a/extreme_estimator/extreme_models/result_from_model_fit/result_from_extremes.py b/extreme_fit/model/result_from_model_fit/result_from_extremes.py similarity index 94% rename from extreme_estimator/extreme_models/result_from_model_fit/result_from_extremes.py rename to extreme_fit/model/result_from_model_fit/result_from_extremes.py index 0103b8be..7bb02b57 100644 --- a/extreme_estimator/extreme_models/result_from_model_fit/result_from_extremes.py +++ b/extreme_fit/model/result_from_model_fit/result_from_extremes.py @@ -1,6 +1,6 @@ from rpy2 import robjects -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import \ +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import \ AbstractResultFromModelFit diff --git a/extreme_estimator/extreme_models/result_from_model_fit/result_from_ismev.py b/extreme_fit/model/result_from_model_fit/result_from_ismev.py similarity index 82% rename from extreme_estimator/extreme_models/result_from_model_fit/result_from_ismev.py rename to extreme_fit/model/result_from_model_fit/result_from_ismev.py index 0300d86e..e3691fc2 100644 --- a/extreme_estimator/extreme_models/result_from_model_fit/result_from_ismev.py +++ b/extreme_fit/model/result_from_model_fit/result_from_ismev.py @@ -3,11 +3,11 @@ from typing import Dict import numpy as np from rpy2 import robjects -from extreme_estimator.extreme_models.margin_model.param_function.linear_coef import LinearCoef -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import \ +from extreme_fit.model.margin_model.param_function.linear_coef import LinearCoef +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import \ AbstractResultFromModelFit -from extreme_estimator.extreme_models.result_from_model_fit.utils import convertFloatVector_to_float -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.result_from_model_fit.utils import convertFloatVector_to_float +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates diff --git a/extreme_estimator/extreme_models/result_from_model_fit/result_from_spatial_extreme.py b/extreme_fit/model/result_from_model_fit/result_from_spatial_extreme.py similarity index 85% rename from extreme_estimator/extreme_models/result_from_model_fit/result_from_spatial_extreme.py rename to extreme_fit/model/result_from_model_fit/result_from_spatial_extreme.py index bf98c665..8e46fde4 100644 --- a/extreme_estimator/extreme_models/result_from_model_fit/result_from_spatial_extreme.py +++ b/extreme_fit/model/result_from_model_fit/result_from_spatial_extreme.py @@ -2,8 +2,8 @@ from typing import Dict import numpy as np -from extreme_estimator.extreme_models.margin_model.param_function.linear_coef import LinearCoef -from extreme_estimator.extreme_models.result_from_model_fit.abstract_result_from_model_fit import \ +from extreme_fit.model.margin_model.param_function.linear_coef import LinearCoef +from extreme_fit.model.result_from_model_fit.abstract_result_from_model_fit import \ AbstractResultFromModelFit diff --git a/extreme_estimator/extreme_models/result_from_model_fit/utils.py b/extreme_fit/model/result_from_model_fit/utils.py similarity index 100% rename from extreme_estimator/extreme_models/result_from_model_fit/utils.py rename to extreme_fit/model/result_from_model_fit/utils.py diff --git a/extreme_estimator/extreme_models/utils.py b/extreme_fit/model/utils.py similarity index 97% rename from extreme_estimator/extreme_models/utils.py rename to extreme_fit/model/utils.py index d085837c..f7ffaf04 100644 --- a/extreme_estimator/extreme_models/utils.py +++ b/extreme_fit/model/utils.py @@ -31,7 +31,7 @@ warnings.filterwarnings("ignore") # Load ismev r.library('ismev') # Load fevd fixed -fevd_fixed_filepath = op.join(get_root_path(), 'extreme_estimator', 'margin_fits', 'gev', 'fevd_fixed.R') +fevd_fixed_filepath = op.join(get_root_path(), 'extreme_fit', 'distribution', 'gev', 'fevd_fixed.R') assert op.exists(fevd_fixed_filepath) r.source(fevd_fixed_filepath) # Reactivate warning diff --git a/spatio_temporal_dataset/dataset/simulation_dataset.py b/spatio_temporal_dataset/dataset/simulation_dataset.py index ebb35477..7ac44db1 100644 --- a/spatio_temporal_dataset/dataset/simulation_dataset.py +++ b/spatio_temporal_dataset/dataset/simulation_dataset.py @@ -1,5 +1,5 @@ -from extreme_estimator.extreme_models.margin_model.abstract_margin_model import AbstractMarginModel -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel +from extreme_fit.model.margin_model.abstract_margin_model import AbstractMarginModel +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatio_temporal_coordinates.abstract_spatio_temporal_coordinates import \ AbstractSpatioTemporalCoordinates diff --git a/spatio_temporal_dataset/spatio_temporal_observations/annual_maxima_observations.py b/spatio_temporal_dataset/spatio_temporal_observations/annual_maxima_observations.py index 162cdaa4..7c21358e 100644 --- a/spatio_temporal_dataset/spatio_temporal_observations/annual_maxima_observations.py +++ b/spatio_temporal_dataset/spatio_temporal_observations/annual_maxima_observations.py @@ -1,7 +1,7 @@ import pandas as pd -from extreme_estimator.extreme_models.margin_model.abstract_margin_model import AbstractMarginModel -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel +from extreme_fit.model.margin_model.abstract_margin_model import AbstractMarginModel +from extreme_fit.model.max_stable_model.abstract_max_stable_model import AbstractMaxStableModel from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatial_coordinates.abstract_spatial_coordinates import \ AbstractSpatialCoordinates diff --git a/test/test_experiment/test_hypercube.py b/test/test_experiment/test_hypercube.py index b80a08b2..ad3b15e6 100644 --- a/test/test_experiment/test_hypercube.py +++ b/test/test_experiment/test_hypercube.py @@ -13,7 +13,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.study_visualizer import \ StudyVisualizer from experiment.trend_analysis.univariate_test.gev_trend_test_one_parameter import GevLocationTrendTest -from extreme_estimator.extreme_models.utils import set_seed_for_test +from extreme_fit.model.utils import set_seed_for_test class TestHypercube(unittest.TestCase): diff --git a/test/test_extreme_estimator/test_estimator/test_margin_estimators.py b/test/test_extreme_estimator/test_estimator/test_margin_estimators.py index 7d6ac6a6..36cf25bc 100644 --- a/test/test_extreme_estimator/test_estimator/test_margin_estimators.py +++ b/test/test_extreme_estimator/test_estimator/test_margin_estimators.py @@ -1,6 +1,6 @@ import unittest -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator from spatio_temporal_dataset.dataset.simulation_dataset import MarginDataset from test.test_utils import load_smooth_margin_models, load_test_1D_and_2D_spatial_coordinates, \ load_test_spatiotemporal_coordinates diff --git a/test/test_extreme_estimator/test_estimator/test_max_stable_estimators.py b/test/test_extreme_estimator/test_estimator/test_max_stable_estimators.py index 8ba17afc..0f632674 100644 --- a/test/test_extreme_estimator/test_estimator/test_max_stable_estimators.py +++ b/test/test_extreme_estimator/test_estimator/test_max_stable_estimators.py @@ -1,6 +1,6 @@ import unittest -from extreme_estimator.extreme_models.utils import SafeRunException +from extreme_fit.model.utils import SafeRunException from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \ BetweenZeroAndOneNormalization from spatio_temporal_dataset.dataset.simulation_dataset import MaxStableDataset diff --git a/test/test_extreme_estimator/test_extreme_models/test_margin_function.py b/test/test_extreme_estimator/test_extreme_models/test_margin_function.py index 1d1fd8ea..6f9e2b0b 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_margin_function.py +++ b/test/test_extreme_estimator/test_extreme_models/test_margin_function.py @@ -2,10 +2,10 @@ import unittest import numpy as np -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel -from extreme_estimator.extreme_models.margin_model.margin_function.abstract_margin_function import \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel +from extreme_fit.model.margin_model.margin_function.abstract_margin_function import \ AbstractMarginFunction -from extreme_estimator.extreme_models.margin_model.margin_function.linear_margin_function import LinearMarginFunction +from extreme_fit.model.margin_model.margin_function.linear_margin_function import LinearMarginFunction from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_2D import LinSpaceSpatial2DCoordinates from test.test_utils import load_test_spatiotemporal_coordinates diff --git a/test/test_extreme_estimator/test_extreme_models/test_margin_model.py b/test/test_extreme_estimator/test_extreme_models/test_margin_model.py index e146af2c..5bae40a6 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_margin_model.py +++ b/test/test_extreme_estimator/test_extreme_models/test_margin_model.py @@ -1,8 +1,8 @@ import unittest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel -from extreme_estimator.extreme_models.margin_model.spline_margin_model import Degree1SplineMarginModel -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel +from extreme_fit.model.margin_model.spline_margin_model import Degree1SplineMarginModel +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_1D import LinSpaceSpatialCoordinates from spatio_temporal_dataset.coordinates.spatial_coordinates.coordinates_2D import LinSpaceSpatial2DCoordinates from test.test_utils import load_test_spatiotemporal_coordinates diff --git a/test/test_extreme_estimator/test_extreme_models/test_margin_temporal.py b/test/test_extreme_estimator/test_extreme_models/test_margin_temporal.py index 7e2c5f6e..fdf159f2 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_margin_temporal.py +++ b/test/test_extreme_estimator/test_extreme_models/test_margin_temporal.py @@ -2,10 +2,10 @@ import unittest import numpy as np -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ LinearStationaryMarginModel -from extreme_estimator.extreme_models.utils import set_seed_for_test +from extreme_fit.model.utils import set_seed_for_test from spatio_temporal_dataset.dataset.simulation_dataset import MarginDataset from test.test_utils import load_test_spatiotemporal_coordinates diff --git a/test/test_extreme_estimator/test_extreme_models/test_margin_temporal_transformed.py b/test/test_extreme_estimator/test_extreme_models/test_margin_temporal_transformed.py index 975c7f28..f4a42a81 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_margin_temporal_transformed.py +++ b/test/test_extreme_estimator/test_extreme_models/test_margin_temporal_transformed.py @@ -2,10 +2,10 @@ import unittest import numpy as np -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ LinearStationaryMarginModel -from extreme_estimator.extreme_models.utils import set_seed_for_test +from extreme_fit.model.utils import set_seed_for_test from spatio_temporal_dataset.coordinates.spatio_temporal_coordinates.abstract_spatio_temporal_coordinates import \ AbstractSpatioTemporalCoordinates from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \ diff --git a/test/test_extreme_estimator/test_extreme_models/test_max_stable_temporal.py b/test/test_extreme_estimator/test_extreme_models/test_max_stable_temporal.py index 07570582..8a6a6b3b 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_max_stable_temporal.py +++ b/test/test_extreme_estimator/test_extreme_models/test_max_stable_temporal.py @@ -2,11 +2,11 @@ import unittest import numpy as np -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel, \ LinearStationaryMarginModel -from extreme_estimator.extreme_models.utils import set_seed_for_test +from extreme_fit.model.utils import set_seed_for_test from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset from test.test_utils import load_test_spatiotemporal_coordinates, load_test_max_stable_models diff --git a/test/test_extreme_estimator/test_extreme_models/test_safe_run_r_estimator.py b/test/test_extreme_estimator/test_extreme_models/test_safe_run_r_estimator.py index 5a9e4b48..7bf1ef17 100644 --- a/test/test_extreme_estimator/test_extreme_models/test_safe_run_r_estimator.py +++ b/test/test_extreme_estimator/test_extreme_models/test_safe_run_r_estimator.py @@ -1,7 +1,7 @@ import numpy as np import unittest -from extreme_estimator.extreme_models.utils import safe_run_r_estimator, WarningMaximumAbsoluteValueTooHigh +from extreme_fit.model.utils import safe_run_r_estimator, WarningMaximumAbsoluteValueTooHigh def function(data=None, control=None): diff --git a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_params.py b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_params.py index 0e7d8903..41e9d2f2 100644 --- a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_params.py +++ b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_params.py @@ -5,7 +5,7 @@ from mpmath import euler import numpy as np from scipy.special.cython_special import gamma -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gev_params import GevParams class TestGevParams(unittest.TestCase): diff --git a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py index 3b7113fa..097b17b2 100644 --- a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py +++ b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py @@ -3,10 +3,10 @@ import unittest import numpy as np import pandas as pd -from extreme_estimator.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryStationModel, \ +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryStationModel, \ NonStationaryLocationStationModel -from extreme_estimator.extreme_models.utils import r, set_seed_r +from extreme_fit.model.utils import r, set_seed_r from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_coordinates import \ AbstractTemporalCoordinates diff --git a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal_bayesian.py b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal_bayesian.py new file mode 100644 index 00000000..5f5ba22c --- /dev/null +++ b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal_bayesian.py @@ -0,0 +1,92 @@ +import unittest + +import numpy as np +import pandas as pd + +from extreme_fit.estimator.margin_estimator.abstract_margin_estimator import LinearMarginEstimator +from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ + AbstractTemporalLinearMarginModel +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import StationaryStationModel, \ + NonStationaryLocationStationModel +from extreme_fit.model.utils import r, set_seed_r +from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates +from spatio_temporal_dataset.coordinates.temporal_coordinates.abstract_temporal_coordinates import \ + AbstractTemporalCoordinates +from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset +from spatio_temporal_dataset.spatio_temporal_observations.abstract_spatio_temporal_observations import \ + AbstractSpatioTemporalObservations +from test.test_utils import load_non_stationary_temporal_margin_models + + +# class TestGevTemporalBayesian(unittest.TestCase): +# +# def setUp(self) -> None: +# set_seed_r() +# r(""" +# N <- 50 +# loc = 0; scale = 1; shape <- 1 +# x_gev <- rgev(N, loc = loc, scale = scale, shape = shape) +# start_loc = 0; start_scale = 1; start_shape = 1 +# """) +# # Compute the stationary temporal margin with isMev +# self.start_year = 0 +# df = pd.DataFrame({AbstractCoordinates.COORDINATE_T: range(self.start_year, self.start_year + 50)}) +# self.coordinates = AbstractTemporalCoordinates.from_df(df) +# df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) +# observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) +# self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) +# self.fit_method = AbstractTemporalLinearMarginModel.EXTREMES_FEVD_BAYESIAN_FIT_METHOD_STR +# +# def test_gev_temporal_margin_fit_stationary(self): +# # Create estimator +# margin_model = StationaryStationModel(self.coordinates, fit_method=self.fit_method) +# estimator = LinearMarginEstimator(self.dataset, margin_model) +# estimator.fit() +# ref = {'loc': 0.0219, 'scale': 1.0347, 'shape': 0.8295} +# for year in range(1, 3): +# mle_params_estimated = estimator.margin_function_fitted.get_gev_params(np.array([year])).to_dict() +# for key in ref.keys(): +# self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) + + # def test_gev_temporal_margin_fit_nonstationary(self): + # # Create estimator + # margin_models = load_non_stationary_temporal_margin_models(self.coordinates) + # for margin_model in margin_models: + # # margin_model = NonStationaryLocationStationModel(self.coordinates) + # estimator = LinearMarginEstimator(self.dataset, margin_model) + # estimator.fit() + # # Checks that parameters returned are indeed different + # mle_params_estimated_year1 = estimator.margin_function_fitted.get_gev_params(np.array([1])).to_dict() + # mle_params_estimated_year3 = estimator.margin_function_fitted.get_gev_params(np.array([3])).to_dict() + # self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) + # + # def test_gev_temporal_margin_fit_nonstationary_with_start_point(self): + # # Create estimator + # estimator = self.fit_non_stationary_estimator(starting_point=3) + # self.assertNotEqual(estimator.margin_function_fitted.mu1_temporal_trend, 0.0) + # # Checks starting point parameter are well passed + # self.assertEqual(3, estimator.margin_function_fitted.starting_point) + # # Checks that parameters returned are indeed different + # mle_params_estimated_year1 = estimator.margin_function_fitted.get_gev_params(np.array([1])).to_dict() + # mle_params_estimated_year3 = estimator.margin_function_fitted.get_gev_params(np.array([3])).to_dict() + # self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year3) + # mle_params_estimated_year5 = estimator.margin_function_fitted.get_gev_params(np.array([5])).to_dict() + # self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year3) + # + # def fit_non_stationary_estimator(self, starting_point): + # margin_model = NonStationaryLocationStationModel(self.coordinates, starting_point=starting_point + self.start_year) + # estimator = LinearMarginEstimator(self.dataset, margin_model) + # estimator.fit() + # return estimator + # + # def test_two_different_starting_points(self): + # # Create two different estimators + # estimator1 = self.fit_non_stationary_estimator(starting_point=3) + # estimator2 = self.fit_non_stationary_estimator(starting_point=28) + # mu1_estimator1 = estimator1.margin_function_fitted.mu1_temporal_trend + # mu1_estimator2 = estimator2.margin_function_fitted.mu1_temporal_trend + # self.assertNotEqual(mu1_estimator1, mu1_estimator2) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gevmle_fit.py b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gevmle_fit.py index 15d003e4..184be222 100644 --- a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gevmle_fit.py +++ b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gevmle_fit.py @@ -2,10 +2,10 @@ import unittest import numpy as np -from extreme_estimator.extreme_models.utils import r, set_seed_r -from extreme_estimator.margin_fits.gev.gev_params import GevParams -from extreme_estimator.margin_fits.gev.gevmle_fit import GevMleFit -from extreme_estimator.margin_fits.gev.ismev_gev_fit import IsmevGevFit +from extreme_fit.model.utils import r, set_seed_r +from extreme_fit.distribution.gev.gev_params import GevParams +from extreme_fit.distribution.gev.gevmle_fit import GevMleFit +from extreme_fit.distribution.gev.ismev_gev_fit import IsmevGevFit class TestGevMleFit(unittest.TestCase): diff --git a/test/test_spatio_temporal_dataset/test_coordinates.py b/test/test_spatio_temporal_dataset/test_coordinates.py index 934269e8..43b12db5 100644 --- a/test/test_spatio_temporal_dataset/test_coordinates.py +++ b/test/test_spatio_temporal_dataset/test_coordinates.py @@ -3,7 +3,7 @@ import numpy as np import pandas as pd from collections import Counter, OrderedDict -from extreme_estimator.extreme_models.utils import set_seed_for_test +from extreme_fit.model.utils import set_seed_for_test from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatio_temporal_coordinates.abstract_spatio_temporal_coordinates import \ AbstractSpatioTemporalCoordinates diff --git a/test/test_spatio_temporal_dataset/test_dataset.py b/test/test_spatio_temporal_dataset/test_dataset.py index bedad477..3e5a6d3a 100644 --- a/test/test_spatio_temporal_dataset/test_dataset.py +++ b/test/test_spatio_temporal_dataset/test_dataset.py @@ -3,8 +3,8 @@ from itertools import product import numpy as np -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel -from extreme_estimator.extreme_models.utils import set_seed_for_test, SafeRunException +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearNonStationaryLocationMarginModel +from extreme_fit.model.utils import set_seed_for_test, SafeRunException from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \ BetweenZeroAndOneNormalization diff --git a/test/test_spatio_temporal_dataset/test_slicer.py b/test/test_spatio_temporal_dataset/test_slicer.py index 3d24a110..0af73b92 100644 --- a/test/test_spatio_temporal_dataset/test_slicer.py +++ b/test/test_spatio_temporal_dataset/test_slicer.py @@ -2,8 +2,8 @@ from typing import List import unittest -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel +from extreme_fit.model.max_stable_model.max_stable_models import Smith from spatio_temporal_dataset.dataset.abstract_dataset import AbstractDataset from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset from spatio_temporal_dataset.slicer.split import ALL_SPLITS_EXCEPT_ALL, Split diff --git a/test/test_unitary/test_fitmaxstab/test_fitmaxstab_with_margin.py b/test/test_unitary/test_fitmaxstab/test_fitmaxstab_with_margin.py index c4c16052..a1ce0df0 100644 --- a/test/test_unitary/test_fitmaxstab/test_fitmaxstab_with_margin.py +++ b/test/test_unitary/test_fitmaxstab/test_fitmaxstab_with_margin.py @@ -1,12 +1,12 @@ import unittest -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel, \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel, \ LinearMarginModelExample -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import CovarianceFunction -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Schlather -from extreme_estimator.extreme_models.utils import r +from extreme_fit.model.max_stable_model.abstract_max_stable_model import CovarianceFunction +from extreme_fit.model.max_stable_model.max_stable_models import Schlather +from extreme_fit.model.utils import r from test.test_unitary.test_rmaxstab.test_rmaxstab_with_margin import TestRMaxStabWithMarginConstant from test.test_unitary.test_unitary_abstract import TestUnitaryAbstract diff --git a/test/test_unitary/test_fitmaxstab/test_fitmaxstab_without_margin.py b/test/test_unitary/test_fitmaxstab/test_fitmaxstab_without_margin.py index bfd48eb4..d1877adb 100644 --- a/test/test_unitary/test_fitmaxstab/test_fitmaxstab_without_margin.py +++ b/test/test_unitary/test_fitmaxstab/test_fitmaxstab_without_margin.py @@ -1,9 +1,9 @@ import unittest -from extreme_estimator.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import CovarianceFunction -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Schlather -from extreme_estimator.extreme_models.utils import r +from extreme_fit.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator +from extreme_fit.model.max_stable_model.abstract_max_stable_model import CovarianceFunction +from extreme_fit.model.max_stable_model.max_stable_models import Schlather +from extreme_fit.model.utils import r from spatio_temporal_dataset.dataset.simulation_dataset import MaxStableDataset from test.test_unitary.test_rmaxstab.test_rmaxstab_without_margin import TestRMaxStab from test.test_unitary.test_unitary_abstract import TestUnitaryAbstract diff --git a/test/test_unitary/test_rmaxstab/test_rmaxstab_with_margin.py b/test/test_unitary/test_rmaxstab/test_rmaxstab_with_margin.py index 0c6869b9..c1570bd6 100644 --- a/test/test_unitary/test_rmaxstab/test_rmaxstab_with_margin.py +++ b/test/test_unitary/test_rmaxstab/test_rmaxstab_with_margin.py @@ -2,10 +2,10 @@ import unittest import numpy as np -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel, \ +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import ConstantMarginModel, \ LinearAllParametersAllDimsMarginModel -from extreme_estimator.extreme_models.utils import r -from extreme_estimator.margin_fits.gev.gev_params import GevParams +from extreme_fit.model.utils import r +from extreme_fit.distribution.gev.gev_params import GevParams from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset from test.test_unitary.test_rmaxstab.test_rmaxstab_without_margin import TestRMaxStab from test.test_unitary.test_unitary_abstract import TestUnitaryAbstract diff --git a/test/test_unitary/test_rmaxstab/test_rmaxstab_without_margin.py b/test/test_unitary/test_rmaxstab/test_rmaxstab_without_margin.py index 8270299b..42bc01e2 100644 --- a/test/test_unitary/test_rmaxstab/test_rmaxstab_without_margin.py +++ b/test/test_unitary/test_rmaxstab/test_rmaxstab_without_margin.py @@ -3,9 +3,9 @@ import unittest import numpy as np import pandas as pd -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import CovarianceFunction -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Schlather -from extreme_estimator.extreme_models.utils import r +from extreme_fit.model.max_stable_model.abstract_max_stable_model import CovarianceFunction +from extreme_fit.model.max_stable_model.max_stable_models import Schlather +from extreme_fit.model.utils import r from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.spatial_coordinates.abstract_spatial_coordinates import \ AbstractSpatialCoordinates diff --git a/test/test_unitary/test_unitary_abstract.py b/test/test_unitary/test_unitary_abstract.py index acf305e2..e988bcd4 100644 --- a/test/test_unitary/test_unitary_abstract.py +++ b/test/test_unitary/test_unitary_abstract.py @@ -1,6 +1,6 @@ import unittest -from extreme_estimator.extreme_models.utils import set_seed_r, r +from extreme_fit.model.utils import set_seed_r, r class TestUnitaryAbstract(unittest.TestCase): diff --git a/test/test_utils.py b/test/test_utils.py index 09b329ab..e9536f80 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -3,16 +3,16 @@ from typing import List from experiment.meteo_france_data.scm_models_data.abstract_study import AbstractStudy from experiment.meteo_france_data.scm_models_data.crocus.crocus import Crocus, CrocusSweTotal, CrocusDepth -from extreme_estimator.estimator.full_estimator.abstract_full_estimator import SmoothMarginalsThenUnitaryMsp, \ +from extreme_fit.estimator.full_estimator.abstract_full_estimator import SmoothMarginalsThenUnitaryMsp, \ FullEstimatorInASingleStepWithSmoothMargin -from extreme_estimator.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator -from extreme_estimator.extreme_models.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ +from extreme_fit.estimator.max_stable_estimator.abstract_max_stable_estimator import MaxStableEstimator +from extreme_fit.model.margin_model.linear_margin_model.linear_margin_model import LinearAllParametersAllDimsMarginModel, \ ConstantMarginModel -from extreme_estimator.extreme_models.margin_model.linear_margin_model.temporal_linear_margin_models import \ +from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_models import \ NonStationaryLocationStationModel, NonStationaryScaleStationModel, NonStationaryShapeStationModel -from extreme_estimator.extreme_models.max_stable_model.abstract_max_stable_model import \ +from extreme_fit.model.max_stable_model.abstract_max_stable_model import \ AbstractMaxStableModelWithCovarianceFunction, CovarianceFunction -from extreme_estimator.extreme_models.max_stable_model.max_stable_models import Smith, BrownResnick, Schlather, \ +from extreme_fit.model.max_stable_model.max_stable_models import Smith, BrownResnick, Schlather, \ Geometric, ExtremalT, ISchlather from experiment.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall, Safran, SafranRainfall, \ SafranTemperature, SafranTotalPrecip diff --git a/thesis_report/gev_plot.py b/thesis_report/gev_plot.py index 284ae3f1..144ac914 100644 --- a/thesis_report/gev_plot.py +++ b/thesis_report/gev_plot.py @@ -1,7 +1,7 @@ import numpy as np import matplotlib.pyplot as plt -from extreme_estimator.extreme_models.utils import r +from extreme_fit.model.utils import r def gev_plot(): diff --git a/thesis_report/simulation_for_quantile_gap.py b/thesis_report/simulation_for_quantile_gap.py index 981df952..816488bb 100644 --- a/thesis_report/simulation_for_quantile_gap.py +++ b/thesis_report/simulation_for_quantile_gap.py @@ -4,7 +4,7 @@ import numpy as np import matplotlib.pyplot as plt -from extreme_estimator.extreme_models.utils import r, set_seed_r +from extreme_fit.model.utils import r, set_seed_r def convergence_quantile_function(zoom=False): diff --git a/thesis_report/slides.py b/thesis_report/slides.py index 8e4852de..f6aed506 100644 --- a/thesis_report/slides.py +++ b/thesis_report/slides.py @@ -1,7 +1,7 @@ import numpy as np import matplotlib.pyplot as plt -from extreme_estimator.extreme_models.utils import r, set_seed_r +from extreme_fit.model.utils import r, set_seed_r def snowfall_plot(flip=False): -- GitLab