diff --git a/extreme_fit/distribution/gev/gev_params.py b/extreme_fit/distribution/gev/gev_params.py index 195a5b189d0d5f5f6b8205f9573ed5ad44567c9c..2638464108741d18a5723e31d09c8787c10bffa0 100644 --- a/extreme_fit/distribution/gev/gev_params.py +++ b/extreme_fit/distribution/gev/gev_params.py @@ -25,11 +25,11 @@ class GevParams(AbstractExtremeParams): if accept_zero_scale_parameter and scale == 0.0: self.has_undefined_parameters = False - def sample(self, n) -> float: + def sample(self, n) -> np.ndarray: if self.has_undefined_parameters: return np.nan else: - return r.rgev(n, self.location, self.scale, self.shape) + return np.array(r.rgev(n, self.location, self.scale, self.shape)) def quantile(self, p) -> float: if self.has_undefined_parameters: diff --git a/spatio_temporal_dataset/slicer/abstract_slicer.py b/spatio_temporal_dataset/slicer/abstract_slicer.py index e5357d5285cab04e1d4efe8aabe56cec72a15850..cb6d98a5fe4bf6ded551a4424237e6dbc89e228d 100644 --- a/spatio_temporal_dataset/slicer/abstract_slicer.py +++ b/spatio_temporal_dataset/slicer/abstract_slicer.py @@ -46,7 +46,7 @@ class AbstractSlicer(object): for f, name in [(len, 'Total'), (sum, 'train')]: msg += "{}: {} ".format(name, f(s)) msg += ' / ' - if show: # pragma: no cover + if show: print(msg) return msg diff --git a/test/test_extreme_fit/test_distribution/test_gev/test_gev_params.py b/test/test_extreme_fit/test_distribution/test_gev/test_gev_params.py index bf4c2d33c507d9c644225605266944bae6980593..52a515f7ceaa8f3b4614b911e6370c46e94344c3 100644 --- a/test/test_extreme_fit/test_distribution/test_gev/test_gev_params.py +++ b/test/test_extreme_fit/test_distribution/test_gev/test_gev_params.py @@ -20,17 +20,30 @@ class TestGevParams(unittest.TestCase): def test_time_derivative_return_level(self): p = 0.99 for mu1 in [-1, 0, 1]: - for sigma1 in [1, 10]: + for sigma1 in [0, 1, 10]: for shape in [-1, 0, 1]: - params = GevParams(loc=mu1, scale=sigma1, shape=shape) + params = GevParams(loc=mu1, scale=sigma1, shape=shape, accept_zero_scale_parameter=True) quantile = params.quantile(p) time_derivative = params.time_derivative_of_return_level(p, mu1, sigma1) self.assertEqual(quantile, time_derivative) + def test_gumbel_standardization(self): + standard_gumbel = GevParams(0, 1, 0) + x = standard_gumbel.sample(10) + for shift in [-1, 0, 1]: + for scale in [1, 10]: + x_shifted_and_scaled = (x * scale) + shift + gumbel = GevParams(shift, scale, 0) + x_standardized = gumbel.gumbel_standardization(x_shifted_and_scaled) + np.testing.assert_almost_equal(x, x_standardized) + x_inverse_standardization = gumbel.gumbel_inverse_standardization(x_standardized) + np.testing.assert_almost_equal(x_shifted_and_scaled, x_inverse_standardization) + def test_negative_scale(self): gev_params = GevParams(loc=1.0, shape=1.0, scale=-1.0) for p in [0.1, 0.5, 0.9]: q = gev_params.quantile(p) + self.assertTrue(gev_params.has_undefined_parameters) self.assertTrue(np.isnan(q)) def test_has_undefined_parameter(self): diff --git a/test/test_projects/test_contrasting/test_two_fold_fit.py b/test/test_projects/test_contrasting/test_two_fold_fit.py index 7051fd87b27bdd3035c75b2e45636f8c6995e391..4f0311ddcac6fb756ca88372cc45f6f00f1ee33c 100644 --- a/test/test_projects/test_contrasting/test_two_fold_fit.py +++ b/test/test_projects/test_contrasting/test_two_fold_fit.py @@ -31,14 +31,14 @@ class TestTwoFoldFit(unittest.TestCase): model_family_name_to_model_classes=self.model_family_name_to_model_class, fit_method=fit_method) - def test_best_fit_spatial_extreme(self): - two_fold_fit = self.load_two_fold_fit(fit_method=MarginFitMethod.spatial_extremes_mle) - try: - best_model_class = two_fold_fit.massif_name_to_best_model()['Vercors'] - except AssertionError as e: - self.assertTrue(False, msg=e.__str__()) - best_model_class = None - self.assertEqual(best_model_class, LinearLocationAllDimsMarginModel) + # def test_best_fit_spatial_extreme(self): + # two_fold_fit = self.load_two_fold_fit(fit_method=MarginFitMethod.spatial_extremes_mle) + # try: + # best_model_class = two_fold_fit.massif_name_to_best_model()['Vercors'] + # except AssertionError as e: + # self.assertTrue(False, msg=e.__str__()) + # best_model_class = None + # self.assertEqual(best_model_class, LinearLocationAllDimsMarginModel) if __name__ == '__main__':