distributions.Normal
Normal distribution implementation with optional truncation.
Usage
distributions.Normal()A continuous probability distribution that follows the Gaussian bell curve. This implementation allows truncating the distribution at a minimum value.
This class conforms to the Distribution protocol and provides methods to sample from a normal distribution with specified mean and standard deviation.
Methods
| Name | Description |
|---|---|
| __init__() | Initialize a normal distribution. |
| sample() | Generate random samples from the normal distribution. |
__init__()
Initialize a normal distribution.
Usage
__init__(mean, sigma, minimum=None, random_seed=None)Parameters
mean: float-
The mean (μ) of the normal distribution.
sigma: float-
The standard deviation (σ) of the normal distribution.
minimum: Optional[float] = None-
If provided, truncates the distribution to this minimum value. Any sampled values below this minimum will be set to this value.
random_seed: Optional[Union[int, SeedSequence]] = None- A random seed or SeedSequence to reproduce samples. If None, a unique sample sequence is generated.
sample()
Generate random samples from the normal distribution.
Usage
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 normal distribution:
- A single float when size is None
- A numpy array of floats with shape determined by size parameter
Notes
If a minimum value was specified during initialization, any samples below this value will be truncated (set to the minimum value).