Commit 8938b42f authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting project] add aic and bic as results of extremes

parent e799fa49
No related merge requests found
Showing with 32 additions and 0 deletions
+32 -0
import numpy as np
from rpy2 import robjects
from extreme_fit.model.utils import r
class AbstractResultFromModelFit(object):
......@@ -44,6 +45,14 @@ class AbstractResultFromModelFit(object):
def deviance(self):
return - 2 * self.nllh
@property
def bic(self):
raise NotImplementedError
@property
def aic(self):
raise NotImplementedError
@property
def convergence(self) -> str:
raise NotImplementedError
......
......@@ -15,10 +15,22 @@ class AbstractResultFromExtremes(AbstractResultFromModelFit):
super().__init__(result_from_fit)
self.gev_param_name_to_dim = gev_param_name_to_dim
@property
def summary_name_to_value(self):
return self.get_python_dictionary(r('summary')(self.result_from_fit))
@property
def results(self):
return self.get_python_dictionary(self.name_to_value['results'])
@property
def bic(self):
return np.array(self.summary_name_to_value['BIC'])[0]
@property
def aic(self):
return np.array(self.summary_name_to_value['AIC'])[0]
@property
def nllh(self):
return np.array(self.results['value'])[0]
......
......@@ -4,6 +4,9 @@ from enum import Enum
class Score(Enum):
NLLH_TEST = 1
AIC_TRAIN = 2
BIC_TRAIN = 3
SPAN_30_RETURN_LEVEL_2019_AT_1000M = 4
class Grouping(Enum):
......
......@@ -70,6 +70,14 @@ class TestGevTemporalExtremesMle(unittest.TestCase):
mle_params_estimated_year3 = estimator.function_from_fit.get_gev_params(np.array([3])).to_dict()
self.assertNotEqual(mle_params_estimated_year1, mle_params_estimated_year3)
self.assertAlmostEqual(estimator.result_from_model_fit.nllh, estimator.nllh())
# self.assertAlmostEqual(estimator.result_from_model_fit.aic, estimator.aic())
# self.assertAlmostEqual(estimator.result_from_model_fit.bic, estimator.bic())
# print(estimator.result_from_model_fit.summary_name_to_value)
# for k, v in estimator.result_from_model_fit.results.items():
# print(k, np.array(v)[0])
self.assertAlmostEqual(estimator.result_from_model_fit.aic, 215.59675857481045)
self.assertAlmostEqual(estimator.result_from_model_fit.bic, 225.1568736019512)
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