Commit 5b406ef5 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting project] add test for two fold

parent 354097c7
No related merge requests found
Showing with 63 additions and 7 deletions
+63 -7
# Title : TODO
# Objective : TODO
# Created by: erwan
# Created on: 04/10/2019
library(extRemes)
library(data.table)
library(stats4)
library(SpatialExtremes)
source('fevd_fixed.R')
source('ci_fevd_fixed.R')
# Sample from a GEV
set.seed(42)
N <- 50
loc = 0; scale = 1; shape <- 1
x_gev <- rgev(N, loc = loc, scale = scale, shape = shape)
# start_loc = 0; start_scale = 1; start_shape = 1
# N <- 50
# loc = 0; scale = 1; shape <- 0.1
# x_gev <- rgev(N, loc = loc, scale = scale, shape = shape)
print(N)
coord <- matrix(ncol=2, nrow = N)
coord[,1]=seq(0,N-1,1)
coord[,2]=seq(0,N-1,1)
print(coord)
colnames(coord) = c("X", "T")
coord = data.frame(coord, stringsAsFactors = TRUE)
# res = fevd_fixed(x_gev, data=coord, method='MLE', verbose=TRUE, use.phi=FALSE)
# res = fevd_fixed(x_gev, data=coord, location.fun= ~T, scale.fun= ~T, method='MLE', type="GEV", verbose=FALSE, use.phi=FALSE)
res = fevd_fixed(x_gev, data=coord, location.fun= ~sin(X) + cos(T), method='MLE', type="GEV", verbose=FALSE, use.phi=FALSE)
print(res)
# Some display for the results
# m = res$results
# print(class(res$chain.info))
# print(dim(m))
# print(m)
print(res$results$par)
# print(res$par)
# print(m[1])
# Confidence interval staionary
# method = "proflik"
# res_ci = ci.fevd.mle(res, alpha = 0.05, type = c("return.level"),
# return.period = 50, method = method, xrange = c(-200,200), nint = 10, R=502, verbose = TRUE,
# tscale = FALSE, return.samples = FALSE)
# print(res_ci)
# Bug to solve for the non stationary - the returned parameter do not match with the return level
...@@ -16,8 +16,6 @@ from extreme_fit.model.utils import safe_run_r_estimator ...@@ -16,8 +16,6 @@ from extreme_fit.model.utils import safe_run_r_estimator
from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
class AbstractTemporalLinearMarginModel(LinearMarginModel): class AbstractTemporalLinearMarginModel(LinearMarginModel):
"""Linearity only with respect to the temporal coordinates""" """Linearity only with respect to the temporal coordinates"""
...@@ -136,7 +134,3 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): ...@@ -136,7 +134,3 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel):
@property @property
def siglink(self): def siglink(self):
return r('identity') return r('identity')
if __name__ == '__main__':
print(fitmethod_to_str(MarginFitMethod.extremes_fevd_l_moments))
...@@ -13,7 +13,7 @@ class TestAltitudesStudies(unittest.TestCase): ...@@ -13,7 +13,7 @@ class TestAltitudesStudies(unittest.TestCase):
super().setUp() super().setUp()
altitudes = [900, 1200] altitudes = [900, 1200]
study_class = SafranSnowfall1Day study_class = SafranSnowfall1Day
studies = AltitudesStudies(study_class, altitudes, year_min=1959, year_max=1962) studies = AltitudesStudies(study_class, altitudes, year_min=1959, year_max=1963)
self.two_fold_estimation = TwoFoldEstimation(studies, nb_samples=2) self.two_fold_estimation = TwoFoldEstimation(studies, nb_samples=2)
def test_dataset_sizes(self): def test_dataset_sizes(self):
...@@ -28,6 +28,11 @@ class TestAltitudesStudies(unittest.TestCase): ...@@ -28,6 +28,11 @@ class TestAltitudesStudies(unittest.TestCase):
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
dataset1.maxima_gev(split=Split.train_spatial) dataset1.maxima_gev(split=Split.train_spatial)
def test_temporal_steps(self):
dataset1, _ = self.two_fold_estimation.two_fold_datasets('Vercors')
self.assertEqual(len(dataset1.coordinates.df_temporal_coordinates(split=Split.train_temporal)), 2)
self.assertEqual(len(dataset1.coordinates.df_temporal_coordinates(split=Split.test_temporal)), 3)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.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