Skip to content

Commit a77f766

Browse files
committed
No implicit prior in Parameter.prior_dist
1 parent 784f074 commit a77f766

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

petab/v2/core.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,13 +1026,17 @@ def _validate(self) -> Self:
10261026
return self
10271027

10281028
@property
1029-
def prior_dist(self) -> Distribution:
1030-
"""Get the prior distribution of the parameter."""
1031-
if self.estimate is False:
1029+
def prior_dist(self) -> Distribution | None:
1030+
"""Get the prior distribution of the parameter.
1031+
1032+
:return: The prior distribution of the parameter, or None if no prior
1033+
distribution is set.
1034+
"""
1035+
if not self.estimate:
10321036
raise ValueError(f"Parameter `{self.id}' is not estimated.")
10331037

10341038
if self.prior_distribution is None:
1035-
return Uniform(self.lb, self.ub)
1039+
return None
10361040

10371041
if not (cls := _prior_to_cls.get(self.prior_distribution)):
10381042
raise ValueError(
@@ -1858,7 +1862,11 @@ def get_priors(self) -> dict[str, Distribution]:
18581862
18591863
:returns: The prior distributions for the estimated parameters.
18601864
"""
1861-
return {p.id: p.prior_dist for p in self.parameters if p.estimate}
1865+
return {
1866+
p.id: p.prior_dist if p.prior_distribution else Uniform(p.lb, p.ub)
1867+
for p in self.parameters
1868+
if p.estimate
1869+
}
18621870

18631871
def sample_parameter_startpoints(self, n_starts: int = 100, **kwargs):
18641872
"""Create 2D array with starting points for optimization"""

petab/v2/lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ def run(self, problem: Problem) -> ValidationIssue | None:
843843

844844
# TODO: check distribution parameter domains more specifically
845845
try:
846-
if parameter.estimate:
846+
if parameter.estimate and parameter.prior_dist is not None:
847847
# .prior_dist fails for non-estimated parameters
848848
_ = parameter.prior_dist.sample(1)
849849
except Exception as e:

0 commit comments

Comments
 (0)