gleam_stats/distributions/exponential
Functions related to continuous exponential random variables.
- Available Functions
Functions
pub fn exponential_cdf(x: Float, lambda: Float) -> Result(
Float,
String,
)
Evaluate, at a certain point, the cumulative distribution function (cdf) of a continuous exponential random variable with given rate parameter ‘lambda’ > 0.
Example:
import gleam_stats/distributions/exponential
import gleeunit/should
pub fn example() {
let lambda: Float = 1.
// For illustrational purposes, evaluate the cdf at the
// point -100.0
exponential.exponential_cdf(-100.0, lambda) |> should.equal(Ok(0.0))
}
pub fn exponential_mean(lambda: Float) -> Result(Float, String)
Analytically compute the mean of a continuous exponential random variable
with given rate parameter ‘lambda’ > 0.
pub fn exponential_pdf(x: Float, lambda: Float) -> Result(
Float,
String,
)
Evaluate the probability density function (pdf) of a continuous exponential random variable with given rate parameter ‘lambda’ > 0.
Example:
import gleam_stats/distributions/exponential
import gleeunit/should
pub fn example() {
let lambda: Float = 1.
// For illustrational purposes, evaluate the pdf at the
// point -100.0
exponential.exponential_pdf(-100.0, lambda) |> should.equal(Ok(0.0))
}
pub fn exponential_random(stream: Iterator(Int), lambda: Float, m: Int) -> Result(
#(List(Float), Iterator(Int)),
String,
)
Generate ‘m’ random numbers from a continuous exponential distribution with given rate parameter ‘lambda’ > 0.
The random numbers are generated using the inverse transform method.
Example:
import gleam/iterator.{Iterator}
import gleam_stats/generator
import gleam_stats/distributions/exponential
pub fn example() {
let seed: Int = 5
let seq: Int = 1
let lambda: Float = 1.
assert Ok(out) =
generators.seed_pcg32(seed, seq)
|> exponential.exponential_random(lambda, 5_000)
let rands: List(Float) = pair.first(out)
let stream: Iterator(Int) = pair.second(out)
}
pub fn exponential_variance(lambda: Float) -> Result(
Float,
String,
)
Analytically compute the variance of a continuous exponential random variable
with given rate parameter ‘lambda’ > 0.