Skip to content

Commit

Permalink
Update ensemble.py (#1124)
Browse files Browse the repository at this point in the history
* Update ensemble.py

Add an option for computing cutoff values for pointwise confidence regions. Needed for ensemble simulations.

* Update ensemble.py

Fix string literal.

* Style changes ensemble.py

Change style of string representation.

* Fix string name & black

* Update C.py

Add simultaneous and pointwise strings for the choice of confidence regions.

* Update strings ensemble.py

Changed strings to constants stored in C.py.

* Fix typo C.py

Fix typo.

* Style and quality ensemble.py

Use black for consistent code style.

---------

Co-authored-by: Doresic <domagoj.doresic@gmail.com>
Co-authored-by: Paul Jonas Jost <70631928+PaulJonasJost@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent 8fe602a commit 2f0f50d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pypesto/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 23 additions & 4 deletions pypesto/ensemble/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
OUTPUT,
OUTPUT_SENSI,
PERCENTILE,
POINTWISE,
PREDICTION_ARRAYS,
PREDICTION_ID,
PREDICTION_RESULTS,
PREDICTION_SUMMARY,
PREDICTIONS,
PREDICTOR,
SIMULTANEOUS,
STANDARD_DEVIATION,
SUMMARY,
TIMEPOINTS,
Expand Down Expand Up @@ -1204,7 +1206,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: str = SIMULTANEOUS,
):
"""
Calculate the cutoff of the ensemble.
Expand All @@ -1220,6 +1226,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
-------
Expand All @@ -1230,10 +1240,19 @@ 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(
"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

0 comments on commit 2f0f50d

Please sign in to comment.