TriangularDistribution
class TriangularDistribution(val a: Double, val b: Double, val c: Double) : ContinuousDistribution(source)
Represents the triangular distribution, a continuous probability distribution defined by a lower limit a, an upper limit b, and a mode (peak) c.
The triangular distribution has a piecewise linear density that rises from zero at a to a peak at c, then falls back to zero at b. It is commonly used in simulation and risk analysis when only the minimum, maximum, and most likely value of a quantity are known, making it a practical alternative to the beta distribution when limited information is available.
The PDF consists of two linear segments joined at the mode c, the CDF is piecewise quadratic, and the quantile function uses the inverse of those quadratic segments. Sampling is performed via the inverse CDF method.
Example:
// Model project duration: min 2 weeks, most likely 5 weeks, max 10 weeks
val dist = TriangularDistribution(a = 2.0, b = 10.0, c = 5.0)
dist.mean // 5.6667 (shifted toward the longer tail)
dist.variance // 2.7222
dist.pdf(5.0) // 0.25 (peak density at the mode)
dist.cdf(5.0) // 0.375
dist.quantile(0.5) // 5.2915 (the median)
dist.sample(Random(42)) // a single random draw from Triangular(2, 10, 5)
// Symmetric triangular distribution
val sym = TriangularDistribution(a = 0.0, b = 1.0, c = 0.5)
sym.skewness // 0.0Content copied to clipboard