Commit 797e77d3 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[contrasting] fix polynomial_margin_model.py creation. extend the form_dict...

[contrasting] fix polynomial_margin_model.py creation. extend the form_dict for spatio temporal models.
parent e50a9c59
No related merge requests found
Showing with 15 additions and 12 deletions
+15 -12
...@@ -27,7 +27,7 @@ coord = data.frame(coord, stringsAsFactors = TRUE) ...@@ -27,7 +27,7 @@ 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, 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= ~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) # res = fevd_fixed(x_gev, data=coord, location.fun= ~sin(X) + cos(T), method='MLE', type="GEV", verbose=FALSE, use.phi=FALSE)
res = fevd_fixed(x_gev, data=coord, location.fun= ~T * X + X +T , method='MLE', type="GEV", verbose=FALSE, use.phi=FALSE) res = fevd_fixed(x_gev, data=coord, location.fun= ~poly(X, 1, raw = TRUE) + 1 , method='MLE', type="GEV", verbose=FALSE, use.phi=FALSE)
print(res) print(res)
# Some display for the results # Some display for the results
......
...@@ -119,8 +119,6 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): ...@@ -119,8 +119,6 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel):
df = df_coordinates_temp df = df_coordinates_temp
else: else:
df = pd.concat([df_coordinates_spat, df_coordinates_temp], axis=1) df = pd.concat([df_coordinates_spat, df_coordinates_temp], axis=1)
print(df.shape)
print(df.head())
y = get_coord_df(df) y = get_coord_df(df)
# Disable the use of log sigma parametrization # Disable the use of log sigma parametrization
......
...@@ -57,7 +57,7 @@ class PolynomialMarginModel(AbstractTemporalLinearMarginModel): ...@@ -57,7 +57,7 @@ class PolynomialMarginModel(AbstractTemporalLinearMarginModel):
for dim, max_degree in param_name_to_list_dim_and_degree.get(param_name, []): for dim, max_degree in param_name_to_list_dim_and_degree.get(param_name, []):
degree_to_coef = {} degree_to_coef = {}
for (param_name_loop, dim_loop, degree), coef in param_name_and_dim_and_degree_to_default_coef.items(): for (param_name_loop, dim_loop, degree), coef in param_name_and_dim_and_degree_to_default_coef.items():
if param_name == param_name_loop and dim == dim_loop: if param_name == param_name_loop and dim == dim_loop and degree <= max_degree:
degree_to_coef[degree] = coef degree_to_coef[degree] = coef
# print(degree_to_coef, param_name) # print(degree_to_coef, param_name)
# if len(degree_to_coef) == 0: # if len(degree_to_coef) == 0:
......
...@@ -90,7 +90,8 @@ def safe_run_r_estimator(function, data=None, start_dict=None, max_ratio_between ...@@ -90,7 +90,8 @@ def safe_run_r_estimator(function, data=None, start_dict=None, max_ratio_between
for _ in range(nb_tries_for_start_value): for _ in range(nb_tries_for_start_value):
parameters['start'] = r.list(**start_dict) parameters['start'] = r.list(**start_dict)
try: try:
return _safe_run_r_estimator(function, data, max_ratio_between_two_extremes_values, maxit, **parameters) return _safe_run_r_estimator(function, data, max_ratio_between_two_extremes_values, maxit,
**parameters)
except Exception: except Exception:
continue continue
else: else:
...@@ -98,7 +99,7 @@ def safe_run_r_estimator(function, data=None, start_dict=None, max_ratio_between ...@@ -98,7 +99,7 @@ def safe_run_r_estimator(function, data=None, start_dict=None, max_ratio_between
def _safe_run_r_estimator(function, data=None, max_ratio_between_two_extremes_values=10, maxit=1000000, def _safe_run_r_estimator(function, data=None, max_ratio_between_two_extremes_values=10, maxit=1000000,
**parameters) -> robjects.ListVector: **parameters) -> robjects.ListVector:
if OptimizationConstants.USE_MAXIT: if OptimizationConstants.USE_MAXIT:
# Add optimization parameters # Add optimization parameters
optim_dict = {'maxit': maxit} optim_dict = {'maxit': maxit}
...@@ -170,17 +171,21 @@ def get_margin_formula_spatial_extreme(fit_marge_form_dict) -> Dict: ...@@ -170,17 +171,21 @@ def get_margin_formula_spatial_extreme(fit_marge_form_dict) -> Dict:
return margin_formula return margin_formula
def old_coef_name_to_new_coef_name(): def new_coef_name_to_old_coef_names():
return { return {
'temp.form.loc': 'location.fun', 'location.fun': ['loc.form', 'temp.form.loc'],
'temp.form.scale': 'scale.fun', 'scale.fun': ['scale.form', 'temp.form.scale'],
'temp.form.shape': 'shape.fun', 'shape.fun': ['shape.form', 'temp.form.shape'],
} }
def get_margin_formula_extremes(fit_marge_form_dict) -> Dict: def get_margin_formula_extremes(fit_marge_form_dict) -> Dict:
d = old_coef_name_to_new_coef_name() v_to_str = lambda v: ' '.join(v.split()[2:]) if v != 'NULL' else ' 1'
form_dict = {d[k]: ' '.join(v.split()[1:]) if v != 'NULL' else ' ~1' for k, v in fit_marge_form_dict.items()} form_dict = {
k: '~' + ' + '.join(
[v_to_str(fit_marge_form_dict[e]) for e in l if e in fit_marge_form_dict])
for k, l in new_coef_name_to_old_coef_names().items()
}
return {k: robjects.Formula(v) for k, v in form_dict.items()} return {k: robjects.Formula(v) for k, v in form_dict.items()}
# def conversion_to_FloatVector(data): # def conversion_to_FloatVector(data):
......
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