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