Commit e5bdf83b authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[refactor] improve test coverage for gev_params.py, and deactivate test_two_fold_fit.py

parent 62b35531
No related merge requests found
Showing with 26 additions and 13 deletions
+26 -13
......@@ -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:
......
......@@ -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
......
......@@ -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):
......
......@@ -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__':
......
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