Commit 95efb390 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting] add quadratic model for gumbel/gev and location/scale. modify...

[contrasting] add quadratic model for gumbel/gev and location/scale. modify code for the name of the models
parent e9409ea3
No related merge requests found
Showing with 146 additions and 28 deletions
+146 -28
...@@ -29,8 +29,9 @@ class PolynomialMarginModel(AbstractTemporalLinearMarginModel): ...@@ -29,8 +29,9 @@ class PolynomialMarginModel(AbstractTemporalLinearMarginModel):
return super().margin_function return super().margin_function
def load_margin_function(self, param_name_to_list_dim_and_degree=None): def load_margin_function(self, param_name_to_list_dim_and_degree=None):
param_name_to_polynomial_all_coef = self.param_name_to_polynomial_all_coef(param_name_to_list_dim_and_degree=param_name_to_list_dim_and_degree, param_name_to_polynomial_all_coef = self.param_name_to_polynomial_all_coef(
param_name_and_dim_and_degree_to_default_coef=self.default_params) param_name_to_list_dim_and_degree=param_name_to_list_dim_and_degree,
param_name_and_dim_and_degree_to_default_coef=self.default_params)
return PolynomialMarginFunction(coordinates=self.coordinates, return PolynomialMarginFunction(coordinates=self.coordinates,
param_name_to_coef=param_name_to_polynomial_all_coef, param_name_to_coef=param_name_to_polynomial_all_coef,
param_name_to_dim_and_max_degree=param_name_to_list_dim_and_degree, param_name_to_dim_and_max_degree=param_name_to_list_dim_and_degree,
...@@ -84,6 +85,24 @@ class NonStationaryQuadraticLocationModel(PolynomialMarginModel): ...@@ -84,6 +85,24 @@ class NonStationaryQuadraticLocationModel(PolynomialMarginModel):
def load_margin_function(self, param_name_to_dims=None): def load_margin_function(self, param_name_to_dims=None):
return super().load_margin_function({GevParams.LOC: [(self.coordinates.idx_temporal_coordinates, 2)]}) return super().load_margin_function({GevParams.LOC: [(self.coordinates.idx_temporal_coordinates, 2)]})
@property
def mul(self):
return 2
class NonStationaryQuadraticScaleModel(PolynomialMarginModel):
def load_margin_function(self, param_name_to_dims=None):
return super().load_margin_function({GevParams.SCALE: [(self.coordinates.idx_temporal_coordinates, 2)]})
@property
def sigl(self):
return 2
class NonStationaryQuadraticLocationGumbelModel(GumbelTemporalModel, NonStationaryQuadraticLocationModel):
pass
class NonStationaryLocationGumbelModel(GumbelTemporalModel, NonStationaryQuadraticLocationModel): class NonStationaryQuadraticScaleGumbelModel(GumbelTemporalModel, NonStationaryQuadraticScaleModel):
pass pass
...@@ -17,6 +17,7 @@ from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_m ...@@ -17,6 +17,7 @@ from extreme_fit.model.margin_model.linear_margin_model.temporal_linear_margin_m
StationaryTemporalModel, GumbelTemporalModel StationaryTemporalModel, GumbelTemporalModel
from extreme_fit.model.margin_model.utils import \ from extreme_fit.model.margin_model.utils import \
MarginFitMethod MarginFitMethod
from extreme_fit.model.utils import get_null
from root_utils import classproperty from root_utils import classproperty
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
from spatio_temporal_dataset.utils import load_temporal_coordinates_and_dataset from spatio_temporal_dataset.utils import load_temporal_coordinates_and_dataset
...@@ -84,23 +85,15 @@ class AbstractGevTrendTest(object): ...@@ -84,23 +85,15 @@ class AbstractGevTrendTest(object):
family = 'Gum' family = 'Gum'
else: else:
family = 'Gev' family = 'Gev'
def get_str_number(param_l):
nb = 0 if param_l == get_null() else param_l
return str(nb)
if self.unconstrained_estimator.margin_model.mul == 1: family += get_str_number(self.unconstrained_estimator.margin_model.mul)
family += '1' family += get_str_number(self.unconstrained_estimator.margin_model.sigl)
else:
family += '0'
if self.unconstrained_estimator.margin_model.sigl == 1:
family += '1'
else:
family += '0'
if family.startswith('Gev'): if family.startswith('Gev'):
if self.unconstrained_estimator.margin_model.shl == 1: family += get_str_number(self.unconstrained_estimator.margin_model.shl)
family += '1'
else:
family += '0'
return family return family
@property @property
......
from extreme_fit.model.margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel, \
NonStationaryQuadraticScaleModel
from extreme_fit.model.margin_model.utils import \ from extreme_fit.model.margin_model.utils import \
MarginFitMethod MarginFitMethod
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
...@@ -65,3 +67,33 @@ class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters): ...@@ -65,3 +67,33 @@ class GevLocationAndScaleTrendTestAgainstGumbel(GevTrendTestThreeParameters):
@classproperty @classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int: def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 5 return 5
class GevLocationQuadraticTrendTestAgainstGumbel(GevTrendTestThreeParameters):
def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE,
fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticLocationModel,
constrained_model_class=GumbelTemporalModel,
quantile_level=quantile_level,
fit_method=fit_method)
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 5
class GevScaleQuadraticTrendTestAgainstGumbel(GevTrendTestThreeParameters):
def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE,
fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticScaleModel,
constrained_model_class=GumbelTemporalModel,
quantile_level=quantile_level,
fit_method=fit_method)
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 5
\ No newline at end of file
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_fit.model.margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel, \
NonStationaryQuadraticScaleModel
from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest
from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \ from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import \
GevLocationTrendTest, GevScaleTrendTest GevLocationTrendTest, GevScaleTrendTest
...@@ -45,6 +47,26 @@ class GevScaleAndShapeTrendTest(GevTrendTestTwoParametersAgainstGev): ...@@ -45,6 +47,26 @@ class GevScaleAndShapeTrendTest(GevTrendTestTwoParametersAgainstGev):
constrained_model_class=constrained_model_class, constrained_model_class=constrained_model_class,
quantile_level=quantile_level, quantile_level=quantile_level,
fit_method=fit_method) fit_method=fit_method)
class GevQuadraticLocationTrendTest(GevTrendTestTwoParametersAgainstGev):
def __init__(self, years, maxima, starting_year, constrained_model_class=StationaryTemporalModel,
quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticLocationModel,
constrained_model_class=constrained_model_class,
quantile_level=quantile_level,
fit_method=fit_method)
class GevQuadraticScaleTrendTest(GevTrendTestTwoParametersAgainstGev):
def __init__(self, years, maxima, starting_year, constrained_model_class=StationaryTemporalModel,
quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticScaleModel,
constrained_model_class=constrained_model_class,
quantile_level=quantile_level,
fit_method=fit_method)
class GevLocationAndScaleTrendTest(GevTrendTestTwoParametersAgainstGev): class GevLocationAndScaleTrendTest(GevTrendTestTwoParametersAgainstGev):
......
from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE from extreme_data.eurocode_data.utils import EUROCODE_QUANTILE
from extreme_fit.model.margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel, \
NonStationaryQuadraticLocationGumbelModel, NonStationaryQuadraticScaleGumbelModel
from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import \ from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import \
GevTrendTestTwoParameters GevTrendTestTwoParameters
from extreme_fit.distribution.gev.gev_params import GevParams from extreme_fit.distribution.gev.gev_params import GevParams
...@@ -41,3 +43,32 @@ class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters): ...@@ -41,3 +43,32 @@ class GumbelLocationAndScaleTrendTest(GevTrendTestTwoParameters):
@classproperty @classproperty
def marker(self): def marker(self):
return 'd' return 'd'
class GumbelLocationQuadraticTrendTest(GevTrendTestTwoParameters):
def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE,
fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticLocationGumbelModel,
constrained_model_class=GumbelTemporalModel,
quantile_level=quantile_level,
fit_method=fit_method)
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4
class GumbelScaleQuadraticTrendTest(GevTrendTestTwoParameters):
def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE,
fit_method=MarginFitMethod.extremes_fevd_mle):
super().__init__(years, maxima, starting_year,
unconstrained_model_class=NonStationaryQuadraticScaleGumbelModel,
constrained_model_class=GumbelTemporalModel,
quantile_level=quantile_level,
fit_method=fit_method)
@classproperty
def total_number_of_parameters_for_unconstrained_model(cls) -> int:
return 4
...@@ -9,12 +9,14 @@ from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import ...@@ -9,12 +9,14 @@ from extreme_trend.trend_test_one_parameter.gev_trend_test_one_parameter import
from extreme_trend.trend_test_one_parameter.gumbel_trend_test_one_parameter import \ from extreme_trend.trend_test_one_parameter.gumbel_trend_test_one_parameter import \
GumbelVersusGumbel, GumbelLocationTrendTest, GumbelScaleTrendTest, GevStationaryVersusGumbel GumbelVersusGumbel, GumbelLocationTrendTest, GumbelScaleTrendTest, GevStationaryVersusGumbel
from extreme_trend.trend_test_three_parameters.gev_trend_test_three_parameters import \ from extreme_trend.trend_test_three_parameters.gev_trend_test_three_parameters import \
GevLocationAndScaleTrendTestAgainstGumbel, GevLocationAndScaleAndShapeTrendTest GevLocationAndScaleTrendTestAgainstGumbel, GevLocationAndScaleAndShapeTrendTest, \
GevLocationQuadraticTrendTestAgainstGumbel, \
GevScaleQuadraticTrendTestAgainstGumbel
from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import \ from extreme_trend.trend_test_two_parameters.gev_trend_test_two_parameters import \
GevLocationAgainstGumbel, GevScaleAgainstGumbel, GevLocationAndScaleTrendTest, GevScaleAndShapeTrendTest, \ GevLocationAgainstGumbel, GevScaleAgainstGumbel, GevLocationAndScaleTrendTest, GevScaleAndShapeTrendTest, \
GevLocationAndShapeTrendTest GevLocationAndShapeTrendTest, GevQuadraticLocationTrendTest, GevQuadraticScaleTrendTest
from extreme_trend.trend_test_two_parameters.gumbel_test_two_parameters import \ from extreme_trend.trend_test_two_parameters.gumbel_test_two_parameters import \
GumbelLocationAndScaleTrendTest GumbelLocationAndScaleTrendTest, GumbelLocationQuadraticTrendTest, GumbelScaleQuadraticTrendTest
paper_altitudes = ALL_ALTITUDES_WITHOUT_NAN paper_altitudes = ALL_ALTITUDES_WITHOUT_NAN
paper_study_classes = [CrocusSnowLoadTotal, CrocusSnowLoadEurocode, CrocusSnowLoad3Days][:2] paper_study_classes = [CrocusSnowLoadTotal, CrocusSnowLoadEurocode, CrocusSnowLoad3Days][:2]
...@@ -33,7 +35,10 @@ NON_STATIONARY_TREND_TEST_PAPER_2 = [ ...@@ -33,7 +35,10 @@ NON_STATIONARY_TREND_TEST_PAPER_2 = [
# GEV models with constant shape # GEV models with constant shape
GevVersusGev, GevLocationTrendTest, GevScaleTrendTest, GevLocationAndScaleTrendTest, GevVersusGev, GevLocationTrendTest, GevScaleTrendTest, GevLocationAndScaleTrendTest,
# GEV models with linear shape # GEV models with linear shape
GevShapeTrendTest, GevLocationAndShapeTrendTest, GevScaleAndShapeTrendTest, GevLocationAndScaleAndShapeTrendTest GevShapeTrendTest, GevLocationAndShapeTrendTest, GevScaleAndShapeTrendTest, GevLocationAndScaleAndShapeTrendTest,
# Quadratic model for the Gev/Gumbel and for the location/scale
GevQuadraticLocationTrendTest, GevQuadraticScaleTrendTest, GumbelLocationQuadraticTrendTest,
GumbelScaleQuadraticTrendTest,
] ]
......
...@@ -4,7 +4,8 @@ import numpy as np ...@@ -4,7 +4,8 @@ import numpy as np
import pandas as pd import pandas as pd
from extreme_fit.distribution.gev.gev_params import GevParams from extreme_fit.distribution.gev.gev_params import GevParams
from extreme_fit.model.margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel from extreme_fit.model.margin_model.polynomial_margin_model import NonStationaryQuadraticLocationModel, \
NonStationaryQuadraticScaleModel, NonStationaryQuadraticLocationGumbelModel, NonStationaryQuadraticScaleGumbelModel
from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator from extreme_trend.abstract_gev_trend_test import fitted_linear_margin_estimator
from extreme_fit.model.margin_model.utils import \ from extreme_fit.model.margin_model.utils import \
MarginFitMethod MarginFitMethod
...@@ -38,9 +39,9 @@ class TestGevTemporalQuadraticExtremesMle(unittest.TestCase): ...@@ -38,9 +39,9 @@ class TestGevTemporalQuadraticExtremesMle(unittest.TestCase):
self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates)
self.fit_method = MarginFitMethod.extremes_fevd_mle self.fit_method = MarginFitMethod.extremes_fevd_mle
def test_gev_temporal_margin_fit_non_stationary_quadratic_location(self): def function_test_gev_temporal_margin_fit_non_stationary_quadratic(self, model_class, quadratic_param):
# Create estimator # Create estimator
estimator = fitted_linear_margin_estimator(NonStationaryQuadraticLocationModel, estimator = fitted_linear_margin_estimator(model_class,
self.coordinates, self.dataset, self.coordinates, self.dataset,
starting_year=0, starting_year=0,
fit_method=self.fit_method) fit_method=self.fit_method)
...@@ -51,15 +52,30 @@ class TestGevTemporalQuadraticExtremesMle(unittest.TestCase): ...@@ -51,15 +52,30 @@ class TestGevTemporalQuadraticExtremesMle(unittest.TestCase):
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
self.assertNotEqual(mle_params_estimated_year3, mle_params_estimated_year5) self.assertNotEqual(mle_params_estimated_year3, mle_params_estimated_year5)
# Assert the relationship for the location is indeed quadratic # Assert the relationship for the location is indeed quadratic
location_gev_params = GevParams.LOC diff1 = mle_params_estimated_year1[quadratic_param] - mle_params_estimated_year3[quadratic_param]
diff1 = mle_params_estimated_year1[location_gev_params] - mle_params_estimated_year3[location_gev_params] diff2 = mle_params_estimated_year3[quadratic_param] - mle_params_estimated_year5[quadratic_param]
diff2 = mle_params_estimated_year3[location_gev_params] - mle_params_estimated_year5[location_gev_params]
self.assertNotAlmostEqual(diff1, diff2) self.assertNotAlmostEqual(diff1, diff2)
# Assert that indicators are correctly computed # Assert that indicators are correctly computed
self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh()) self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh())
self.assertAlmostEqual(estimator.result_from_model_fit.aic, estimator.aic()) self.assertAlmostEqual(estimator.result_from_model_fit.aic, estimator.aic())
self.assertAlmostEqual(estimator.result_from_model_fit.bic, estimator.bic()) self.assertAlmostEqual(estimator.result_from_model_fit.bic, estimator.bic())
def test_gev_temporal_margin_fit_non_stationary_quadratic_location(self):
self.function_test_gev_temporal_margin_fit_non_stationary_quadratic(NonStationaryQuadraticLocationModel,
quadratic_param=GevParams.LOC)
def test_gev_temporal_margin_fit_non_stationary_quadratic_scale(self):
self.function_test_gev_temporal_margin_fit_non_stationary_quadratic(NonStationaryQuadraticScaleModel,
quadratic_param=GevParams.SCALE)
def test_gumbel_temporal_margin_fit_non_stationary_quadratic_location(self):
self.function_test_gev_temporal_margin_fit_non_stationary_quadratic(NonStationaryQuadraticLocationGumbelModel,
quadratic_param=GevParams.LOC)
def test_gumbel_temporal_margin_fit_non_stationary_quadratic_scale(self):
self.function_test_gev_temporal_margin_fit_non_stationary_quadratic(NonStationaryQuadraticScaleGumbelModel,
quadratic_param=GevParams.SCALE)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment