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 (
@@ -90,8 +97,9 @@ def __init__(
9097 self ._parameters = parameters
9198 self ._bounds = bounds
9299 self ._transformation = transformation
100+ self ._bounds_truncate = bounds_truncate
93101
94- truncation = bounds if USE_PROPER_TRUNCATION else None
102+ truncation = bounds if bounds_truncate else None
95103 if truncation is not None :
96104 # for uniform, we don't want to implement truncation and just
97105 # adapt the distribution parameters
@@ -184,7 +192,7 @@ def _clip_to_bounds(self, x):
184192
185193 :param x: The values to clip. Assumed to be on the parameter scale.
186194 """
187- if self .bounds is None or USE_PROPER_TRUNCATION :
195+ if self .bounds is None or self . _bounds_truncate :
188196 return x
189197
190198 return np .maximum (
@@ -235,12 +243,16 @@ def neglogprior(self, x):
235243
236244 @staticmethod
237245 def from_par_dict (
238- d , type_ = Literal ["initialization" , "objective" ]
246+ d ,
247+ type_ = Literal ["initialization" , "objective" ],
248+ bounds_truncate : bool = True ,
239249 ) -> Prior :
240250 """Create a distribution from a row of the parameter table.
241251
242252 :param d: A dictionary representing a row of the parameter table.
243253 :param type_: The type of the distribution.
254+ :param bounds_truncate: Whether the generated prior will be truncated
255+ at the bounds.
244256 :return: A distribution object.
245257 """
246258 dist_type = d .get (f"{ type_ } PriorType" , C .PARAMETER_SCALE_UNIFORM )
@@ -268,6 +280,7 @@ def from_par_dict(
268280 parameters = params ,
269281 bounds = (d [C .LOWER_BOUND ], d [C .UPPER_BOUND ]),
270282 transformation = pscale ,
283+ bounds_truncate = bounds_truncate ,
271284 )
272285
273286
0 commit comments