BetaDistribution

Represents the Beta distribution, a continuous probability distribution defined on the interval 0, 1.

The Beta distribution is commonly used to model probabilities, proportions, and percentages because its support is naturally bounded between zero and one. It is widely used as a conjugate prior in Bayesian statistics -- for example, modeling the probability of success in a Bernoulli trial before observing data. The two shape parameters alpha and beta control the shape of the density: when both are equal, the distribution is symmetric around 0.5; when they differ, the distribution skews toward one end.

The CDF is computed via the regularized incomplete beta function, and quantiles are found using Newton's method. Random samples are generated by taking the ratio of two independent Gamma-distributed random variables.

Example:

val dist = BetaDistribution(alpha = 2.0, beta = 5.0)
dist.mean // 0.2857... (skewed toward 0)
dist.pdf(0.3) // 1.8522... (density at x = 0.3)
dist.cdf(0.5) // 0.8906... (probability of being at most 0.5)

val uniform = BetaDistribution.STANDARD
uniform.pdf(0.5) // 1.0 (flat density on [0, 1])

See also

Constructors

Link copied to clipboard
constructor(alpha: Double, beta: Double)

Types

Link copied to clipboard
object Companion

Predefined Beta distribution instances.

Properties

Link copied to clipboard

the first shape parameter, controlling weight toward 1. Must be positive.

Link copied to clipboard

the second shape parameter, controlling weight toward 0. Must be positive.

Link copied to clipboard
open override val entropy: Double

The differential entropy of this distribution.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution.

Link copied to clipboard
open override val mean: Double

The mean of this distribution, equal to alpha / (alpha + beta).

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution. Positive when alpha < beta, negative when alpha > beta.

Link copied to clipboard
open override val variance: Double

The variance of this distribution, which decreases as alpha + beta increases.

Functions

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

Computes the cumulative distribution function at x.

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.

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

Draws a single random value from this Beta distribution.

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

Computes the survival function (one minus the CDF) at x.