From 5b406ef59e571b72fd3c30a5aa8ceef2a58d799a Mon Sep 17 00:00:00 2001
From: Le Roux Erwan <erwan.le-roux@irstea.fr>
Date: Wed, 15 Apr 2020 20:28:46 +0200
Subject: [PATCH] [contrasting project] add test for two fold

---
 .../gev/main_fevd_mle_two_covariates.R        | 57 +++++++++++++++++++
 .../abstract_temporal_linear_margin_model.py  |  6 --
 .../test_two_fold_estimation.py               |  7 ++-
 3 files changed, 63 insertions(+), 7 deletions(-)
 create mode 100644 extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R

diff --git a/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R b/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R
new file mode 100644
index 00000000..aeb32b10
--- /dev/null
+++ b/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R
@@ -0,0 +1,57 @@
+# 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
+
+
+
+
+
+
+
+
diff --git a/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py
index b0179e88..af2e2533 100644
--- a/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py
+++ b/extreme_fit/model/margin_model/linear_margin_model/abstract_temporal_linear_margin_model.py
@@ -16,8 +16,6 @@ from extreme_fit.model.utils import safe_run_r_estimator
 from spatio_temporal_dataset.coordinates.abstract_coordinates import AbstractCoordinates
 
 
-
-
 class AbstractTemporalLinearMarginModel(LinearMarginModel):
     """Linearity only with respect to the temporal coordinates"""
 
@@ -136,7 +134,3 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel):
     @property
     def siglink(self):
         return r('identity')
-
-
-if __name__ == '__main__':
-    print(fitmethod_to_str(MarginFitMethod.extremes_fevd_l_moments))
diff --git a/test/test_projects/test_contrasting/test_two_fold_estimation.py b/test/test_projects/test_contrasting/test_two_fold_estimation.py
index 8af825f7..808e6446 100644
--- a/test/test_projects/test_contrasting/test_two_fold_estimation.py
+++ b/test/test_projects/test_contrasting/test_two_fold_estimation.py
@@ -13,7 +13,7 @@ class TestAltitudesStudies(unittest.TestCase):
         super().setUp()
         altitudes = [900, 1200]
         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)
 
     def test_dataset_sizes(self):
@@ -28,6 +28,11 @@ class TestAltitudesStudies(unittest.TestCase):
         with self.assertRaises(AssertionError):
             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__':
     unittest.main()
-- 
GitLab