CauchyDistribution

class CauchyDistribution(val location: Double = 0.0, val scale: Double = 1.0) : ContinuousDistribution(source)

Represents the Cauchy distribution (also known as the Lorentz distribution).

The Cauchy distribution is a symmetric, heavy-tailed continuous distribution centered at location. It is famous for having no defined mean, variance, or higher moments -- all of these properties return Double.NaN. This happens because the tails are so heavy that the integrals defining these moments diverge.

A common way the Cauchy distribution arises in practice is as the ratio of two independent standard normal random variables. It also describes the distribution of the tangent of a uniformly distributed angle and appears in physics as the line shape of spectral lines (where it is called a Lorentzian).

The distribution is supported on the entire real line, from negative infinity to positive infinity. The scale parameter controls how spread out the distribution is around the location (analogous to standard deviation in a normal distribution, but the Cauchy distribution decays much more slowly in the tails).

The quantile function has a closed-form expression using the tangent function, so sampling is performed via inverse CDF (no iterative root-finding is needed).

Example:

val cauchy = CauchyDistribution(location = 0.0, scale = 1.0)
cauchy.pdf(0.0) // 0.3183... (peak density at the location)
cauchy.cdf(0.0) // 0.5 (symmetric around the location)
cauchy.quantile(0.75) // 1.0 (third quartile of the standard Cauchy)
cauchy.mean // NaN (the mean is undefined)
cauchy.entropy // 2.5310... (entropy is defined even though moments are not)
cauchy.sample(Random(42)) // a single random draw

Constructors

Link copied to clipboard
constructor(location: Double = 0.0, scale: Double = 1.0)

Types

Link copied to clipboard
object Companion

Provides the standard Cauchy distribution instance.

Properties

Link copied to clipboard
open override val entropy: Double

Returns the Shannon entropy of this distribution in nats. The Cauchy entropy is always defined even though the moments are not.

Link copied to clipboard
open override val kurtosis: Double

Returns Double.NaN because the Cauchy distribution has no defined kurtosis.

Link copied to clipboard

the center of the distribution, where the density peaks. Defaults to 0.0.

Link copied to clipboard
open override val mean: Double

Returns Double.NaN because the Cauchy distribution has no defined mean.

Link copied to clipboard

the half-width at half-maximum, controlling the spread of the distribution. Must be positive. Defaults to 1.0.

Link copied to clipboard
open override val skewness: Double

Returns Double.NaN because the Cauchy distribution has no defined skewness.

Link copied to clipboard
open override val standardDeviation: Double

Returns Double.NaN because the Cauchy distribution has no defined standard deviation.

Link copied to clipboard
open override val variance: Double

Returns Double.NaN because the Cauchy distribution has no defined variance.

Functions

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

Returns the cumulative distribution function value at x.

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

Returns the natural logarithm of the probability density at x.

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

Returns the probability density at x.

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

Returns 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 Cauchy distribution.

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

Returns the survival function value at x, equal to 1 - cdf(x).