Repository navigation
Commit 402393d
petab1to2: fix conversion of logNormal, logLaplace and parameterScaleUniform priors (#536)
Fixes three prior-conversion bugs in the PEtab v1 -> v2 converter
(`update_prior` in `v1v2_parameter_df`). They turned up while verifying
#535.
### Mappings
| v1 `objectivePriorType` | `parameterScale` | v1 parameters | before |
now |
|---|---|---|---|---|
| `logNormal` / `logLaplace` | any | `mu;sigma` | `logNormal` /
`logLaplace` verbatim → pydantic `ValidationError` when building
`v2.Parameter` | `log-normal` / `log-laplace`, `mu;sigma` |
| `parameterScaleUniform` | `log` | `a;b` (ln-space) | `log-uniform`
with `a;b` → prior pdf is NaN | `log-uniform` with `exp(a);exp(b)`,
clipped to the bounds |
| `parameterScaleUniform` | `log10` | `a;b` (log10-space) |
`NotImplementedError` (`log10-uniform`) | `log-uniform` with
`10^a;10^b`, clipped to the bounds |
Why these are correct:
1. **logNormal / logLaplace.** In v1 these are always based on the
natural logarithm, whatever the `parameterScale` (`Prior` maps
`(LOG_NORMAL, _)` to `Normal(..., log=True)`). That is the same
convention as v2 `log-normal` / `log-laplace`, so only the name changes.
2. **and 3. parameterScaleUniform on log/log10.** If ln(x) (or log10(x))
is uniform on [a, b], then x is log-uniform on [e^a, e^b] (or [10^a,
10^b]). v2 `log-uniform` takes the bounds of x itself as parameters.
`Parameter.prior_dist` notes this ("Mind the different interpretation of
distribution parameters for `Uniform(..., log=True)` and `LogUniform`").
So the parameters are transformed back to linear scale. Like v1's
`Prior`, the scaled interval [a, b] is first clipped to the scaled
parameter bounds, and the linear bounds are used for clipped endpoints.
Within the bounds this gives the same truncated density, and it avoids
overflow for valid but wide intervals such as log10 `-400;400`.
Missing `objectivePriorParameters` for `parameterScaleUniform` stay
missing, so `update_prior_pars` still fills in `lowerBound;upperBound`.
In v1 they default to the scaled bounds, which is the same distribution.
Not changed: a missing `objectivePriorType` (v1 default
`parameterScaleUniform`) still converts to `uniform` with
`lowerBound;upperBound` on any scale. On log-scaled parameters the
density differs from v1's log-uniform default. But this matches the v2
spec's default for parameters without a prior, and it keeps the optimum
of v1 problems that have no priors.
### Verification
For each case I compared `petab.v1.priors.Prior.from_par_dict(row,
type_="objective").pdf(x)` with the converted
`v2.Parameter.prior_dist.pdf(x)` on a grid spanning the bounds [1e-3,
1e2]. This included prior ranges inside the bounds, wider than the
bounds (truncation) and partly outside them. All agree to rel. 1e-12.
Tests: `test_petab1to2_parameter_scale_priors` (from #535) is now
`test_petab1to2_priors`. It is parametrized over prior parameters and
adds the cases above: log/log10 `parameterScaleUniform` within bounds,
exceeding bounds (including `-400;400` / `-1000;1000`, which overflow
when unscaled), and with missing parameters, plus
`logNormal`/`logLaplace` on `lin` and `log10` scale. 11 of the new cases
fail on the previous converter code, and all pass with this change.
`pytest tests/v2` passes (141 passed), including
`test_benchmark_collection` with `benchmark_models_petab` installed.
`pre-commit` (ruff, ruff-format) is clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 37b7025 commit 402393d
2 files changed
Lines changed: 59 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
516 | 517 | | |
517 | 518 | | |
518 | 519 | | |
519 | | - | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
520 | 550 | | |
521 | 551 | | |
522 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
207 | 224 | | |
208 | 225 | | |
209 | | - | |
210 | | - | |
| 226 | + | |
| 227 | + | |
211 | 228 | | |
212 | | - | |
213 | | - | |
| 229 | + | |
| 230 | + | |
214 | 231 | | |
215 | 232 | | |
216 | 233 | | |
217 | | - | |
| 234 | + | |
218 | 235 | | |
219 | 236 | | |
220 | 237 | | |
| |||
0 commit comments