Commit 67bff11b authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[refactor] get_gev_params -> gev_params

parent 3f750c33
No related merge requests found
Showing with 70 additions and 70 deletions
+70 -70
...@@ -55,7 +55,7 @@ class LinearMarginEstimator(AbstractMarginEstimator): ...@@ -55,7 +55,7 @@ class LinearMarginEstimator(AbstractMarginEstimator):
assert len( assert len(
maximum) == 1, 'So far, only one observation for each coordinate, but code would be easy to change' maximum) == 1, 'So far, only one observation for each coordinate, but code would be easy to change'
maximum = maximum[0] maximum = maximum[0]
gev_params = self.function_from_fit.get_gev_params(coordinate, is_transformed=False) gev_params = self.function_from_fit.get_params(coordinate, is_transformed=False)
p = gev_params.density(maximum) p = gev_params.density(maximum)
nllh -= np.log(p) nllh -= np.log(p)
assert not np.isinf(nllh) assert not np.isinf(nllh)
......
...@@ -35,7 +35,7 @@ def fitted_stationary_gev(x_gev, fit_method=MarginFitMethod.is_mev_gev_fit, mode ...@@ -35,7 +35,7 @@ def fitted_stationary_gev(x_gev, fit_method=MarginFitMethod.is_mev_gev_fit, mode
dataset = AbstractDataset(observations=observations, coordinates=coordinates) dataset = AbstractDataset(observations=observations, coordinates=coordinates)
estimator = fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_year, fit_method) estimator = fitted_linear_margin_estimator(model_class, coordinates, dataset, starting_year, fit_method)
first_coordinate = coordinates.coordinates_values()[0] first_coordinate = coordinates.coordinates_values()[0]
gev_param = estimator.function_from_fit.get_gev_params(first_coordinate) gev_param = estimator.function_from_fit.get_params(first_coordinate)
if not -0.5 < gev_param.shape < 0.5: if not -0.5 < gev_param.shape < 0.5:
warnings.warn('fitted shape parameter is outside physical bounds {}'.format(gev_param.shape)) warnings.warn('fitted shape parameter is outside physical bounds {}'.format(gev_param.shape))
return gev_param return gev_param
...@@ -59,5 +59,5 @@ class QuantileFunctionFromMarginFunction(AbstractQuantileFunction): ...@@ -59,5 +59,5 @@ class QuantileFunctionFromMarginFunction(AbstractQuantileFunction):
self.quantile = quantile self.quantile = quantile
def _get_quantile(self, coordinate: np.ndarray) -> float: def _get_quantile(self, coordinate: np.ndarray) -> float:
gev_params = self.margin_function.get_gev_params(coordinate) gev_params = self.margin_function.get_params(coordinate)
return gev_params.quantile(self.quantile) return gev_params.quantile(self.quantile)
...@@ -52,14 +52,14 @@ class AbstractMarginFunction(AbstractFunction): ...@@ -52,14 +52,14 @@ class AbstractMarginFunction(AbstractFunction):
def y(self): def y(self):
return self.coordinates.y_coordinates return self.coordinates.y_coordinates
def get_gev_params(self, coordinate: np.ndarray) -> GevParams: def get_params(self, coordinate: np.ndarray) -> GevParams:
"""Main method that maps each coordinate to its GEV parameters""" """Main method that maps each coordinate to its distribution parameters"""
raise NotImplementedError raise NotImplementedError
@property @property
def gev_value_name_to_serie(self) -> Dict[str, pd.Series]: def gev_value_name_to_serie(self) -> Dict[str, pd.Series]:
# Load the gev_params # Load the gev_params
gev_params = [self.get_gev_params(coordinate) for coordinate in self.coordinates.coordinates_values()] gev_params = [self.get_params(coordinate) for coordinate in self.coordinates.coordinates_values()]
# Load the dictionary of values (distribution parameters + the quantiles) # Load the dictionary of values (distribution parameters + the quantiles)
value_dicts = [gev_param.summary_dict for gev_param in gev_params] value_dicts = [gev_param.summary_dict for gev_param in gev_params]
gev_value_name_to_serie = {} gev_value_name_to_serie = {}
...@@ -154,7 +154,7 @@ class AbstractMarginFunction(AbstractFunction): ...@@ -154,7 +154,7 @@ class AbstractMarginFunction(AbstractFunction):
grid = [] grid = []
for i, xi in enumerate(linspace): for i, xi in enumerate(linspace):
gev_param = self.get_gev_params(np.array([xi])) gev_param = self.get_params(np.array([xi]))
assert not gev_param.has_undefined_parameters, 'This case needs to be handled during display,' \ assert not gev_param.has_undefined_parameters, 'This case needs to be handled during display,' \
'gev_parameter for xi={} is undefined'.format(xi) 'gev_parameter for xi={} is undefined'.format(xi)
grid.append(gev_param.summary_dict) grid.append(gev_param.summary_dict)
...@@ -215,7 +215,7 @@ class AbstractMarginFunction(AbstractFunction): ...@@ -215,7 +215,7 @@ class AbstractMarginFunction(AbstractFunction):
coordinate = [xi, yj] coordinate = [xi, yj]
if temporal_step is not None: if temporal_step is not None:
coordinate.append(temporal_step) coordinate.append(temporal_step)
grid.append(self.get_gev_params(np.array(coordinate)).summary_dict) grid.append(self.get_params(np.array(coordinate)).summary_dict)
grid = {value_name: np.array([g[value_name] for g in grid]).reshape( grid = {value_name: np.array([g[value_name] for g in grid]).reshape(
[self.VISUALIZATION_RESOLUTION, self.VISUALIZATION_RESOLUTION]) [self.VISUALIZATION_RESOLUTION, self.VISUALIZATION_RESOLUTION])
for value_name in GevParams.SUMMARY_NAMES} for value_name in GevParams.SUMMARY_NAMES}
......
...@@ -15,8 +15,8 @@ class CombinedMarginFunction(AbstractMarginFunction): ...@@ -15,8 +15,8 @@ class CombinedMarginFunction(AbstractMarginFunction):
super().__init__(coordinates) super().__init__(coordinates)
self.margin_functions = margin_functions # type: List[AbstractMarginFunction] self.margin_functions = margin_functions # type: List[AbstractMarginFunction]
def get_gev_params(self, coordinate: np.ndarray) -> GevParams: def get_params(self, coordinate: np.ndarray) -> GevParams:
gev_params_list = [margin_function.get_gev_params(coordinate) for margin_function in self.margin_functions] gev_params_list = [margin_function.get_params(coordinate) for margin_function in self.margin_functions]
mean_gev_params = np.mean(np.array([gev_param.to_array() for gev_param in gev_params_list]), axis=0) mean_gev_params = np.mean(np.array([gev_param.to_array() for gev_param in gev_params_list]), axis=0)
gev_param = self.params_class(*mean_gev_params) gev_param = self.params_class(*mean_gev_params)
return gev_param return gev_param
......
...@@ -19,7 +19,7 @@ class IndependentMarginFunction(AbstractMarginFunction): ...@@ -19,7 +19,7 @@ class IndependentMarginFunction(AbstractMarginFunction):
super().__init__(coordinates, params_class) super().__init__(coordinates, params_class)
self.gev_param_name_to_param_function = None # type: Union[None, Dict[str, AbstractParamFunction]] self.gev_param_name_to_param_function = None # type: Union[None, Dict[str, AbstractParamFunction]]
def get_gev_params(self, coordinate: np.ndarray, is_transformed: bool = True) -> GevParams: def get_params(self, coordinate: np.ndarray, is_transformed: bool = True) -> GevParams:
"""Each GEV parameter is computed independently through its corresponding param_function""" """Each GEV parameter is computed independently through its corresponding param_function"""
# Since all the coordinates are usually transformed by default # Since all the coordinates are usually transformed by default
# then we assume that the input coordinate are transformed by default # then we assume that the input coordinate are transformed by default
......
...@@ -66,7 +66,7 @@ class ParametricMarginFunction(IndependentMarginFunction): ...@@ -66,7 +66,7 @@ class ParametricMarginFunction(IndependentMarginFunction):
def transformed_starting_point(self): def transformed_starting_point(self):
return self.coordinates.temporal_coordinates.transformation.transform_array(np.array([self.starting_point])) return self.coordinates.temporal_coordinates.transformation.transform_array(np.array([self.starting_point]))
def get_gev_params(self, coordinate: np.ndarray, is_transformed: bool = True) -> GevParams: def get_params(self, coordinate: np.ndarray, is_transformed: bool = True) -> GevParams:
if self.starting_point is not None: if self.starting_point is not None:
starting_point = self.transformed_starting_point if is_transformed else self.starting_point starting_point = self.transformed_starting_point if is_transformed else self.starting_point
# Shift temporal coordinate to enable to model temporal trend with starting point # Shift temporal coordinate to enable to model temporal trend with starting point
...@@ -74,7 +74,7 @@ class ParametricMarginFunction(IndependentMarginFunction): ...@@ -74,7 +74,7 @@ class ParametricMarginFunction(IndependentMarginFunction):
assert 0 <= self.coordinates.idx_temporal_coordinates < len(coordinate) assert 0 <= self.coordinates.idx_temporal_coordinates < len(coordinate)
if coordinate[self.coordinates.idx_temporal_coordinates] < starting_point: if coordinate[self.coordinates.idx_temporal_coordinates] < starting_point:
coordinate[self.coordinates.idx_temporal_coordinates] = starting_point coordinate[self.coordinates.idx_temporal_coordinates] = starting_point
return super().get_gev_params(coordinate, is_transformed=is_transformed) return super().get_params(coordinate, is_transformed=is_transformed)
@classmethod @classmethod
def from_coef_dict(cls, coordinates: AbstractCoordinates, gev_param_name_to_dims: Dict[str, List[int]], def from_coef_dict(cls, coordinates: AbstractCoordinates, gev_param_name_to_dims: Dict[str, List[int]],
......
...@@ -50,7 +50,7 @@ class AbstractMarginModel(AbstractModel, ABC): ...@@ -50,7 +50,7 @@ class AbstractMarginModel(AbstractModel, ABC):
assert len(maxima) == len(coordinates_values) assert len(maxima) == len(coordinates_values)
converted_maxima = [] converted_maxima = []
for x, coordinate in zip(maxima, coordinates_values): for x, coordinate in zip(maxima, coordinates_values):
gev_params = margin_function.get_gev_params(coordinate) gev_params = margin_function.get_params(coordinate)
x_gev = convertion_r_function(x, **gev_params.to_dict()) x_gev = convertion_r_function(x, **gev_params.to_dict())
converted_maxima.append(x_gev) converted_maxima.append(x_gev)
return np.array(converted_maxima) return np.array(converted_maxima)
...@@ -75,7 +75,7 @@ class AbstractMarginModel(AbstractModel, ABC): ...@@ -75,7 +75,7 @@ class AbstractMarginModel(AbstractModel, ABC):
sample_r_function='rgev') -> np.ndarray: sample_r_function='rgev') -> np.ndarray:
maxima_gev = [] maxima_gev = []
for coordinate in coordinates_values: for coordinate in coordinates_values:
gev_params = self.margin_function_sample.get_gev_params(coordinate) gev_params = self.margin_function_sample.get_params(coordinate)
x_gev = r(sample_r_function)(nb_obs, **gev_params.to_dict()) x_gev = r(sample_r_function)(nb_obs, **gev_params.to_dict())
assert not np.isnan(x_gev).any(), 'params={} generated Nan values'.format(gev_params.__str__()) assert not np.isnan(x_gev).any(), 'params={} generated Nan values'.format(gev_params.__str__())
maxima_gev.append(x_gev) maxima_gev.append(x_gev)
......
...@@ -79,7 +79,7 @@ class ExtractEurocodeReturnLevelFromMyBayesianExtremes(AbstractExtractEurocodeRe ...@@ -79,7 +79,7 @@ class ExtractEurocodeReturnLevelFromMyBayesianExtremes(AbstractExtractEurocodeRe
@property @property
def gev_params_from_fit_for_temporal_covariate(self) -> List[GevParams]: def gev_params_from_fit_for_temporal_covariate(self) -> List[GevParams]:
return [margin_function.get_gev_params(coordinate=np.array([self.temporal_covariate]), is_transformed=False) return [margin_function.get_params(coordinate=np.array([self.temporal_covariate]), is_transformed=False)
for margin_function in self.margin_functions_from_fit] for margin_function in self.margin_functions_from_fit]
@cached_property @cached_property
......
...@@ -113,14 +113,14 @@ class AbstractGevTrendTest(object): ...@@ -113,14 +113,14 @@ class AbstractGevTrendTest(object):
@cached_property @cached_property
def unconstrained_estimator_gev_params(self) -> GevParams: def unconstrained_estimator_gev_params(self) -> GevParams:
# Constant parameters correspond to the gev params in 1958 # Constant parameters correspond to the gev params in 1958
return self.unconstrained_estimator.function_from_fit.get_gev_params(coordinate=np.array([1958]), return self.unconstrained_estimator.function_from_fit.get_params(coordinate=np.array([1958]),
is_transformed=False) is_transformed=False)
@cached_property @cached_property
def constrained_estimator_gev_params(self) -> GevParams: def constrained_estimator_gev_params(self) -> GevParams:
# Constant parameters correspond to any gev params # Constant parameters correspond to any gev params
return self.constrained_estimator.function_from_fit.get_gev_params(coordinate=np.array([1958]), return self.constrained_estimator.function_from_fit.get_params(coordinate=np.array([1958]),
is_transformed=False) is_transformed=False)
def time_derivative_times_years(self, nb_years): def time_derivative_times_years(self, nb_years):
# Compute the slope strength # Compute the slope strength
...@@ -139,7 +139,7 @@ class AbstractGevTrendTest(object): ...@@ -139,7 +139,7 @@ class AbstractGevTrendTest(object):
def relative_change_in_return_level(self, initial_year, final_year): def relative_change_in_return_level(self, initial_year, final_year):
return_level_values = [] return_level_values = []
for year in [initial_year, final_year]: for year in [initial_year, final_year]:
gev_params = self.unconstrained_estimator.function_from_fit.get_gev_params( gev_params = self.unconstrained_estimator.function_from_fit.get_params(
coordinate=np.array([year]), coordinate=np.array([year]),
is_transformed=False) is_transformed=False)
return_level_values.append(gev_params.quantile(self.quantile_level)) return_level_values.append(gev_params.quantile(self.quantile_level))
...@@ -265,7 +265,7 @@ class AbstractGevTrendTest(object): ...@@ -265,7 +265,7 @@ class AbstractGevTrendTest(object):
label = 'Y({})'.format(year) if year is not None else label label = 'Y({})'.format(year) if year is not None else label
if year is None: if year is None:
year = 2019 year = 2019
gev_params_year = self.unconstrained_estimator.function_from_fit.get_gev_params( gev_params_year = self.unconstrained_estimator.function_from_fit.get_params(
coordinate=np.array([year]), coordinate=np.array([year]),
is_transformed=False) is_transformed=False)
extended_maxima = [gev_params_year.gumbel_inverse_standardization(q) for q in extended_quantiles] extended_maxima = [gev_params_year.gumbel_inverse_standardization(q) for q in extended_quantiles]
...@@ -356,7 +356,7 @@ class AbstractGevTrendTest(object): ...@@ -356,7 +356,7 @@ class AbstractGevTrendTest(object):
def compute_empirical_quantiles(self, estimator): def compute_empirical_quantiles(self, estimator):
empirical_quantiles = [] empirical_quantiles = []
for year, maximum in sorted(zip(self.years, self.maxima), key=lambda t: t[1]): for year, maximum in sorted(zip(self.years, self.maxima), key=lambda t: t[1]):
gev_param = estimator.function_from_fit.get_gev_params( gev_param = estimator.function_from_fit.get_params(
coordinate=np.array([year]), coordinate=np.array([year]),
is_transformed=False) is_transformed=False)
maximum_standardized = gev_param.gumbel_standardization(maximum) maximum_standardized = gev_param.gumbel_standardization(maximum)
...@@ -402,8 +402,8 @@ class AbstractGevTrendTest(object): ...@@ -402,8 +402,8 @@ class AbstractGevTrendTest(object):
plt.gca().set_ylim(bottom=0) plt.gca().set_ylim(bottom=0)
def get_gev_params_with_big_shape_and_correct_shape(self): def get_gev_params_with_big_shape_and_correct_shape(self):
gev_params = self.unconstrained_estimator.function_from_fit.get_gev_params(coordinate=np.array([YEAR_OF_INTEREST_FOR_RETURN_LEVEL]), gev_params = self.unconstrained_estimator.function_from_fit.get_params(coordinate=np.array([YEAR_OF_INTEREST_FOR_RETURN_LEVEL]),
is_transformed=False) # type: GevParams is_transformed=False) # type: GevParams
gev_params_with_corrected_shape = GevParams(loc=gev_params.location, gev_params_with_corrected_shape = GevParams(loc=gev_params.location,
scale=gev_params.scale, scale=gev_params.scale,
shape=0.5) shape=0.5)
......
...@@ -47,7 +47,7 @@ class AnnualMaximaSimulation(AbstractSimulation): ...@@ -47,7 +47,7 @@ class AnnualMaximaSimulation(AbstractSimulation):
last_coordinate = coordinates.coordinates_values()[-1] last_coordinate = coordinates.coordinates_values()[-1]
# Compute true value # Compute true value
margin_model = self.time_series_lengths_to_margin_model[length] margin_model = self.time_series_lengths_to_margin_model[length]
true_gev_params = margin_model.margin_function_sample.get_gev_params(last_coordinate) true_gev_params = margin_model.margin_function_sample.get_params(last_coordinate)
true_quantile = true_gev_params.quantile(self.quantile_data) true_quantile = true_gev_params.quantile(self.quantile_data)
# Compute estimated values # Compute estimated values
estimated_quantiles = [estimator.function_from_fit.get_quantile(last_coordinate) for estimator in estimators] estimated_quantiles = [estimator.function_from_fit.get_quantile(last_coordinate) for estimator in estimators]
......
...@@ -43,7 +43,7 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase): ...@@ -43,7 +43,7 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase):
fit_method=self.fit_method) fit_method=self.fit_method)
ref = {'loc': 0.34272436381693616, 'scale': 1.3222588712831973, 'shape': 0.30491484962825105} ref = {'loc': 0.34272436381693616, 'scale': 1.3222588712831973, 'shape': 0.30491484962825105}
for year in range(1, 3): for year in range(1, 3):
mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(np.array([year])).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
...@@ -55,8 +55,8 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase): ...@@ -55,8 +55,8 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase):
mu1_values = estimator.result_from_model_fit.df_posterior_samples.iloc[:, 1] mu1_values = estimator.result_from_model_fit.df_posterior_samples.iloc[:, 1]
self.assertTrue((mu1_values != 0).any()) self.assertTrue((mu1_values != 0).any())
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
def test_gev_temporal_margin_fit_non_stationary_location_and_scale(self): def test_gev_temporal_margin_fit_non_stationary_location_and_scale(self):
...@@ -67,8 +67,8 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase): ...@@ -67,8 +67,8 @@ class TestGevTemporalExtremesBayesian(unittest.TestCase):
mu1_values = estimator.result_from_model_fit.df_posterior_samples.iloc[:, 1] mu1_values = estimator.result_from_model_fit.df_posterior_samples.iloc[:, 1]
self.assertTrue((mu1_values != 0).any()) self.assertTrue((mu1_values != 0).any())
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
......
...@@ -42,7 +42,7 @@ class TestGevTemporalExtremesGumbel(unittest.TestCase): ...@@ -42,7 +42,7 @@ class TestGevTemporalExtremesGumbel(unittest.TestCase):
fit_method=MarginFitMethod.extremes_fevd_mle) fit_method=MarginFitMethod.extremes_fevd_mle)
ref = {'loc': -0.0862185692806497, 'scale': 1.0818465357627252, 'shape': 0} ref = {'loc': -0.0862185692806497, 'scale': 1.0818465357627252, 'shape': 0}
for year in range(1, 3): for year in range(1, 3):
mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(np.array([year])).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
......
...@@ -45,7 +45,7 @@ class TestGevTemporalExtremesLMoments(unittest.TestCase): ...@@ -45,7 +45,7 @@ class TestGevTemporalExtremesLMoments(unittest.TestCase):
fit_method=self.fit_method) fit_method=self.fit_method)
ref = {'loc': 0.0813843045950251, 'scale': 1.1791830110181365, 'shape': 0.6610403806908737} ref = {'loc': 0.0813843045950251, 'scale': 1.1791830110181365, 'shape': 0.6610403806908737}
for year in range(1, 3): for year in range(1, 3):
mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(np.array([year])).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
......
...@@ -43,7 +43,7 @@ class TestGevTemporalExtremesMle(unittest.TestCase): ...@@ -43,7 +43,7 @@ class TestGevTemporalExtremesMle(unittest.TestCase):
fit_method=self.fit_method) fit_method=self.fit_method)
ref = {'loc': 0.02191974259369493, 'scale': 1.0347946062900268, 'shape': 0.829052520147379} ref = {'loc': 0.02191974259369493, 'scale': 1.0347946062900268, 'shape': 0.829052520147379}
for year in range(1, 3): for year in range(1, 3):
mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(np.array([year])).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh()) self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh())
...@@ -54,8 +54,8 @@ class TestGevTemporalExtremesMle(unittest.TestCase): ...@@ -54,8 +54,8 @@ class TestGevTemporalExtremesMle(unittest.TestCase):
starting_year=0, starting_year=0,
fit_method=self.fit_method) fit_method=self.fit_method)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh()) self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh())
...@@ -66,8 +66,8 @@ class TestGevTemporalExtremesMle(unittest.TestCase): ...@@ -66,8 +66,8 @@ class TestGevTemporalExtremesMle(unittest.TestCase):
starting_year=0, starting_year=0,
fit_method=self.fit_method) fit_method=self.fit_method)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
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())
......
...@@ -45,7 +45,7 @@ class TestGevTemporal(unittest.TestCase): ...@@ -45,7 +45,7 @@ class TestGevTemporal(unittest.TestCase):
fit_method=self.fit_method) fit_method=self.fit_method)
ref = {'loc': 0.04309190816463247, 'scale': 2.0688696961628437, 'shape': 0.8291528207825063} ref = {'loc': 0.04309190816463247, 'scale': 2.0688696961628437, 'shape': 0.8291528207825063}
for year in range(1, 3): for year in range(1, 3):
mle_params_estimated = estimator.function_from_fit.get_gev_params(np.array([year])).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(np.array([year])).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
...@@ -56,8 +56,8 @@ class TestGevTemporal(unittest.TestCase): ...@@ -56,8 +56,8 @@ class TestGevTemporal(unittest.TestCase):
estimator = LinearMarginEstimator(self.dataset, margin_model) estimator = LinearMarginEstimator(self.dataset, margin_model)
estimator.fit() estimator.fit()
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
def test_gev_temporal_margin_fit_nonstationary_with_start_point(self): def test_gev_temporal_margin_fit_nonstationary_with_start_point(self):
...@@ -67,10 +67,10 @@ class TestGevTemporal(unittest.TestCase): ...@@ -67,10 +67,10 @@ class TestGevTemporal(unittest.TestCase):
# Checks starting point parameter are well passed # Checks starting point parameter are well passed
self.assertEqual(3, estimator.function_from_fit.starting_point) self.assertEqual(3, estimator.function_from_fit.starting_point)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(np.array([1])).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(np.array([1])).to_dict()
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(np.array([3])).to_dict()
self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year3)
mle_params_estimated_year5 = estimator.function_from_fit.get_gev_params(np.array([5])).to_dict() mle_params_estimated_year5 = estimator.function_from_fit.get_params(np.array([5])).to_dict()
self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year3)
def fit_non_stationary_estimator(self, starting_point): def fit_non_stationary_estimator(self, starting_point):
......
...@@ -32,7 +32,7 @@ class MarginFunction(unittest.TestCase): ...@@ -32,7 +32,7 @@ class MarginFunction(unittest.TestCase):
margin_function = self.margin_function_class.from_coef_dict(coordinates, margin_function = self.margin_function_class.from_coef_dict(coordinates,
margin_model.margin_function_sample.gev_param_name_to_dims, margin_model.margin_function_sample.gev_param_name_to_dims,
coef_dict) coef_dict)
gev_param = margin_function.get_gev_params(coordinate=np.array([0.5, 1.0]), is_transformed=False) gev_param = margin_function.get_params(coordinate=np.array([0.5, 1.0]), is_transformed=False)
self.assertEqual({'loc': 2, 'scale': 2, 'shape': 2}, gev_param.to_dict()) self.assertEqual({'loc': 2, 'scale': 2, 'shape': 2}, gev_param.to_dict())
def test_coef_dict_spatial_coordinates(self): def test_coef_dict_spatial_coordinates(self):
...@@ -46,7 +46,7 @@ class MarginFunction(unittest.TestCase): ...@@ -46,7 +46,7 @@ class MarginFunction(unittest.TestCase):
margin_function = self.margin_function_class.from_coef_dict(coordinates, margin_function = self.margin_function_class.from_coef_dict(coordinates,
margin_model.margin_function_sample.gev_param_name_to_dims, margin_model.margin_function_sample.gev_param_name_to_dims,
coef_dict) coef_dict)
gev_param = margin_function.get_gev_params(coordinate=np.array([1]), is_transformed=False) gev_param = margin_function.get_params(coordinate=np.array([1]), is_transformed=False)
self.assertEqual({'loc': 3, 'scale': 1, 'shape': 1}, gev_param.to_dict()) self.assertEqual({'loc': 3, 'scale': 1, 'shape': 1}, gev_param.to_dict())
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -33,7 +33,7 @@ class TestMarginTemporal(unittest.TestCase): ...@@ -33,7 +33,7 @@ class TestMarginTemporal(unittest.TestCase):
ref = {'loc': 1.3456595684773085, 'scale': 1.090369430386199, 'shape': 0.6845422250749476} ref = {'loc': 1.3456595684773085, 'scale': 1.090369430386199, 'shape': 0.6845422250749476}
for year in range(1, 3): for year in range(1, 3):
coordinate = np.array([0.0, 0.0, year]) coordinate = np.array([0.0, 0.0, year])
mle_params_estimated = estimator.function_from_fit.get_gev_params(coordinate).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(coordinate).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
...@@ -45,9 +45,9 @@ class TestMarginTemporal(unittest.TestCase): ...@@ -45,9 +45,9 @@ class TestMarginTemporal(unittest.TestCase):
self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0) self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1).to_dict()
coordinate3 = np.array([0.0, 0.0, 3]) coordinate3 = np.array([0.0, 0.0, 3])
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(coordinate3).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(coordinate3).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
def test_margin_fit_nonstationary_with_start_point(self): def test_margin_fit_nonstationary_with_start_point(self):
...@@ -62,12 +62,12 @@ class TestMarginTemporal(unittest.TestCase): ...@@ -62,12 +62,12 @@ class TestMarginTemporal(unittest.TestCase):
self.assertEqual(2, estimator.function_from_fit.starting_point) self.assertEqual(2, estimator.function_from_fit.starting_point)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1).to_dict()
coordinate2 = np.array([0.0, 0.0, 2]) coordinate2 = np.array([0.0, 0.0, 2])
mle_params_estimated_year2 = estimator.function_from_fit.get_gev_params(coordinate2).to_dict() mle_params_estimated_year2 = estimator.function_from_fit.get_params(coordinate2).to_dict()
self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2) self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2)
coordinate5 = np.array([0.0, 0.0, 5]) coordinate5 = np.array([0.0, 0.0, 5])
mle_params_estimated_year5 = estimator.function_from_fit.get_gev_params(coordinate5).to_dict() mle_params_estimated_year5 = estimator.function_from_fit.get_params(coordinate5).to_dict()
self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2) self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2)
def fit_non_stationary_estimator(self, starting_point): def fit_non_stationary_estimator(self, starting_point):
......
...@@ -41,8 +41,8 @@ class TestMarginTemporalTransformed(unittest.TestCase): ...@@ -41,8 +41,8 @@ class TestMarginTemporalTransformed(unittest.TestCase):
'shape': 0.7289248773961512} 'shape': 0.7289248773961512}
for year in range(1, 3): for year in range(1, 3):
coordinate = np.array([0.0, 0.0, year]) coordinate = np.array([0.0, 0.0, year])
mle_params_estimated = estimator.function_from_fit.get_gev_params(coordinate, mle_params_estimated = estimator.function_from_fit.get_params(coordinate,
is_transformed=False).to_dict() is_transformed=False).to_dict()
self.assertEqual(mle_params_estimated, ref) self.assertEqual(mle_params_estimated, ref)
def test_margin_fit_nonstationary(self): def test_margin_fit_nonstationary(self):
...@@ -53,11 +53,11 @@ class TestMarginTemporalTransformed(unittest.TestCase): ...@@ -53,11 +53,11 @@ class TestMarginTemporalTransformed(unittest.TestCase):
self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0) self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1, mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1,
is_transformed=False).to_dict() is_transformed=False).to_dict()
coordinate3 = np.array([0.0, 0.0, 3]) coordinate3 = np.array([0.0, 0.0, 3])
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(coordinate3, mle_params_estimated_year3 = estimator.function_from_fit.get_params(coordinate3,
is_transformed=False).to_dict() is_transformed=False).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
def test_margin_fit_nonstationary_with_start_point(self): def test_margin_fit_nonstationary_with_start_point(self):
...@@ -67,15 +67,15 @@ class TestMarginTemporalTransformed(unittest.TestCase): ...@@ -67,15 +67,15 @@ class TestMarginTemporalTransformed(unittest.TestCase):
self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0) self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1, mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1,
is_transformed=False).to_dict() is_transformed=False).to_dict()
coordinate2 = np.array([0.0, 0.0, 2]) coordinate2 = np.array([0.0, 0.0, 2])
mle_params_estimated_year2 = estimator.function_from_fit.get_gev_params(coordinate2, mle_params_estimated_year2 = estimator.function_from_fit.get_params(coordinate2,
is_transformed=False).to_dict() is_transformed=False).to_dict()
self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2) self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2)
coordinate5 = np.array([0.0, 0.0, 5]) coordinate5 = np.array([0.0, 0.0, 5])
mle_params_estimated_year5 = estimator.function_from_fit.get_gev_params(coordinate5, mle_params_estimated_year5 = estimator.function_from_fit.get_params(coordinate5,
is_transformed=False).to_dict() is_transformed=False).to_dict()
self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2) self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2)
def fit_non_stationary_estimator(self, starting_point): def fit_non_stationary_estimator(self, starting_point):
......
...@@ -37,7 +37,7 @@ class TestMaxStableTemporal(unittest.TestCase): ...@@ -37,7 +37,7 @@ class TestMaxStableTemporal(unittest.TestCase):
ref = {'loc': 1.2091156634312243, 'scale': 1.1210085591373455, 'shape': 0.9831957705294134} ref = {'loc': 1.2091156634312243, 'scale': 1.1210085591373455, 'shape': 0.9831957705294134}
for year in range(1, 3): for year in range(1, 3):
coordinate = np.array([0.0, 0.0, year]) coordinate = np.array([0.0, 0.0, year])
mle_params_estimated = estimator.function_from_fit.get_gev_params(coordinate).to_dict() mle_params_estimated = estimator.function_from_fit.get_params(coordinate).to_dict()
for key in ref.keys(): for key in ref.keys():
self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3) self.assertAlmostEqual(ref[key], mle_params_estimated[key], places=3)
...@@ -50,9 +50,9 @@ class TestMaxStableTemporal(unittest.TestCase): ...@@ -50,9 +50,9 @@ class TestMaxStableTemporal(unittest.TestCase):
self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0) self.assertNotEqual(estimator.function_from_fit.mu1_temporal_trend, 0.0)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1).to_dict()
coordinate3 = np.array([0.0, 0.0, 3]) coordinate3 = np.array([0.0, 0.0, 3])
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(coordinate3).to_dict() mle_params_estimated_year3 = estimator.function_from_fit.get_params(coordinate3).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3) self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
def test_margin_fit_nonstationary_with_start_point(self): def test_margin_fit_nonstationary_with_start_point(self):
...@@ -67,12 +67,12 @@ class TestMaxStableTemporal(unittest.TestCase): ...@@ -67,12 +67,12 @@ class TestMaxStableTemporal(unittest.TestCase):
self.assertEqual(2, estimator.function_from_fit.starting_point) self.assertEqual(2, estimator.function_from_fit.starting_point)
# Checks that parameters returned are indeed different # Checks that parameters returned are indeed different
coordinate1 = np.array([0.0, 0.0, 1]) coordinate1 = np.array([0.0, 0.0, 1])
mle_params_estimated_year1 = estimator.function_from_fit.get_gev_params(coordinate1).to_dict() mle_params_estimated_year1 = estimator.function_from_fit.get_params(coordinate1).to_dict()
coordinate2 = np.array([0.0, 0.0, 2]) coordinate2 = np.array([0.0, 0.0, 2])
mle_params_estimated_year2 = estimator.function_from_fit.get_gev_params(coordinate2).to_dict() mle_params_estimated_year2 = estimator.function_from_fit.get_params(coordinate2).to_dict()
self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2) self.assertEqual(mle_params_estimated_year1, mle_params_estimated_year2)
coordinate5 = np.array([0.0, 0.0, 5]) coordinate5 = np.array([0.0, 0.0, 5])
mle_params_estimated_year5 = estimator.function_from_fit.get_gev_params(coordinate5).to_dict() mle_params_estimated_year5 = estimator.function_from_fit.get_params(coordinate5).to_dict()
self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2) self.assertNotEqual(mle_params_estimated_year5, mle_params_estimated_year2)
def fit_non_stationary_estimator(self, starting_point): def fit_non_stationary_estimator(self, starting_point):
......
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