diff --git a/extreme_estimator/estimator/abstract_estimator.py b/extreme_estimator/estimator/abstract_estimator.py index 0b938d36253cfd0966cfcd0ac9cdffc77ce0a38f..d21f3063aceb481e6006271ca139ee67f752826f 100644 --- a/extreme_estimator/estimator/abstract_estimator.py +++ b/extreme_estimator/estimator/abstract_estimator.py @@ -64,15 +64,7 @@ class AbstractEstimator(object): def train_split(self): return self.dataset.train_split - def scalars(self, true_max_stable_params: dict): - error = self._error(true_max_stable_params) - return {**error, **self.additional_information} - # Methods to override in the child class def _fit(self): raise NotImplementedError - - def _error(self, true_max_stable_params: dict): - raise NotImplementedError - diff --git a/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py b/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py index f9b369e7085604aa4479e6a8569d7f3a826db8fe..1340adfef21be73b90b6d88643ba7f4a43c3bc38 100644 --- a/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py +++ b/extreme_estimator/estimator/margin_estimator/abstract_margin_estimator.py @@ -28,6 +28,9 @@ class PointWiseMarginEstimator(AbstractMarginEstimator): class SmoothMarginEstimator(AbstractMarginEstimator): """# with different type of marginals: cosntant, linear....""" + def _error(self, true_max_stable_params: dict): + pass + def __init__(self, dataset: AbstractDataset, margin_model: LinearMarginModel): super().__init__(dataset) assert isinstance(margin_model, LinearMarginModel) @@ -35,10 +38,10 @@ class SmoothMarginEstimator(AbstractMarginEstimator): def _fit(self): maxima_gev = self.dataset.maxima_gev(split=self.train_split) - df_coordinates_spatial = self.dataset.coordinates.df_spatial_coordinates(self.train_split) - df_coordinates_temporal = self.dataset.coordinates.df_temporal_coordinates(self.train_split) + df_coordinates_spat = self.dataset.coordinates.df_spatial_coordinates(self.train_split) + df_coordinates_temp = self.dataset.coordinates.df_temporal_coordinates(self.train_split) self._result_from_fit = self.margin_model.fitmargin_from_maxima_gev(maxima_gev=maxima_gev, - df_coordinates_spatial=df_coordinates_spatial, - df_coordinates_temporal=df_coordinates_temporal) + df_coordinates_spat=df_coordinates_spat, + df_coordinates_temp=df_coordinates_temp) self.extract_fitted_models_from_fitted_params(self.margin_model.margin_function_start_fit, self.fitted_values) assert isinstance(self.margin_function_fitted, AbstractMarginFunction) diff --git a/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py b/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py index 9016613e718e26c6a25939c815cb674067f7398b..b749d3f746e727a1141da555653eac31deaf7fba 100644 --- a/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py +++ b/extreme_estimator/estimator/max_stable_estimator/abstract_max_stable_estimator.py @@ -23,6 +23,10 @@ class MaxStableEstimator(AbstractMaxStableEstimator): df_coordinates=self.dataset.df_coordinates(split=self.train_split)) self.max_stable_params_fitted = self.fitted_values + def scalars(self, true_max_stable_params: dict): + error = self._error(true_max_stable_params) + return {**error, **self.additional_information} + def _error(self, true_max_stable_params: dict): absolute_errors = {param_name: np.abs(param_true_value - self.max_stable_params_fitted[param_name]) for param_name, param_true_value in true_max_stable_params.items()} diff --git a/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py b/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py index 0fa0e34b4d756cf378ba73143c724ee6efc79b7e..1e77a4ea42be0516f77e79603284081dadf3f30c 100644 --- a/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py +++ b/extreme_estimator/extreme_models/margin_model/smooth_margin_model.py @@ -57,18 +57,18 @@ class LinearMarginModel(AbstractMarginModel): params[(gev_param_name, dim)] = coef return cls(coordinates, params_sample=params, params_start_fit=params) - def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, df_coordinates_spatial: pd.DataFrame, - df_coordinates_temporal: pd.DataFrame) -> ResultFromFit: + def fitmargin_from_maxima_gev(self, maxima_gev: np.ndarray, df_coordinates_spat: pd.DataFrame, + df_coordinates_temp: pd.DataFrame) -> ResultFromFit: # The reshaping on the line below is only valid if we have a single observation per spatio-temporal point if maxima_gev.shape[1] == 1: - maxima_gev = maxima_gev.reshape([len(df_coordinates_temporal), len(df_coordinates_spatial)]) + maxima_gev = maxima_gev.reshape([len(df_coordinates_temp), len(df_coordinates_spat)]) data = np.transpose(maxima_gev) fit_params = get_margin_formula(self.margin_function_start_fit.form_dict) # Covariables - covariables = get_coord(df_coordinates=df_coordinates_spatial) - fit_params['temp.cov'] = get_coord(df_coordinates=df_coordinates_temporal) + covariables = get_coord(df_coordinates=df_coordinates_spat) + fit_params['temp.cov'] = get_coord(df_coordinates=df_coordinates_temp) # Start parameters coef_dict = self.margin_function_start_fit.coef_dict