Class BinomialDistribution
java.lang.Object
cloud.opencode.base.math.distribution.BinomialDistribution
Immutable binomial distribution.
不可变二项分布
Provides PMF, CDF, mean, and variance. Thread-safe: instances are immutable.
提供概率质量函数、累积分布函数、均值和方差。 线程安全:实例不可变。
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondoublecdf(int k) Computes the cumulative distribution function (CDF) at k: P(X ≤ k).doublemean()Returns the mean of this distribution: n * p.static BinomialDistributionof(int n, double p) Creates a binomial distribution with the specified parameters.doublepmf(int k) Computes the probability mass function (PMF) at k.doubleReturns the probability of success.toString()inttrials()Returns the number of trials.doublevariance()Returns the variance of this distribution: n * p * (1 - p).
-
Method Details
-
of
Creates a binomial distribution with the specified parameters. 创建具有指定参数的二项分布- Parameters:
n- the number of trials, must be ≥ 0 / 试验次数,必须 ≥ 0p- the probability of success, must be in [0, 1] / 成功概率,必须在 [0, 1] 内- Returns:
- a new BinomialDistribution instance / 新的二项分布实例
- Throws:
IllegalArgumentException- if n < 0 or p is not in [0, 1]
-
trials
public int trials()Returns the number of trials. 返回试验次数- Returns:
- the number of trials / 试验次数
-
probability
public double probability()Returns the probability of success. 返回成功概率- Returns:
- the probability of success / 成功概率
-
mean
public double mean()Returns the mean of this distribution: n * p. 返回此分布的均值:n * p- Returns:
- the mean / 均值
-
variance
public double variance()Returns the variance of this distribution: n * p * (1 - p). 返回此分布的方差:n * p * (1 - p)- Returns:
- the variance / 方差
-
pmf
public double pmf(int k) Computes the probability mass function (PMF) at k. 计算在 k 处的概率质量函数值P(X = k) = C(n, k) * p^k * (1 - p)^(n - k), computed in log-space.
- Parameters:
k- the number of successes / 成功次数- Returns:
- the probability P(X = k) / 概率 P(X = k)
-
cdf
public double cdf(int k) Computes the cumulative distribution function (CDF) at k: P(X ≤ k). 计算在 k 处的累积分布函数值:P(X ≤ k)Uses the regularized incomplete beta function for efficiency: P(X ≤ k) = I(1-p, n-k, k+1).
- Parameters:
k- the upper limit / 上限- Returns:
- the cumulative probability P(X ≤ k) / 累积概率
-
toString
-