4040
4141__all__ = ["priors_to_measurements" ]
4242
43- # TODO: does anybody really rely on the old behavior?
44- USE_PROPER_TRUNCATION = True
45-
4643
4744class Prior :
4845 """A PEtab parameter prior.
@@ -61,6 +58,15 @@ class Prior:
6158 on the `parameter_scale` scale).
6259 :param bounds: The untransformed bounds of the sample (lower, upper).
6360 :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.
6470 """
6571
6672 def __init__ (
@@ -69,6 +75,7 @@ def __init__(
6975 parameters : tuple ,
7076 bounds : tuple = None ,
7177 transformation : str = C .LIN ,
78+ bounds_truncate : bool = True ,
7279 ):
7380 if transformation not in C .PARAMETER_SCALES :
7481 raise ValueError (
@@ -91,7 +98,7 @@ def __init__(
9198 self ._bounds = bounds
9299 self ._transformation = transformation
93100
94- truncation = bounds if USE_PROPER_TRUNCATION else None
101+ truncation = bounds if bounds_truncate else None
95102 if truncation is not None :
96103 # for uniform, we don't want to implement truncation and just
97104 # adapt the distribution parameters
@@ -235,12 +242,16 @@ def neglogprior(self, x):
235242
236243 @staticmethod
237244 def from_par_dict (
238- d , type_ = Literal ["initialization" , "objective" ]
245+ d ,
246+ type_ = Literal ["initialization" , "objective" ],
247+ bounds_truncate : bool = True ,
239248 ) -> Prior :
240249 """Create a distribution from a row of the parameter table.
241250
242251 :param d: A dictionary representing a row of the parameter table.
243252 :param type_: The type of the distribution.
253+ :param bounds_truncate: Whether the generated prior will be truncated
254+ at the bounds.
244255 :return: A distribution object.
245256 """
246257 dist_type = d .get (f"{ type_ } PriorType" , C .PARAMETER_SCALE_UNIFORM )
@@ -268,6 +279,7 @@ def from_par_dict(
268279 parameters = params ,
269280 bounds = (d [C .LOWER_BOUND ], d [C .UPPER_BOUND ]),
270281 transformation = pscale ,
282+ bounds_truncate = bounds_truncate ,
271283 )
272284
273285
0 commit comments