## distributions.Weibull


Weibull distribution implementation.


Usage

``` python
distributions.Weibull(
    alpha,
    beta,
    location=0.0,
    random_seed=None,
)
```


A continuous probability distribution useful for modeling time-to-failure and similar phenomena. Characterized by shape (alpha) and scale (beta) parameters.

This implementation also includes a third parameter "location" (default=0) to shift the distribution if a lower bound is needed.

The probability density function (PDF) is: f(x) = (α/β) \* ((x-location)/β)^(α-1) \* exp(-((x-location)/β)^α) for x ≥ location, where α is the shape parameter and β is the scale parameter.

The samples are generated using: X = scale × (-ln(U))^(1/shape) + location where U is a uniform random number between 0 and 1.

The Weibull distribution reduces to: - Exponential distribution when shape=1 - Rayleigh distribution when shape=2 - Approximately Normal distribution when shape≈3.4


## Attributes

| Name | Description |
|----|----|
| [mean](#mean) | Return the theoretical mean of the Weibull distribution. |
| [variance](#variance) | Return the theoretical variance of the Weibull distribution. |

------------------------------------------------------------------------


#### mean


Return the theoretical mean of the Weibull distribution.


`mean: float`


The formula is: location + scale \* Γ(1 + 1/shape) where Γ is the gamma function.


------------------------------------------------------------------------


#### variance


Return the theoretical variance of the Weibull distribution.


`variance: float`


The formula is: scale² \* \[Γ(1 + 2/shape) - (Γ(1 + 1/shape))²\] where Γ is the gamma function.


## Methods

| Name | Description |
|----|----|
| [__init__()](#__init__) | Initialize a three-parameter Weibull distribution. |
| [sample()](#sample) | Generate random samples from the Weibull distribution. |

------------------------------------------------------------------------


#### \_\_init\_\_()


Initialize a three-parameter Weibull distribution.


Usage

``` python
__init__(alpha, beta, location=0.0, random_seed=None)
```


##### Parameters


`alpha: float`  
The shape parameter. Must be \> 0.

`beta: float`  
The scale parameter. Must be \> 0. The higher the scale parameter, the more variance in the samples.

`location: float = ``0.0`  
An offset to shift the distribution from 0.

`random_seed: Optional[Union[int, SeedSequence]] = None`  
A random seed or SeedSequence to reproduce samples. If None, a unique sample sequence is generated.


##### Notes

Caution is advised when setting shape and scale parameters as different sources use different notations:

- In Law and Kelton, shape=alpha and scale=beta
- Wikipedia defines shape=k and scale=lambda=1/beta
- Other sources define shape=beta and scale=eta (η)
- In Python's random.weibullvariate, alpha=scale and beta=shape!

It's recommended to verify the mean and variance of samples match expectations.

------------------------------------------------------------------------


#### sample()


Generate random samples from the Weibull distribution.


Usage

``` python
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 Weibull distribution:

- A single float when size is None
- A numpy array of floats with shape determined by size parameter
