diff --git a/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R b/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R index adeab5ac7a2a1f321e5da5a13e063dc74feb19bd..74d853e86abf6ecc88efac394ea4def6524131d9 100644 --- a/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R +++ b/extreme_fit/distribution/gev/main_fevd_mle_two_covariates.R @@ -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, 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= ~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) # Some display for the results 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 33a1d3b6bb087b7b92cffb469d78f80c6d295510..b28219a4e2fe3d6fc03e6fd2d4c7c62dcf325f39 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 @@ -119,8 +119,6 @@ class AbstractTemporalLinearMarginModel(LinearMarginModel): df = df_coordinates_temp else: df = pd.concat([df_coordinates_spat, df_coordinates_temp], axis=1) - print(df.shape) - print(df.head()) y = get_coord_df(df) # Disable the use of log sigma parametrization diff --git a/extreme_fit/model/margin_model/polynomial_margin_model/polynomial_margin_model.py b/extreme_fit/model/margin_model/polynomial_margin_model/polynomial_margin_model.py index c5066d7210d4f5cda931dfe1014fa9730555ee2e..838043c08bbe9d19fef34b1da78f6ab59bfb703f 100644 --- a/extreme_fit/model/margin_model/polynomial_margin_model/polynomial_margin_model.py +++ b/extreme_fit/model/margin_model/polynomial_margin_model/polynomial_margin_model.py @@ -57,7 +57,7 @@ class PolynomialMarginModel(AbstractTemporalLinearMarginModel): for dim, max_degree in param_name_to_list_dim_and_degree.get(param_name, []): degree_to_coef = {} 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 # print(degree_to_coef, param_name) # if len(degree_to_coef) == 0: diff --git a/extreme_fit/model/utils.py b/extreme_fit/model/utils.py index 0047c85fa43ed68d99b34213c1aebf06ce429045..1b6e82d34622c7252dfeb29ece1ffdc386f1da88 100644 --- a/extreme_fit/model/utils.py +++ b/extreme_fit/model/utils.py @@ -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): parameters['start'] = r.list(**start_dict) 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: continue else: @@ -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, - **parameters) -> robjects.ListVector: + **parameters) -> robjects.ListVector: if OptimizationConstants.USE_MAXIT: # Add optimization parameters optim_dict = {'maxit': maxit} @@ -170,17 +171,21 @@ def get_margin_formula_spatial_extreme(fit_marge_form_dict) -> Dict: return margin_formula -def old_coef_name_to_new_coef_name(): +def new_coef_name_to_old_coef_names(): return { - 'temp.form.loc': 'location.fun', - 'temp.form.scale': 'scale.fun', - 'temp.form.shape': 'shape.fun', + 'location.fun': ['loc.form', 'temp.form.loc'], + 'scale.fun': ['scale.form', 'temp.form.scale'], + 'shape.fun': ['shape.form', 'temp.form.shape'], } def get_margin_formula_extremes(fit_marge_form_dict) -> Dict: - d = old_coef_name_to_new_coef_name() - form_dict = {d[k]: ' '.join(v.split()[1:]) if v != 'NULL' else ' ~1' for k, v in fit_marge_form_dict.items()} + v_to_str = lambda v: ' '.join(v.split()[2:]) if v != 'NULL' else ' 1' + 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()} # def conversion_to_FloatVector(data):