From 8979e8811b9e2488932dd2c9404fc728b07f2700 Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:51:12 +0200 Subject: [PATCH 1/8] Update ensemble.py Add an option for computing cutoff values for pointwise confidence regions. Needed for ensemble simulations. --- pypesto/ensemble/ensemble.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index 178c1c2b1..92d30a017 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -1204,7 +1204,11 @@ def get_percentile_label(percentile: Union[float, int, str]) -> str: return f'{PERCENTILE} {percentile}' -def calculate_cutoff(result: Result, percentile: float = 0.95): +def calculate_cutoff( + result: Result, + percentile: float = 0.95, + cr_option: string = "simultaneous", +): """ Calculate the cutoff of the ensemble. @@ -1220,6 +1224,10 @@ def calculate_cutoff(result: Result, percentile: float = 0.95): The percentile of the chi^2 distribution. Between 0 and 100. Higher values will result in a more lax cutoff. If the value is greater than 100, the cutoff will be returned as np.inf. + cr_option: + The type of confidence region, which determines the degree of freedom of + the chi^2 distribution for the cutoff value. It can take "simultaneous" or + "pointwise". Returns ------- @@ -1230,10 +1238,20 @@ def calculate_cutoff(result: Result, percentile: float = 0.95): f"percentile={percentile} is too large. Choose " f"0<=percentile<=100." ) + if cr_option not in ["simultaneous", "pointwise"]: + raise ValueError( + f"Confidence region must be either simultaneous + or pointwise." + ) + # optimal point as base: fval_opt = result.optimize_result[0].fval - # degrees of freedom is equal to the number of parameters - df = result.problem.dim - range = chi2.ppf(q=percentile / 100, df=df) + if cr_option == "simultaneous": + # degrees of freedom is equal to the number of parameters + df = result.problem.dim + elif cr_option == "pointwise": + # degrees of freedom is equal to 1 + df = 1 + range = chi2.ppf(q=percentile / 100, df=df) return fval_opt + range From e2a052e0123814ebce1b14bb49215fc2bdc00c50 Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:56:05 +0200 Subject: [PATCH 2/8] Update ensemble.py Fix string literal. --- pypesto/ensemble/ensemble.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index 92d30a017..cb98b0943 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -1240,8 +1240,8 @@ def calculate_cutoff( ) if cr_option not in ["simultaneous", "pointwise"]: raise ValueError( - f"Confidence region must be either simultaneous - or pointwise." + f"Confidence region must be either simultaneous " + f"or pointwise." ) # optimal point as base: From b7984181c0b6e26076de5cbc3f22853c7eb3f42b Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:58:10 +0200 Subject: [PATCH 3/8] Style changes ensemble.py Change style of string representation. --- pypesto/ensemble/ensemble.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index cb98b0943..2d36569b5 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -1207,7 +1207,7 @@ def get_percentile_label(percentile: Union[float, int, str]) -> str: def calculate_cutoff( result: Result, percentile: float = 0.95, - cr_option: string = "simultaneous", + cr_option: string = 'simultaneous', ): """ Calculate the cutoff of the ensemble. @@ -1226,8 +1226,8 @@ def calculate_cutoff( than 100, the cutoff will be returned as np.inf. cr_option: The type of confidence region, which determines the degree of freedom of - the chi^2 distribution for the cutoff value. It can take "simultaneous" or - "pointwise". + the chi^2 distribution for the cutoff value. It can take 'simultaneous' or + 'pointwise'. Returns ------- @@ -1246,10 +1246,10 @@ def calculate_cutoff( # optimal point as base: fval_opt = result.optimize_result[0].fval - if cr_option == "simultaneous": + if cr_option == 'simultaneous': # degrees of freedom is equal to the number of parameters df = result.problem.dim - elif cr_option == "pointwise": + elif cr_option == 'pointwise': # degrees of freedom is equal to 1 df = 1 From b760cfd942e867e72d920816c2ef62c3bfd8b30f Mon Sep 17 00:00:00 2001 From: Doresic Date: Fri, 6 Oct 2023 14:19:24 +0200 Subject: [PATCH 4/8] Fix string name & black --- pypesto/ensemble/ensemble.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index 2d36569b5..6818267ab 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -1205,9 +1205,9 @@ def get_percentile_label(percentile: Union[float, int, str]) -> str: def calculate_cutoff( - result: Result, + result: Result, percentile: float = 0.95, - cr_option: string = 'simultaneous', + cr_option: str = 'simultaneous', ): """ Calculate the cutoff of the ensemble. @@ -1240,8 +1240,7 @@ def calculate_cutoff( ) if cr_option not in ["simultaneous", "pointwise"]: raise ValueError( - f"Confidence region must be either simultaneous " - f"or pointwise." + "Confidence region must be either simultaneous or pointwise." ) # optimal point as base: From 727056fa196338e3802816f6ef65dbc4b519a19a Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:48:58 +0200 Subject: [PATCH 5/8] Update C.py Add simultaneous and pointwise strings for the choice of confidence regions. --- pypesto/C.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pypesto/C.py b/pypesto/C.py index 61f4eb449..bedac2b93 100644 --- a/pypesto/C.py +++ b/pypesto/C.py @@ -35,6 +35,9 @@ ENSEMBLE_TYPE = 'ensemble_type' PREDICTIONS = 'predictions' +SIMULTANEOUS = 'simultaneous' +POINTWISE = 'pointwise + LOWER_BOUND = 'lower_bound' UPPER_BOUND = 'upper_bound' PREEQUILIBRATION_CONDITION_ID = 'preequilibrationConditionId' From 686e4a3c95099ac3fb5fc7dffe52c7c1e71aa09b Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:51:19 +0200 Subject: [PATCH 6/8] Update strings ensemble.py Changed strings to constants stored in C.py. --- pypesto/ensemble/ensemble.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index 6818267ab..0f2fbd16a 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -45,6 +45,8 @@ X_VECTOR, EnsembleType, ModeType, + SIMULTANEOUS, + POINTWISE ) from ..engine import ( Engine, @@ -1207,7 +1209,7 @@ def get_percentile_label(percentile: Union[float, int, str]) -> str: def calculate_cutoff( result: Result, percentile: float = 0.95, - cr_option: str = 'simultaneous', + cr_option: str = SIMULTANEOUS, ): """ Calculate the cutoff of the ensemble. @@ -1238,17 +1240,17 @@ def calculate_cutoff( f"percentile={percentile} is too large. Choose " f"0<=percentile<=100." ) - if cr_option not in ["simultaneous", "pointwise"]: + if cr_option not in [SIMULTANEOUS, POINTWISE]: raise ValueError( "Confidence region must be either simultaneous or pointwise." ) # optimal point as base: fval_opt = result.optimize_result[0].fval - if cr_option == 'simultaneous': + if cr_option == SIMULTANEOUS: # degrees of freedom is equal to the number of parameters df = result.problem.dim - elif cr_option == 'pointwise': + elif cr_option == POINTWISE: # degrees of freedom is equal to 1 df = 1 From 4e704c82a3e9855519877690b1787e6ef578366d Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:55:40 +0200 Subject: [PATCH 7/8] Fix typo C.py Fix typo. --- pypesto/C.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypesto/C.py b/pypesto/C.py index bedac2b93..c5b65452a 100644 --- a/pypesto/C.py +++ b/pypesto/C.py @@ -36,7 +36,7 @@ PREDICTIONS = 'predictions' SIMULTANEOUS = 'simultaneous' -POINTWISE = 'pointwise +POINTWISE = 'pointwise' LOWER_BOUND = 'lower_bound' UPPER_BOUND = 'upper_bound' From 656b891c1037f9a9d82b58bfa5a18374c4372f80 Mon Sep 17 00:00:00 2001 From: Vincent Wieland <90847066+vwiela@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:05:48 +0200 Subject: [PATCH 8/8] Style and quality ensemble.py Use black for consistent code style. --- pypesto/ensemble/ensemble.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pypesto/ensemble/ensemble.py b/pypesto/ensemble/ensemble.py index 0f2fbd16a..d2ab53df9 100644 --- a/pypesto/ensemble/ensemble.py +++ b/pypesto/ensemble/ensemble.py @@ -29,12 +29,14 @@ OUTPUT, OUTPUT_SENSI, PERCENTILE, + POINTWISE, PREDICTION_ARRAYS, PREDICTION_ID, PREDICTION_RESULTS, PREDICTION_SUMMARY, PREDICTIONS, PREDICTOR, + SIMULTANEOUS, STANDARD_DEVIATION, SUMMARY, TIMEPOINTS, @@ -45,8 +47,6 @@ X_VECTOR, EnsembleType, ModeType, - SIMULTANEOUS, - POINTWISE ) from ..engine import ( Engine,