gleam_stats/distributions/weibull
Functions related to continuous Weibull random variables.
- Available functions
Functions
pub fn do_weibull_cdf(x: Float, lambda: Float, k: Float) -> Result(
Float,
String,
)
pub fn weibull_cdf(x: Float, lambda: Float, k: Float) -> Result(
Float,
String,
)
Evaluate, at a certain point $$x \in (-\infty, +\infty)$$, the cumulative distribution function (cdf) of a Weibull random variable with scale parameter $$\lambda in (0, +\infty)$$ and shape parameter $$k \in (0, +\infty)$$.
Example:
import gleam_stats/distributions/weibull
import gleeunit/should
pub fn example() {
let lambda: Float = 1.
let k: Float = 5.
// For illustrational purposes, evaluate the cdf at the
// point -100.0
weibull.weibull_cdf(-100.0, lambda, k)
|> should.equal(Ok(0.0))
}
pub fn weibull_mean(lambda: Float, k: Float) -> Result(
Float,
String,
)
Analytically compute the mean of a continuous Weibull random variable
with scale parameter $$\lambda \in (0, +\infty)$$ and shape parameter
$$k \in (0, +\infty)$$.
The mean returned is: $$\lambda \cdot \Gamma\left(1 + \frac{1}{k}\right)$$.
pub fn weibull_pdf(x: Float, lambda: Float, k: Float) -> Result(
Float,
String,
)
Evaluate, at a certain point $$x \in [0, +\infty)$$, the probability density function (pdf) of a continuous Weibull random variable with scale parameter $$\lambda in (0,+\infty)$$ and shape parameter $$k \in (0, +\infty)$$.
Example:
import gleam_stats/distributions/weibull
import gleeunit/should
pub fn example() {
let lambda: Float = 1.
let k: Float = 5.
// For illustrational purposes, evaluate the pdf at the
// point -100.0
weibull.weibull_pdf(-100.0, lambda, k)
|> should.equal(Ok(0.0))
}
pub fn weibull_random(stream: Iterator(Int), lambda: Float, k: Float, m: Int) -> Result(
#(List(Float), Iterator(Int)),
String,
)
Generate $$m \in \mathbb{Z}_{>0}$$ random numbers from a continuous Weibull distribution with scale parameter $$\lambda \in (0, +\infty)$$ and shape parameter $$k \in (0, +\infty)$$.
The random numbers are generated using the inverse transform method.
Example:
import gleam/iterator.{Iterator}
import gleam_stats/generators
import gleam_stats/distributions/weibull
pub fn example() {
let seed: Int = 5
let seq: Int = 1
let lambda: Float = 1.
let k: Float = 5.
assert Ok(out) =
generators.seed_pcg32(seed, seq)
|> weibull.weibull_random(lambda, k, 5_000)
let rands: List(Float) = pair.first(out)
let stream: Iterator(Int) = pair.second(out)
}
pub fn weibull_variance(lambda: Float, k: Float) -> Result(
Float,
String,
)
Analytically compute the variance of a continuous Weibull random variable
with scale parameter $$\lambda \in (0, +\infty)$$ and shape parameter
$$k \in (0, +\infty)$$.
The variance returned is: $$\lambda^{2} \cdot \left[ \Gamma\left(1 + \frac{2}{k}\right) - \left(\Gamma\left(1 + \frac{1}{k}\right)\right)^{2} \right]$$.