Skip to content

Commit 3775bb4

Browse files
committed
_bounds_truncate
1 parent e3d2eba commit 3775bb4

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

petab/v1/priors.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Prior:
5959
on the `parameter_scale` scale).
6060
:param bounds: The untransformed bounds of the sample (lower, upper).
6161
:param transformation: The transformation of the distribution.
62-
:param bounds_truncate: Whether the generated prior will be truncated
63-
at the bounds.
62+
:param _bounds_truncate: **deprecated**
63+
Whether the generated prior will be truncated at the bounds.
6464
If ``True``, the probability density will be rescaled
6565
accordingly and the sample is generated from the truncated
6666
distribution.
@@ -75,7 +75,7 @@ def __init__(
7575
parameters: tuple,
7676
bounds: tuple = None,
7777
transformation: str = C.LIN,
78-
bounds_truncate: bool = True,
78+
_bounds_truncate: bool = True,
7979
):
8080
if transformation not in C.PARAMETER_SCALES:
8181
raise ValueError(
@@ -97,7 +97,7 @@ def __init__(
9797
self._parameters = parameters
9898
self._bounds = bounds
9999
self._transformation = transformation
100-
self._bounds_truncate = bounds_truncate
100+
self._bounds_truncate = _bounds_truncate
101101

102102
truncation = bounds
103103
if truncation is not None:
@@ -267,14 +267,14 @@ def neglogprior(
267267
def from_par_dict(
268268
d,
269269
type_=Literal["initialization", "objective"],
270-
bounds_truncate: bool = True,
270+
_bounds_truncate: bool = True,
271271
) -> Prior:
272272
"""Create a distribution from a row of the parameter table.
273273
274274
:param d: A dictionary representing a row of the parameter table.
275275
:param type_: The type of the distribution.
276-
:param bounds_truncate: Whether the generated prior will be truncated
277-
at the bounds.
276+
:param _bounds_truncate: Whether the generated prior will be truncated
277+
at the bounds. **deprecated**.
278278
:return: A distribution object.
279279
"""
280280
dist_type = d.get(f"{type_}PriorType", C.PARAMETER_SCALE_UNIFORM)
@@ -300,7 +300,7 @@ def from_par_dict(
300300
parameters=params,
301301
bounds=(d[C.LOWER_BOUND], d[C.UPPER_BOUND]),
302302
transformation=pscale,
303-
bounds_truncate=bounds_truncate,
303+
_bounds_truncate=_bounds_truncate,
304304
)
305305

306306

@@ -329,6 +329,12 @@ def priors_to_measurements(problem: Problem):
329329
- `measurement`: the PDF location
330330
- `noiseFormula`: the PDF scale
331331
332+
.. warning::
333+
334+
This function does not account for the truncation of the prior by
335+
the bounds in the parameter table. The resulting observable will
336+
not be truncated, and the PDF will not be rescaled.
337+
332338
Arguments
333339
---------
334340
problem:

petab/v1/sampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def sample_from_prior(
3232
tuple(p_params),
3333
bounds=tuple(bounds),
3434
transformation=scaling,
35-
bounds_truncate=True,
3635
)
3736
return prior.sample(shape=(n_starts,))
3837

@@ -79,7 +78,8 @@ def sample_parameter_startpoints(
7978
return np.array(
8079
[
8180
Prior.from_par_dict(
82-
row, type_="initialization", bounds_truncate=True
81+
row,
82+
type_="initialization",
8383
).sample(n_starts, x_scaled=True)
8484
for row in par_to_estimate.to_dict("records")
8585
]

tests/v1/test_priors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def apply_parameter_values(row):
196196
Prior.from_par_dict(
197197
petab_problem_priors.parameter_df.loc[par_id],
198198
type_="objective",
199-
bounds_truncate=False,
199+
_bounds_truncate=False,
200200
)
201201
for par_id in parameter_ids
202202
]

0 commit comments

Comments
 (0)