Skip to content

Commit 68144a0

Browse files
authored
Validator: check for positive bounds for log-scaled parameter (#278)
Check the parameter table for positive bounds for log-scaled estimated parameters that don't have an explicit intialization prior or that have initialPriorType=parameterScaleUniform. See discussion in #259 Supersedes and closes #259
1 parent f567a1e commit 68144a0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

petab/lint.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,17 @@ def check_parameter_bounds(parameter_df: pd.DataFrame) -> None:
558558
f"Bounds for {row[PARAMETER_SCALE]} scaled parameter "
559559
f"{ row.name} must be positive."
560560
)
561+
if (
562+
row.get(PARAMETER_SCALE, LIN) in [LOG, LOG10]
563+
and (row[LOWER_BOUND] == 0.0 or row[UPPER_BOUND] == 0.0)
564+
and not row.get(INITIALIZATION_PRIOR_TYPE)
565+
):
566+
raise AssertionError(
567+
f"Bounds for {row[PARAMETER_SCALE]} scaled parameter "
568+
f"{row.name} must be positive if no "
569+
f"{INITIALIZATION_PRIOR_TYPE} is provided. "
570+
"Cannot sample from unbounded interval."
571+
)
561572

562573

563574
def assert_parameter_prior_type_is_valid(parameter_df: pd.DataFrame) -> None:
@@ -636,6 +647,19 @@ def assert_parameter_prior_parameters_are_valid(
636647
f"{PARAMETER_SEPARATOR}par2' for all prior types)."
637648
)
638649

650+
# we can't sample uniformly from [log(0)=-inf, ...]
651+
if (
652+
type_col == INITIALIZATION_PRIOR_TYPE
653+
and row.get(type_col, "") == PARAMETER_SCALE_UNIFORM
654+
and row.get(PARAMETER_SCALE, LIN) in [LOG, LOG10]
655+
and (pars[0] == 0.0 or pars[1] == 0.0)
656+
):
657+
raise AssertionError(
658+
f"{prior_par_cols} for {row[PARAMETER_SCALE]} scaled "
659+
f"parameter {row.name} must be positive if "
660+
f"{type_col}={PARAMETER_SCALE_UNIFORM}."
661+
)
662+
639663

640664
def assert_parameter_estimate_is_boolean(parameter_df: pd.DataFrame) -> None:
641665
"""

tests/test_lint.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,3 +642,18 @@ def test_parameter_ids_are_unique():
642642
parameter_df.index = ["par0", "par1"]
643643
parameter_df.index.name = "parameterId"
644644
lint.check_parameter_df(parameter_df)
645+
646+
647+
def test_check_positive_bounds_for_scaled_parameters():
648+
parameter_df = pd.DataFrame(
649+
{
650+
PARAMETER_ID: ["par"],
651+
PARAMETER_SCALE: [LOG10],
652+
ESTIMATE: [1],
653+
LOWER_BOUND: [0.0],
654+
UPPER_BOUND: [1],
655+
}
656+
).set_index(PARAMETER_ID)
657+
658+
with pytest.raises(AssertionError, match="positive"):
659+
lint.check_parameter_df(parameter_df)

0 commit comments

Comments
 (0)