Commit ea4fd952 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[MAX STABLE] add starting point for non stationary full estimator. fix display...

[MAX STABLE] add starting point for non stationary full estimator. fix display in non stationary trends
parent a05d4d01
No related merge requests found
Showing with 13 additions and 18 deletions
+13 -18
...@@ -81,16 +81,12 @@ class AbstractNonStationaryTrendTest(object): ...@@ -81,16 +81,12 @@ class AbstractNonStationaryTrendTest(object):
mu1_trends = [self.get_mu1(starting_point=year) for year in years] mu1_trends = [self.get_mu1(starting_point=year) for year in years]
ax2 = ax.twinx() ax2 = ax.twinx()
color_mu1 = 'c' color_mu1 = 'c'
ax.plot(years, mu1_trends, color_mu1 + 'o-') ax2.plot(years, mu1_trends, color_mu1 + 'o-')
ax2.set_ylabel('mu1 parameter', color=color_mu1) ax2.set_ylabel('mu1 parameter', color=color_mu1)
ax.set_xlabel('starting year for the linear trend of mu1') ax.set_xlabel('starting year for the linear trend of mu1')
align_yaxis_on_zero(ax, ax2) align_yaxis_on_zero(ax, ax2)
title = self.display_name title = self.display_name
first = mu1_trends[0]
last = mu1_trends[-1]
title += '\n mu1: first {}\nlast {}'.format(first, last)
title += '; equals? {}'.format(first == last)
ax.set_title(title) ax.set_title(title)
ax.legend() ax.legend()
......
...@@ -56,12 +56,21 @@ class FullEstimatorInASingleStepWithSmoothMargin(AbstractFullEstimator): ...@@ -56,12 +56,21 @@ class FullEstimatorInASingleStepWithSmoothMargin(AbstractFullEstimator):
def margin_function_start_fit(self): def margin_function_start_fit(self):
return self.linear_margin_model.margin_function_start_fit return self.linear_margin_model.margin_function_start_fit
@property
def df_coordinates_spat(self):
return self.dataset.coordinates.df_spatial_coordinates(self.train_split)
@property
def df_coordinates_temp(self):
df_coordinates_temp = self.dataset.coordinates.df_temporal_coordinates(self.train_split)
return self.linear_margin_model.add_starting_temporal_point(df_coordinates_temp)
def _fit(self): def _fit(self):
# Estimate both the margin and the max-stable structure # Estimate both the margin and the max-stable structure
self._result_from_fit = self.max_stable_model.fitmaxstab( self._result_from_fit = self.max_stable_model.fitmaxstab(
data_gev=self.dataset.maxima_gev_for_spatial_extremes_package(self.train_split), data_gev=self.dataset.maxima_gev_for_spatial_extremes_package(self.train_split),
df_coordinates_spat=self.dataset.coordinates.df_spatial_coordinates(self.train_split), df_coordinates_spat=self.df_coordinates_spat,
df_coordinates_temp=self.dataset.coordinates.df_temporal_coordinates(self.train_split), df_coordinates_temp=self.df_coordinates_temp,
fit_marge=True, fit_marge=True,
fit_marge_form_dict=self.linear_margin_model.margin_function_start_fit.form_dict, fit_marge_form_dict=self.linear_margin_model.margin_function_start_fit.form_dict,
margin_start_dict=self.linear_margin_model.margin_function_start_fit.coef_dict margin_start_dict=self.linear_margin_model.margin_function_start_fit.coef_dict
......
...@@ -32,6 +32,7 @@ class LinearMarginEstimator(AbstractMarginEstimator): ...@@ -32,6 +32,7 @@ class LinearMarginEstimator(AbstractMarginEstimator):
maxima_gev_specialized = self.dataset.maxima_gev_for_spatial_extremes_package(self.train_split) maxima_gev_specialized = self.dataset.maxima_gev_for_spatial_extremes_package(self.train_split)
df_coordinates_spat = self.dataset.coordinates.df_spatial_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) df_coordinates_temp = self.dataset.coordinates.df_temporal_coordinates(self.train_split)
df_coordinates_temp = self.margin_model.add_starting_temporal_point(df_coordinates_temp)
self._result_from_fit = self.margin_model.fitmargin_from_maxima_gev(data=maxima_gev_specialized, self._result_from_fit = self.margin_model.fitmargin_from_maxima_gev(data=maxima_gev_specialized,
df_coordinates_spat=df_coordinates_spat, df_coordinates_spat=df_coordinates_spat,
df_coordinates_temp=df_coordinates_temp) df_coordinates_temp=df_coordinates_temp)
......
...@@ -38,9 +38,6 @@ class ParametricMarginModel(AbstractMarginModel, ABC): ...@@ -38,9 +38,6 @@ class ParametricMarginModel(AbstractMarginModel, ABC):
df_coordinates_temp: pd.DataFrame) -> ResultFromFit: df_coordinates_temp: pd.DataFrame) -> ResultFromFit:
assert data.shape[1] == len(df_coordinates_spat) assert data.shape[1] == len(df_coordinates_spat)
# Modify df_coordinates_temp
df_coordinates_temp = self.add_starting_temporal_point(df_coordinates_temp)
# Margin formula for fitspatgev # Margin formula for fitspatgev
fit_params = get_margin_formula(self.margin_function_start_fit.form_dict) fit_params = get_margin_formula(self.margin_function_start_fit.form_dict)
......
...@@ -99,14 +99,6 @@ class TestMaxStableTemporal(unittest.TestCase): ...@@ -99,14 +99,6 @@ class TestMaxStableTemporal(unittest.TestCase):
# Create two different estimators # Create two different estimators
estimator1 = self.fit_non_stationary_estimator(starting_point=3) estimator1 = self.fit_non_stationary_estimator(starting_point=3)
estimator2 = self.fit_non_stationary_estimator(starting_point=20) estimator2 = self.fit_non_stationary_estimator(starting_point=20)
for starting_point in range(3, 20):
estimator = self.fit_non_stationary_estimator(starting_point=starting_point)
print(estimator.margin_function_fitted.starting_point)
print(estimator.margin_function_fitted.coef_dict)
print(estimator.margin_function_fitted.mu0)
print(estimator.margin_function_fitted.mu1_temporal_trend)
mu1_estimator1 = estimator1.margin_function_fitted.mu1_temporal_trend mu1_estimator1 = estimator1.margin_function_fitted.mu1_temporal_trend
mu1_estimator2 = estimator2.margin_function_fitted.mu1_temporal_trend mu1_estimator2 = estimator2.margin_function_fitted.mu1_temporal_trend
self.assertNotEqual(mu1_estimator1, mu1_estimator2) self.assertNotEqual(mu1_estimator1, mu1_estimator2)
......
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