distributions.TruncatedDistribution

Truncated Distribution implementation.

Usage

Source

distributions.TruncatedDistribution()

Wraps any distribution conforming to the Distribution protocol and truncates samples at a specified lower bound. No resampling is performed; the class simply ensures no values are below the lower bound.

This class itself conforms to the Distribution protocol.

Methods

Name Description
__init__() Initialize a truncated distribution.
sample() Generate random samples from the truncated distribution.

__init__()

Initialize a truncated distribution.

Usage

Source

__init__(dist_to_truncate, lower_bound)
Parameters
dist_to_truncate: Distribution

Any object conforming to the Distribution protocol that generates samples.

lower_bound: float
Truncation point. Any samples below this value will be set to this value.

sample()

Generate random samples from the truncated distribution.

Usage

Source

sample(size=None)
Parameters
size: Optional[Union[int, Tuple[int, …]]] = None
The number/shape of samples to generate:
  • If None: returns a single sample as a float
  • If int: returns a 1-D array with that many samples
  • If tuple of ints: returns an array with that shape
Returns
Union[float, NDArray[np.float64]]
Random samples from the truncated distribution:
  • A single float when size is None
  • A numpy array of floats with shape determined by size parameter
Notes

All values will be greater than or equal to the specified lower bound.