Commit 0db99592 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[COORDINATES] refactor test_coordinates

parent c44d5441
No related merge requests found
Showing with 86 additions and 64 deletions
+86 -64
......@@ -5,7 +5,7 @@ from experiment.robustness_plot.display_item import DisplayItem
from experiment.robustness_plot.multiple_plot import MultiplePlot
from experiment.robustness_plot.single_plot import SinglePlot
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
from spatio_temporal_dataset.dataset.simulation_dataset import MaxStableDataset
......@@ -23,7 +23,7 @@ class CoordinateDisplayItem(DisplayItem):
class MaxStableProcessPlot(object):
MaxStableModelItem = MaxStableDisplayItem('max_stable_model', Smith)
CoordinateClassItem = CoordinateDisplayItem('coordinate_class', CircleCoordinatesRadius1)
CoordinateClassItem = CoordinateDisplayItem('coordinate_class', CircleCoordinates)
NbStationItem = DisplayItem('Number of stations', 50)
NbObservationItem = DisplayItem('nb_obs', 60)
......
......@@ -4,7 +4,7 @@ from experiment.robustness_plot.estimation_robustness.max_stable_process_plot im
from experiment.robustness_plot.single_plot import SinglePlot
from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_2D_coordinates import \
AlpsStation2DCoordinatesBetweenZeroAndOne, AlpsStationCoordinatesBetweenZeroAndTwo
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1, \
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates, \
CircleCoordinatesRadius2
......@@ -49,7 +49,7 @@ def multiple_spatial_robustness_alps():
MaxStableProcessPlot.NbStationItem.name: nb_stations,
MaxStableProcessPlot.NbObservationItem.name: nb_observation,
MaxStableProcessPlot.MaxStableModelItem.name: msp_models,
MaxStableProcessPlot.CoordinateClassItem.name: [CircleCoordinatesRadius1,
MaxStableProcessPlot.CoordinateClassItem.name: [CircleCoordinates,
CircleCoordinatesRadius2,
AlpsStation2DCoordinatesBetweenZeroAndOne,
AlpsStationCoordinatesBetweenZeroAndTwo][:],
......
......@@ -4,7 +4,7 @@ from experiment.robustness_plot.estimation_robustness.max_stable_process_plot im
from experiment.robustness_plot.single_plot import SinglePlot
from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_2D_coordinates import \
AlpsStation2DCoordinatesBetweenZeroAndOne, AlpsStationCoordinatesBetweenZeroAndTwo
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1, \
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates, \
CircleCoordinatesRadius2
......@@ -49,7 +49,7 @@ def multiple_unidimensional_robustness():
MaxStableProcessPlot.NbStationItem.name: nb_stations,
MaxStableProcessPlot.NbObservationItem.name: nb_observation,
MaxStableProcessPlot.MaxStableModelItem.name: msp_models,
MaxStableProcessPlot.CoordinateClassItem.name: [CircleCoordinatesRadius1,
MaxStableProcessPlot.CoordinateClassItem.name: [CircleCoordinates,
CircleCoordinatesRadius2,
AlpsStation2DCoordinatesBetweenZeroAndOne,
AlpsStationCoordinatesBetweenZeroAndTwo][:],
......
from extreme_estimator.extreme_models.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, \
Geometric, ExtremalT, ISchlather
MAX_STABLE_TYPES = [Smith, BrownResnick, Schlather, Geometric, ExtremalT, ISchlather]
def load_max_stable_models():
# Load all max stable model
max_stable_models = []
for max_stable_class in MAX_STABLE_TYPES:
if issubclass(max_stable_class, AbstractMaxStableModelWithCovarianceFunction):
max_stable_models.extend([max_stable_class(covariance_function=covariance_function)
for covariance_function in CovarianceFunction])
else:
max_stable_models.append(max_stable_class())
return max_stable_models
......@@ -101,6 +101,15 @@ class AbstractCoordinates(object):
# Visualization
def visualize(self):
nb_coordinates_columns = len(self.coordinates_columns(self.df_coordinates))
if nb_coordinates_columns == 1:
self.visualization_1D()
elif nb_coordinates_columns == 2:
self.visualization_2D()
else:
self.visualization_3D()
def visualization_1D(self):
assert len(self.coordinates_columns(self.df_coordinates)) >= 1
x = self.coordinates_values[:]
......
......@@ -7,7 +7,7 @@ from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoo
import matplotlib.pyplot as plt
class CircleCoordinatesRadius1(AbstractCoordinates):
class CircleCoordinates(AbstractCoordinates):
@classmethod
def from_nb_points(cls, nb_points, max_radius=1.0):
......@@ -15,7 +15,8 @@ class CircleCoordinatesRadius1(AbstractCoordinates):
r = get_loaded_r()
angles = np.array(r.runif(nb_points, max=2 * math.pi))
radius = np.sqrt(np.array(r.runif(nb_points, max=max_radius)))
df = pd.DataFrame.from_dict({cls.COORDINATE_X: radius * np.cos(angles), cls.COORDINATE_Y: radius * np.sin(angles)})
df = pd.DataFrame.from_dict({cls.COORDINATE_X: radius * np.cos(angles),
cls.COORDINATE_Y: radius * np.sin(angles)})
return cls.from_df(df)
def visualization_2D(self):
......@@ -27,7 +28,7 @@ class CircleCoordinatesRadius1(AbstractCoordinates):
super().visualization_2D()
class CircleCoordinatesRadius2(CircleCoordinatesRadius1):
class CircleCoordinatesRadius2(CircleCoordinates):
@classmethod
def from_nb_points(cls, nb_points, max_radius=1.0):
......
......@@ -6,14 +6,14 @@ from extreme_estimator.extreme_models.utils import get_loaded_r
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
class UniDimensionalCoordinates(AbstractCoordinates):
class AbstractUniDimensionalCoordinates(AbstractCoordinates):
pass
class UniformAxisCoordinates(UniDimensionalCoordinates):
class UniformCoordinates(AbstractUniDimensionalCoordinates):
@classmethod
def from_nb_points(cls, nb_points, start=0.0, end=1.0):
def from_nb_points(cls, nb_points, start=-1.0, end=1.0):
# Sample uniformly inside the circle
r = get_loaded_r()
axis_coordinates = np.array(r.runif(nb_points, min=start, max=end))
......
from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_3D_coordinates import \
AlpsStation3DCoordinatesWithAnisotropy
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
from spatio_temporal_dataset.coordinates.unidimensional_coordinates.coordinates_1D import UniformCoordinates
COORDINATES = [UniformCoordinates, CircleCoordinates, AlpsStation3DCoordinatesWithAnisotropy]
def load_coordinates(nb_points):
return [coordinate_class.from_nb_points(nb_points=nb_points) for coordinate_class in COORDINATES]
......@@ -2,14 +2,14 @@ import unittest
from extreme_estimator.gev_params import GevParams
from extreme_estimator.extreme_models.margin_model.smooth_margin_model import LinearShapeAxis0MarginModel
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
class TestLinearMarginModel(unittest.TestCase):
DISPLAY = False
def test_visualization_2D(self):
spatial_coordinates = CircleCoordinatesRadius1.from_nb_points(nb_points=50)
spatial_coordinates = CircleCoordinates.from_nb_points(nb_points=50)
margin_model = LinearShapeAxis0MarginModel(coordinates=spatial_coordinates)
for gev_param_name in GevParams.GEV_PARAM_NAMES:
margin_model.margin_function_sample.visualize_2D(gev_param_name=gev_param_name, show=self.DISPLAY)
......
......@@ -3,8 +3,9 @@ from itertools import product
from extreme_estimator.estimator.full_estimator import SmoothMarginalsThenUnitaryMsp, \
FullEstimatorInASingleStepWithSmoothMargin
from extreme_estimator.extreme_models.max_stable_model.utils import load_max_stable_models
from spatio_temporal_dataset.dataset.simulation_dataset import FullSimulatedDataset
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
from test.test_extreme_estimator.test_estimator.test_margin_estimators import TestSmoothMarginEstimator
from test.test_extreme_estimator.test_estimator.test_max_stable_estimators import TestMaxStableEstimators
......@@ -15,9 +16,10 @@ class TestFullEstimators(unittest.TestCase):
def setUp(self):
super().setUp()
self.spatial_coordinates = CircleCoordinatesRadius1.from_nb_points(nb_points=5, max_radius=1)
self.max_stable_models = TestMaxStableEstimators.load_max_stable_models()
self.smooth_margin_models = TestSmoothMarginEstimator.load_smooth_margin_models(spatial_coordinates=self.spatial_coordinates)
self.spatial_coordinates = CircleCoordinates.from_nb_points(nb_points=5, max_radius=1)
self.max_stable_models = load_max_stable_models()
self.smooth_margin_models = TestSmoothMarginEstimator.load_smooth_margin_models(
coordinates=self.spatial_coordinates)
def test_full_estimators(self):
for margin_model, max_stable_model in product(self.smooth_margin_models, self.max_stable_models):
......
......@@ -6,7 +6,7 @@ from extreme_estimator.extreme_models.margin_model.smooth_margin_model import Co
from extreme_estimator.estimator.margin_estimator import SmoothMarginEstimator
from extreme_estimator.return_level_plot.spatial_2D_plot import Spatial2DPlot
from spatio_temporal_dataset.dataset.simulation_dataset import MarginDataset
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
class TestSmoothMarginEstimator(unittest.TestCase):
......@@ -18,12 +18,12 @@ class TestSmoothMarginEstimator(unittest.TestCase):
def setUp(self):
super().setUp()
self.spatial_coordinates = CircleCoordinatesRadius1.from_nb_points(nb_points=5, max_radius=1)
self.smooth_margin_models = self.load_smooth_margin_models(spatial_coordinates=self.spatial_coordinates)
self.spatial_coordinates = CircleCoordinates.from_nb_points(nb_points=5, max_radius=1)
self.smooth_margin_models = self.load_smooth_margin_models(coordinates=self.spatial_coordinates)
@classmethod
def load_smooth_margin_models(cls, spatial_coordinates):
return [margin_class(coordinates=spatial_coordinates) for margin_class in cls.MARGIN_TYPES]
def load_smooth_margin_models(cls, coordinates):
return [margin_class(coordinates=coordinates) for margin_class in cls.MARGIN_TYPES]
def test_dependency_estimators(self):
for margin_model in self.smooth_margin_models:
......
......@@ -2,34 +2,21 @@ import unittest
from extreme_estimator.extreme_models.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, \
Geometric, ExtremalT, ISchlather
from extreme_estimator.estimator.max_stable_estimator import MaxStableEstimator
from extreme_estimator.extreme_models.max_stable_model.utils import load_max_stable_models
from spatio_temporal_dataset.dataset.simulation_dataset import MaxStableDataset
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
class TestMaxStableEstimators(unittest.TestCase):
DISPLAY = False
MAX_STABLE_TYPES = [Smith, BrownResnick, Schlather, Geometric, ExtremalT, ISchlather]
MAX_STABLE_ESTIMATORS = [MaxStableEstimator]
def setUp(self):
super().setUp()
self.spatial_coord = CircleCoordinatesRadius1.from_nb_points(nb_points=5, max_radius=1)
self.max_stable_models = self.load_max_stable_models()
@classmethod
def load_max_stable_models(cls):
# Load all max stable model
max_stable_models = []
for max_stable_class in cls.MAX_STABLE_TYPES:
if issubclass(max_stable_class, AbstractMaxStableModelWithCovarianceFunction):
max_stable_models.extend([max_stable_class(covariance_function=covariance_function)
for covariance_function in CovarianceFunction])
else:
max_stable_models.append(max_stable_class())
return max_stable_models
self.spatial_coord = CircleCoordinates.from_nb_points(nb_points=5, max_radius=1)
self.max_stable_models = load_max_stable_models()
def test_max_stable_estimators(self):
for max_stable_model in self.max_stable_models:
......
import unittest
from spatio_temporal_dataset.coordinates.unidimensional_coordinates.axis_coordinates import UniformAxisCoordinates
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
from spatio_temporal_dataset.coordinates.unidimensional_coordinates.coordinates_1D import UniformCoordinates
from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_2D_coordinates import \
AlpsStation2DCoordinatesBetweenZeroAndOne
from spatio_temporal_dataset.coordinates.spatial_coordinates.alps_station_3D_coordinates import \
AlpsStation3DCoordinatesWithAnisotropy
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_coordinates import CircleCoordinatesRadius1
from spatio_temporal_dataset.coordinates.spatial_coordinates.generated_spatial_coordinates import CircleCoordinates
class TestSpatialCoordinates(unittest.TestCase):
class TestCoordinates(unittest.TestCase):
DISPLAY = False
def test_circle(self):
coord = CircleCoordinatesRadius1.from_nb_points(nb_points=500)
if self.DISPLAY:
coord.visualization_2D()
self.assertTrue(True)
def __init__(self, methodName='runTest'):
super().__init__(methodName)
self.coord = None # type: AbstractCoordinates
def test_anisotropy(self):
coord = AlpsStation3DCoordinatesWithAnisotropy.from_csv()
def tearDown(self):
if self.DISPLAY:
coord.visualization_3D()
self.coord.visualize()
self.assertTrue(True)
def test_normalization(self):
coord = AlpsStation2DCoordinatesBetweenZeroAndOne.from_csv()
if self.DISPLAY:
coord.visualization_2D()
self.assertTrue(True)
def test_unif(self):
self.coord = UniformCoordinates.from_nb_points(nb_points=10)
def test_circle(self):
self.coord = CircleCoordinates.from_nb_points(nb_points=500)
class TestUniDimensionalCoordinates(unittest.TestCase):
DISPLAY = False
def test_normalization(self):
self.coord = AlpsStation2DCoordinatesBetweenZeroAndOne.from_csv()
def test_unif(self):
coord = UniformAxisCoordinates.from_nb_points(nb_points=10)
if self.DISPLAY:
coord.visualization_1D()
self.assertTrue(True)
def test_anisotropy(self):
self.coord = AlpsStation3DCoordinatesWithAnisotropy.from_csv()
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