gleam_stats/distributions/uniform
Functions related to continuous uniform random variables.
- Available Functions
Functions
pub fn uniform_cdf(x: Float, a: Float, b: Float) -> Result(
Float,
String,
)
Evaluate, at a certain point, the cumulative distribution function (cdf) of a continuous uniform random variable that takes values in the interval ‘[a, b]’.
Example:
import gleam_stats/distributions/uniform
import gleeunit/should
pub fn example() {
let a: Float = 0.
let b: Float = 1.
// For illustrational purposes, evaluate the cdf at points
// 0.0 and 1.0
uniform.uniform_cdf(0.0, a, b) |> should.equal(Ok(0.0))
uniform.uniform_cdf(1.0, a, b) |> should.equal(Ok(1.0))
}
pub fn uniform_mean(a: Float, b: Float) -> Result(Float, String)
Analytically compute the mean of a continuous uniform random variable
that takes values in the interval ‘[a, b]’.
pub fn uniform_pdf(x: Float, a: Float, b: Float) -> Result(
Float,
String,
)
Evaluate the probability density function (pdf) of a continuous uniform random variable that takes values in the interval ‘[a, b]’.
Example:
import gleam_stats/distributions/uniform
import gleeunit/should
pub fn example() {
let a: Float = 0.
let b: Float = 1.
// For illustrational purposes, evaluate the pdf at points
// 0.0 and 1.0
uniform.uniform_cdf(0.0, a, b) |> should.equal(Ok(0.5))
uniform.uniform_cdf(1.0, a, b) |> should.equal(Ok(1.0))
}
pub fn uniform_random(stream: Iterator(Int), a: Float, b: Float, m: Int) -> Result(
#(List(Float), Iterator(Int)),
String,
)
Generate ‘m’ random numbers in the interval ‘[a, b]’ from a continuous uniform distribution.
Example:
import gleam/iterator.{Iterator}
import gleam_stats/generator
import gleam_stats/distributions/uniform
pub fn example() {
let seed: Int = 5
let seq: Int = 1
// Min value
let a: Float = 0.
// Max value
let b: Float = 1.
assert Ok(out) =
generators.seed_pcg32(seed)
|> uniform.uniform_random(a, b, 5_000)
let rands: List(Float) = pair.first(out)
let stream: Iterator(Int) = pair.second(out)
}
pub fn uniform_variance(a: Float, b: Float) -> Result(
Float,
String,
)
Analytically compute the variance of a continuous uniform random variable
that takes values in the interval ‘[a, b]’.