distributions.Triangular
Triangular distribution implementation.
Usage
distributions.Triangular()A continuous probability distribution with lower limit, upper limit, and mode, forming a triangular-shaped probability density function.
This class conforms to the Distribution protocol and provides methods to sample from a triangular distribution with specified parameters.
Methods
| Name | Description |
|---|---|
| __init__() | Initialize a triangular distribution. |
| sample() | Generate random samples from the triangular distribution. |
__init__()
Initialize a triangular distribution.
Usage
__init__(low, mode, high, random_seed=None)Parameters
low: float-
Lower limit of the distribution.
mode: float-
Mode (peak) of the distribution. Must be between low and high.
high: float-
Upper limit of the distribution.
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 triangular 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 triangular distribution:
- A single float when size is None
- A numpy array of floats with shape determined by size parameter