Repository navigation
v2: handle infinite parameter bounds (PEtab 2.0 erratum E1) - #601
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #601 +/- ##
==========================================
+ Coverage 79.93% 80.14% +0.21%
==========================================
Files 70 70
Lines 8362 8431 +69
Branches 1519 1545 +26
==========================================
+ Hits 6684 6757 +73
+ Misses 1188 1183 -5
- Partials 490 491 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f73091a to
799768f
Compare
| raise ValueError( | ||
| "The default uniform distribution is undefined for estimated " | ||
| "parameters with infinite or missing bounds and no prior: " | ||
| f"{unbounded}." | ||
| ) |
There was a problem hiding this comment.
Maybe, "Proper priors are required and must be specified for estimated parameters with infinite or missing bounds. Affected parameters: {unbounded}"?
There was a problem hiding this comment.
This error message is used for both MAP and MLE problems, so I think it would be incorrect to ask for proper priors. I can distinguish the two cases though.
| """Create 2D array with starting points for optimization""" | ||
| priors = self.get_priors() | ||
| return np.vstack([p.sample(n_starts) for p in priors.values()]).T | ||
| def sample_parameter_startpoints(self, n_starts: int = 100) -> np.ndarray: |
There was a problem hiding this comment.
Not sure what kwargs was for, but removing them would be a breaking changes?
There was a problem hiding this comment.
[...] and no longer accepts arbitrary keyword arguments. These were a leftover from copying the v1 method, where they are forwarded to petab.v1.sampling.sample_parameter_startpoints; in v2 they have been silently ignored since #380, so nothing should depend on them.
Technically, you are right, but **kwargs was just useless copypasta.
| assert sp.shape == (n_starts, 2) | ||
|
|
||
|
|
||
| def test_sample_startpoints_ml(): |
There was a problem hiding this comment.
Test that the samples match the expected distribution, and that the bounds are (in)valid samples (distribution-specific)?
There was a problem hiding this comment.
The actual sampling is tested in test_sample_matches_pdf (https://github.com/dweindl/libpetab-python/blob/799768fe80db62e1cac47d702bfa72c270457b9e/tests/v1/test_distributions.py#L44), untouched here. I don't think repeating it here would add much.
There was a problem hiding this comment.
Added an additional bound check there.
PEtab 2.0.0 erratum E1 allows `lowerBound=-inf` and `upperBound=inf`. If any estimated parameter has a prior, estimated parameters with infinite bounds require an explicit proper prior, since the default `uniform(lowerBound, upperBound)` prior would be improper. * `Parameter.lb` must be finite or `-inf`, `Parameter.ub` finite or `inf`. Errors refer to the `lowerBound`/`upperBound` columns. * `CheckPriorDistribution` reports estimated parameters with infinite bounds and no prior if the problem has a MAP objective. * `Problem.get_startpoint_distributions` raises a `ValueError` naming estimated parameters with infinite or missing bounds and no prior, instead of returning improper uniform distributions. `get_priors` delegates to it for MAP problems. * `Problem.sample_parameter_startpoints` used `get_priors`, which is empty for maximum likelihood problems, and thus failed. It now uses `get_startpoint_distributions`, returns an `(n_starts, 0)` array if no parameters are estimated, and no longer accepts and ignores arbitrary keyword arguments. * Test that prior truncation at bounds matching the prior's domain is a no-op, and that one-sided infinite bounds still truncate. Closes PEtab-dev#565. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
799768f to
60973cb
Compare
Implements PEtab 2.0.0 erratum E1:
lowerBoundmay be-inf,upperBoundmay beinf, and if any estimated parameter has a prior, estimated parameters with infinite bounds need an explicit proper prior.Parameter.lbmust be finite or-inf,Parameter.ubfinite orinf. Previously, e.g.lb=ub=infwas accepted.CheckPriorDistributionreports estimated parameters with infinite bounds and no prior if the problem has a MAP objective. Explicit improperuniform/log-uniformpriors (e.g., with infinite prior parameters) are already rejected via Reject improperUniformandLogUniformdistributions #604.Problem.get_priorsandProblem.get_startpoint_distributionsraise aValueErrornaming the parameters with infinite (or missing) bounds and no prior, instead of the generic error fromUniform(since Reject improperUniformandLogUniformdistributions #604) or, before that, an improperUniformthat failed on sampling. I chose this over adding a fallback-distribution argument to keep the API unchanged; a fallback could be added later if needed.Problem.sample_parameter_startpointsusedget_priors, which is empty for maximum likelihood problems, and thus always failed for them. It now usesget_startpoint_distributions(identical toget_priorsfor MAP problems). It also returns an(n_starts, 0)array if no parameters are estimated, and no longer accepts arbitrary keyword arguments. These were a leftover from copying the v1 method, where they are forwarded topetab.v1.sampling.sample_parameter_startpoints; in v2 they have been silently ignored since v2: Startpoint sampling #380, so nothing should depend on them.log-normalon[0, inf]) is a no-op, and that one-sided infinite bounds still truncate at the finite bound.Infinite nominal values (erratum E3) were already accepted; no change.
Closes #565.
🤖 Generated with Claude Code