40
40
41
41
__all__ = ["priors_to_measurements" ]
42
42
43
- # TODO: does anybody really rely on the old behavior?
44
- USE_PROPER_TRUNCATION = True
45
-
46
43
47
44
class Prior :
48
45
"""A PEtab parameter prior.
@@ -61,6 +58,15 @@ class Prior:
61
58
on the `parameter_scale` scale).
62
59
:param bounds: The untransformed bounds of the sample (lower, upper).
63
60
:param transformation: The transformation of the distribution.
61
+ :param bounds_truncate: Whether the generated prior will be truncated
62
+ at the bounds.
63
+ If ``True``, the probability density will be rescaled
64
+ accordingly and the sample is generated from the truncated
65
+ distribution.
66
+ If ``False``, the probability density will not account for the
67
+ bounds, but any parameter samples outside the bounds will be set to
68
+ the value of the closest bound. In this case, the PDF might not match
69
+ the sample.
64
70
"""
65
71
66
72
def __init__ (
@@ -69,6 +75,7 @@ def __init__(
69
75
parameters : tuple ,
70
76
bounds : tuple = None ,
71
77
transformation : str = C .LIN ,
78
+ bounds_truncate : bool = True ,
72
79
):
73
80
if transformation not in C .PARAMETER_SCALES :
74
81
raise ValueError (
@@ -91,7 +98,7 @@ def __init__(
91
98
self ._bounds = bounds
92
99
self ._transformation = transformation
93
100
94
- truncation = bounds if USE_PROPER_TRUNCATION else None
101
+ truncation = bounds if bounds_truncate else None
95
102
if truncation is not None :
96
103
# for uniform, we don't want to implement truncation and just
97
104
# adapt the distribution parameters
@@ -235,12 +242,16 @@ def neglogprior(self, x):
235
242
236
243
@staticmethod
237
244
def from_par_dict (
238
- d , type_ = Literal ["initialization" , "objective" ]
245
+ d ,
246
+ type_ = Literal ["initialization" , "objective" ],
247
+ bounds_truncate : bool = True ,
239
248
) -> Prior :
240
249
"""Create a distribution from a row of the parameter table.
241
250
242
251
:param d: A dictionary representing a row of the parameter table.
243
252
:param type_: The type of the distribution.
253
+ :param bounds_truncate: Whether the generated prior will be truncated
254
+ at the bounds.
244
255
:return: A distribution object.
245
256
"""
246
257
dist_type = d .get (f"{ type_ } PriorType" , C .PARAMETER_SCALE_UNIFORM )
@@ -268,6 +279,7 @@ def from_par_dict(
268
279
parameters = params ,
269
280
bounds = (d [C .LOWER_BOUND ], d [C .UPPER_BOUND ]),
270
281
transformation = pscale ,
282
+ bounds_truncate = bounds_truncate ,
271
283
)
272
284
273
285
0 commit comments