NormalDistribution

class NormalDistribution(val mu: Double = 0.0, val sigma: Double = 1.0) : ContinuousDistribution(source)

Represents the normal (Gaussian) distribution, the most widely used continuous probability distribution in statistics.

The normal distribution is symmetric and bell-shaped, centered at the mean mu with spread controlled by the standard deviation sigma. It arises naturally as the limiting distribution of sums of independent random variables (central limit theorem) and is the foundation for many statistical methods including confidence intervals, hypothesis tests, and regression.

About 68% of values fall within one standard deviation of the mean, about 95% within two, and about 99.7% within three. The distribution is fully supported on the entire real line, meaning any real number is a possible outcome, though values far from the mean are exceedingly rare.

The CDF and survival function use the error function for numerical accuracy, and the quantile function uses the inverse error function. Random sampling uses the Box-Muller transform, which converts two uniform random draws into a normally distributed value.

Example:

val dist = NormalDistribution(mu = 100.0, sigma = 15.0)
dist.mean // 100.0
dist.variance // 225.0
dist.pdf(100.0) // 0.0266 (peak density at the mean)
dist.cdf(115.0) // 0.8413 (about 84% of values are below one SD above the mean)
dist.quantile(0.975) // 129.39 (the 97.5th percentile)
dist.sample(Random(42)) // a single random draw from N(100, 15)

// Standard normal (mu=0, sigma=1)
val z = NormalDistribution.STANDARD
z.cdf(1.96) // 0.975

Constructors

Link copied to clipboard
constructor(mu: Double = 0.0, sigma: Double = 1.0)

Types

Link copied to clipboard
object Companion

Provides the pre-built standard normal distribution constant.

Properties

Link copied to clipboard
open override val entropy: Double

The differential entropy of this distribution in nats, computed from sigma.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution, always zero by definition (the normal distribution is the reference).

Link copied to clipboard
open override val mean: Double

The mean of this distribution, equal to mu.

Link copied to clipboard
val mu: Double

the mean (location parameter) of the distribution. Default is 0.0, which centers the distribution at the origin.

Link copied to clipboard

the standard deviation (scale parameter) of the distribution. Must be positive. Default is 1.0, which gives the standard normal distribution.

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution, always zero because the normal distribution is symmetric.

Link copied to clipboard
open override val standardDeviation: Double

The standard deviation of this distribution, equal to sigma.

Link copied to clipboard
open override val variance: Double

The variance of this distribution, equal to sigma squared.

Functions

Link copied to clipboard
open override fun cdf(x: Double): Double

Computes the cumulative distribution function at x using the error function.

Link copied to clipboard
open override fun logPdf(x: Double): Double

Computes the natural logarithm of the probability density at x.

Link copied to clipboard
open override fun pdf(x: Double): Double

Computes the probability density at x.

Link copied to clipboard
open override fun quantile(p: Double): Double

Computes the quantile (inverse CDF) for the given probability p using the inverse error function.

Link copied to clipboard
open override fun sample(random: Random): Double

Draws a single random value from this normal distribution using the Box-Muller transform.

Link copied to clipboard
open override fun sf(x: Double): Double

Computes the survival function at x using the complementary error function.