gleam_stats/distributions/normal
Functions related to continuous normal random variables.
- Available Functions
Functions
pub fn normal_cdf(x: Float, mu: Float, sigma: Float) -> Result(
Float,
String,
)
Evaluate, at a certain point, the cumulative distribution function (cdf) of a continuous normal random variable with mean ‘mu’ and standard deviation ‘sigma’.
Example:
import gleam_stats/distributions/normal
import gleeunit/should
pub fn example() {
let mean: Float = 0.
let sigma: Float = 1.
// For illustrational purposes, evaluate the cdf at the
// point -100.0
normal.normal_cdf(-100.0, mu, sigma) |> should.equal(Ok(0.0))
}
pub fn normal_mean(mu: Float, sigma: Float) -> Result(
Float,
String,
)
Analytically compute the mean of a continuous normal random variable
with given mean ‘mu’ and standard deviation ‘sigma’.
pub fn normal_pdf(x: Float, mu: Float, sigma: Float) -> Result(
Float,
String,
)
Evaluate the probability density function (pdf) of a continuous normal random variable with given mean ‘mu’ and standard deviation ‘sigma’.
Example:
import gleam_stats/distributions/normal
import gleeunit/should
pub fn example() {
let mean: Float = 0.
let sigma: Float = 1.
// For illustrational purposes, evaluate the pdf at the
// point -100.0
normal.normal_pdf(-100.0, mu, sigma) |> should.equal(Ok(0.0))
}
pub fn normal_random(stream: Iterator(Int), mu: Float, sigma: Float, m: Int) -> Result(
#(List(Float), Iterator(Int)),
String,
)
Generate ‘m’ random numbers from a continuous normal distribution with a given mean ‘mu’ and standard deviation ‘sigma’.
The random numbers are generated using Box–Muller transform.
Example:
import gleam/iterator.{Iterator}
import gleam_stats/generator
import gleam_stats/distributions/normal
pub fn example() {
let seed: Int = 5
let seq: Int = 1
let mean: Float = 0.
let std: Float = 1.
assert Ok(out) =
generators.seed_pcg32(seed, seq)
|> normal.normal_random(mean, std, 5_000)
let rands: List(Float) = pair.first(out)
let stream: Iterator(Int) = pair.second(out)
}
pub fn normal_variance(mu: Float, sigma: Float) -> Result(
Float,
String,
)
Analytically compute the variance of a continuous normal random variable
with given mean ‘mu’ and standard deviation ‘sigma’.