Class Distributions

java.lang.Object
cloud.opencode.base.math.distribution.Distributions

public final class Distributions extends Object
Utility class providing common probability distribution functions. 提供常用概率分布函数的工具类

Includes uniform, exponential, and Poisson distribution helpers. All methods are stateless and thread-safe.

包括均匀分布、指数分布和泊松分布辅助方法。 所有方法无状态且线程安全。

Since:
JDK 25, opencode-base-math V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    exponentialCdf(double lambda, double x)
    Computes the CDF of the exponential distribution at x.
    static double
    exponentialPdf(double lambda, double x)
    Computes the PDF of the exponential distribution at x.
    static double
    poissonCdf(double lambda, int k)
    Computes the CDF of the Poisson distribution: P(X ≤ k).
    static double
    poissonPmf(double lambda, int k)
    Computes the probability mass function (PMF) of the Poisson distribution.
    uniform(double min, double max)
    Returns the PDF of a uniform distribution on [min, max].

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • uniform

      public static DoubleUnaryOperator uniform(double min, double max)
      Returns the PDF of a uniform distribution on [min, max]. 返回 [min, max] 上均匀分布的概率密度函数

      The returned operator evaluates to 1/(max-min) for x in [min, max], and 0 otherwise.

      返回的算子在 x 属于 [min, max] 时值为 1/(max-min),否则为 0。

      Parameters:
      min - the lower bound / 下界
      max - the upper bound, must be > min / 上界,必须 > min
      Returns:
      a DoubleUnaryOperator representing the PDF / 表示 PDF 的 DoubleUnaryOperator
      Throws:
      IllegalArgumentException - if min ≥ max or values are not finite
    • exponentialPdf

      public static double exponentialPdf(double lambda, double x)
      Computes the PDF of the exponential distribution at x. 计算指数分布在 x 处的概率密度函数值

      f(x) = lambda * exp(-lambda * x) for x ≥ 0, 0 otherwise.

      Parameters:
      lambda - the rate parameter, must be > 0 / 速率参数,必须 > 0
      x - the point at which to evaluate / 计算点
      Returns:
      the PDF value at x / x 处的 PDF 值
      Throws:
      IllegalArgumentException - if lambda ≤ 0
    • exponentialCdf

      public static double exponentialCdf(double lambda, double x)
      Computes the CDF of the exponential distribution at x. 计算指数分布在 x 处的累积分布函数值

      F(x) = 1 - exp(-lambda * x) for x ≥ 0, 0 otherwise.

      Parameters:
      lambda - the rate parameter, must be > 0 / 速率参数,必须 > 0
      x - the point at which to evaluate / 计算点
      Returns:
      the CDF value at x / x 处的 CDF 值
      Throws:
      IllegalArgumentException - if lambda ≤ 0
    • poissonPmf

      public static double poissonPmf(double lambda, int k)
      Computes the probability mass function (PMF) of the Poisson distribution. 计算泊松分布的概率质量函数

      P(X = k) = (lambda^k * exp(-lambda)) / k!

      Computed in log-space for numerical stability.

      在对数空间中计算以保证数值稳定性。

      Parameters:
      lambda - the rate parameter, must be > 0 / 速率参数,必须 > 0
      k - the number of events, must be ≥ 0 / 事件数,必须 ≥ 0
      Returns:
      P(X = k) / 概率质量函数值
      Throws:
      IllegalArgumentException - if lambda ≤ 0 or k < 0
    • poissonCdf

      public static double poissonCdf(double lambda, int k)
      Computes the CDF of the Poisson distribution: P(X ≤ k). 计算泊松分布的累积分布函数:P(X ≤ k)

      Computed as the sum of PMF values from 0 to k.

      通过求和 PMF 值(从 0 到 k)计算。

      Parameters:
      lambda - the rate parameter, must be > 0 / 速率参数,必须 > 0
      k - the upper limit, must be ≥ 0 / 上限,必须 ≥ 0
      Returns:
      P(X ≤ k) / 累积分布函数值
      Throws:
      IllegalArgumentException - if lambda ≤ 0 or k < 0