Commit 32c3d6aa authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[projections] fix np.nan issue, by removing models with undedefined parameters...

[projections] fix np.nan issue, by removing models with undedefined parameters for the coordinate of interest.
parent 8515b9b4
No related merge requests found
Showing with 15 additions and 12 deletions
+15 -12
......@@ -59,13 +59,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
# Load one fold fit
self.massif_name_to_massif_altitudes = {}
# Multiprocess
multiprocessing = False
if multiprocessing:
with Pool(NB_CORES) as p:
one_fold_fit_list = p.map(self.fit_one_fold, self.massif_names)
else:
one_fold_fit_list = [self.fit_one_fold(massif_name) for massif_name in self.massif_names]
one_fold_fit_list = [self.fit_one_fold(massif_name) for massif_name in self.massif_names]
self._massif_name_to_one_fold_fit = {m: o for m, o in zip(self.massif_names, one_fold_fit_list) if
o is not None}
......@@ -153,6 +147,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
print("shape to large > 0.5, thus removing std that are infinite")
massif_name_to_value = {m: v for m, v in massif_name_to_value.items()
if not np.isinf(v)}
# todo: i could remove here potential undefined parameters
# Store it
self._method_name_and_order_to_massif_name_to_value[c] = massif_name_to_value
return self._method_name_and_order_to_massif_name_to_value[c]
......
......@@ -69,6 +69,8 @@ class OneFoldFit(object):
self.model_class_to_estimator = {}
for model_class in models_classes:
self.model_class_to_estimator[model_class] = self.fitted_linear_margin_estimator(model_class, self.dataset)
# Compute sorted estimators indirectly
_ = self.has_at_least_one_valid_model
# Best estimator definition
self.best_estimator_class_for_total_aic = None
......@@ -145,7 +147,11 @@ class OneFoldFit(object):
def sorted_estimators(self):
estimators = list(self.model_class_to_estimator.values())
if self.remove_physically_implausible_models:
# Remove wrong shape
estimators = [e for e in estimators if -0.5 < self._compute_shape_for_reference_altitude(e) < 0.5]
# Remove models with undefined parameters for the coordinate of interest
coordinate = np.array([self.altitude_group.reference_altitude, self.last_year])
estimators = [e for e in estimators if not e.function_from_fit.get_params(coordinate).has_undefined_parameters]
if len(estimators) == 0:
print(self.massif_name, " has only implausible models")
......
......@@ -44,21 +44,22 @@ def main():
set_seed_for_test()
AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2
fast = None
fast = False
if fast is None:
massif_names = None
gcm_rcm_couples = gcm_rcm_couples[:5]
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
altitudes_list = altitudes_for_groups[:]
altitudes_list = altitudes_for_groups[:1]
elif fast:
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
massif_names = None
gcm_rcm_couples = ('CNRM-CM5', 'CCLM4-8-17')
gcm_rcm_couples = [('EC-EARTH', 'RACMO22E')]
altitudes_list = altitudes_for_groups[:1]
else:
massif_names = None
altitudes_list = altitudes_for_groups[:]
assert isinstance(gcm_rcm_couples, list)
start = time.time()
main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ensemble_fit_class, scenario,
temporal_covariate_for_fit)
......@@ -71,7 +72,7 @@ def main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ense
temporal_covariate_for_fit):
assert isinstance(altitudes_list, List)
assert isinstance(altitudes_list[0], List)
gof_test = True
gof_test = False
print('Goodness of fit test ?', gof_test)
print('Covariate is {}'.format(temporal_covariate_for_fit))
for study_class in study_classes:
......
......@@ -83,8 +83,9 @@ class MetaVisualizerForProjectionEnsemble(object):
with_significance = False
# Individual plots
for independent_ensemble_fit in self.ensemble_fits(IndependentEnsembleFit):
print(independent_ensemble_fit)
for c, v in independent_ensemble_fit.gcm_rcm_couple_to_visualizer.items():
print(c)
print(c, v.altitude_group)
v.plot_moments()
# Aggregated at gcm_rcm_level plots
for gcm_rcm_couple in self.gcm_rcm_couples:
......
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