Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator: check for positive bounds for log-scaled parameter #278

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions petab/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,17 @@ def check_parameter_bounds(parameter_df: pd.DataFrame) -> None:
f"Bounds for {row[PARAMETER_SCALE]} scaled parameter "
f"{ row.name} must be positive."
)
if (
row.get(PARAMETER_SCALE, LIN) in [LOG, LOG10]
and (row[LOWER_BOUND] == 0.0 or row[UPPER_BOUND] == 0.0)
and not row.get(INITIALIZATION_PRIOR_TYPE)
):
Comment on lines +561 to +565
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move row[UPPER_BOUND] == 0.0 above, i.e. change row[UPPER_BOUND] < 0.0 to row[UPPER_BOUND] <= 0.0 -- does not make sense to estimate something that can only take the value 0.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lb=ub is allowed so far. I'd say things that are legal but dumb shouldn't raise exceptions. Although we might want to add some optional hints for improvement at some point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me 👍 Should we check the initialization prior then, to make sure it's sampling in finite bounds?

raise AssertionError(
f"Bounds for {row[PARAMETER_SCALE]} scaled parameter "
f"{row.name} must be positive if no "
f"{INITIALIZATION_PRIOR_TYPE} is provided. "
"Cannot sample from unbounded interval."
)


def assert_parameter_prior_type_is_valid(parameter_df: pd.DataFrame) -> None:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,18 @@ def test_parameter_ids_are_unique():
parameter_df.index = ["par0", "par1"]
parameter_df.index.name = "parameterId"
lint.check_parameter_df(parameter_df)


def test_check_positive_bounds_for_scaled_parameters():
parameter_df = pd.DataFrame(
{
PARAMETER_ID: ["par"],
PARAMETER_SCALE: [LOG10],
ESTIMATE: [1],
LOWER_BOUND: [0.0],
UPPER_BOUND: [1],
}
).set_index(PARAMETER_ID)

with pytest.raises(AssertionError, match="positive"):
lint.check_parameter_df(parameter_df)