Skip to content

Reject improper Uniform and LogUniform distributions - #604

Merged
dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:distributions_validate_uniform
Nov 17, 2026
Merged

dweindl merged 1 commit into
PEtab-dev:mainfrom
dweindl:distributions_validate_uniform

Conversation

@dweindl

@dweindl dweindl commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

petab.v1.distributions.Uniform accepted any limits. E.g., Uniform(0, inf) has pdf 0 and cdf nan, and fails only when sampled, with numpy's OverflowError: Range exceeds valid bounds.

Uniform now requires finite limits with low < high (on the scale of the underlying uniform distribution), and LogUniform requires 0 < low < high < inf. Both raise a ValueError otherwise.

Affected petab.v1 use: start point sampling for parameters with infinite bounds, or with lowerBound=0 and a log-scaled default parameterScaleUniform initialization prior. These already failed during sampling; they now fail when the Prior is created. low == high is also rejected, so an estimated parameter with lowerBound == upperBound and no prior can no longer be sampled (v1 and v2). None of the problems in the PEtab benchmark collection are affected.

In petab.v2, invalid uniform/log-uniform priors are still reported by CheckPriorDistribution, now with a clearer hint. If a uniform prior range does not overlap the parameter bounds, the error names the prior parameters and bounds instead of the clipped limits.

🤖 Generated with Claude Code

@dweindl dweindl self-assigned this Nov 17, 2026
@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.93%. Comparing base (3fd2a3f) to head (81653cd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #604      +/-   ##
==========================================
+ Coverage   79.87%   79.93%   +0.06%     
==========================================
  Files          70       70              
  Lines        8356     8362       +6     
  Branches     1516     1519       +3     
==========================================
+ Hits         6674     6684      +10     
+ Misses       1191     1188       -3     
+ Partials      491      490       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dweindl
dweindl force-pushed the distributions_validate_uniform branch from 11ac1aa to 3883ca9 Compare November 17, 2026 10:11
@dweindl
dweindl marked this pull request as ready for review November 17, 2026 11:17
@dweindl
dweindl requested a review from a team as a code owner November 17, 2026 11:17
Comment thread petab/v1/distributions.py Resolved
Comment thread petab/v1/distributions.py Resolved
`Uniform` accepted any limits, e.g., `Uniform(0, inf)`, whose pdf is 0,
whose cdf is nan, and which fails only when sampled, with numpy's
`OverflowError: Range exceeds valid bounds`.

`Uniform` now requires finite limits with `low < high` (on the scale of
the underlying uniform distribution), and `LogUniform` requires
`0 < low < high < inf`.

In `petab.v1`, this affects start point sampling for parameters with
infinite bounds or with `lowerBound=0` and log-scaled
`parameterScaleUniform` priors. These already failed during sampling;
they now fail when the `Prior` is created. Estimated parameters with
`lowerBound == upperBound` and no prior can no longer be sampled.

In `petab.v2`, `Parameter.prior_dist` reports the original prior
parameters and bounds if a `uniform` prior does not overlap the
parameter bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the distributions_validate_uniform branch from 3883ca9 to 81653cd Compare November 17, 2026 14:06
@dweindl
dweindl enabled auto-merge November 17, 2026 14:08
@dweindl
dweindl added this pull request to the merge queue Nov 17, 2026
Merged via the queue into PEtab-dev:main with commit 71091ea Nov 17, 2026
8 checks passed
@dweindl
dweindl deleted the distributions_validate_uniform branch November 17, 2026 14:17
dweindl added a commit to dweindl/libpetab-python that referenced this pull request Nov 18, 2026
…v#601)

Implements PEtab 2.0.0 erratum E1: `lowerBound` may be `-inf`,
`upperBound` may be `inf`, and if any estimated parameter has a prior,
estimated parameters with infinite bounds need an explicit proper prior.

* `Parameter.lb` must be finite or `-inf`, `Parameter.ub` finite or
`inf`. Previously, e.g. `lb=ub=inf` was accepted.
* `CheckPriorDistribution` reports estimated parameters with infinite
bounds and no prior if the problem has a MAP objective. Explicit
improper `uniform`/`log-uniform` priors (e.g., with infinite prior
parameters) are already rejected via PEtab-dev#604.
* `Problem.get_priors` and `Problem.get_startpoint_distributions` raise
a `ValueError` naming the parameters with infinite (or missing) bounds
and no prior, instead of the generic error from `Uniform` (since PEtab-dev#604)
or, before that, an improper `Uniform` that 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_startpoints` used `get_priors`, which is
empty for maximum likelihood problems, and thus always failed for them.
It now uses `get_startpoint_distributions` (identical to `get_priors`
for 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 to `petab.v1.sampling.sample_parameter_startpoints`; in v2
they have been silently ignored since PEtab-dev#380, so nothing should depend on
them.
* Tests that prior truncation at bounds matching the prior's domain
(e.g., `log-normal` on `[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 PEtab-dev#565.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants