Class NormalDistribution
java.lang.Object
cloud.opencode.base.math.distribution.NormalDistribution
Immutable normal (Gaussian) distribution.
不可变正态(高斯)分布
Provides PDF, CDF, inverse CDF (quantile function), and random sampling.
Thread-safe: instances are immutable and sampling uses ThreadLocalRandom.
提供概率密度函数、累积分布函数、逆累积分布函数(分位函数)和随机抽样。
线程安全:实例不可变,抽样使用 ThreadLocalRandom。
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NormalDistributionStandard normal distribution N(0, 1). / 标准正态分布 N(0, 1) -
Method Summary
Modifier and TypeMethodDescriptiondoublecdf(double x) Computes the cumulative distribution function (CDF) at x.doubleinverseCdf(double p) Computes the inverse CDF (quantile function / percent-point function).doublemean()Returns the mean of this distribution.static NormalDistributionof(double mean, double stdDev) Creates a normal distribution with the specified mean and standard deviation.doublepdf(double x) Computes the probability density function (PDF) at x.doublesample()Generates one random sample from this distribution using the Box-Muller transform.double[]sample(int n) doubleReturns the standard deviation of this distribution.toString()doublevariance()Returns the variance of this distribution.
-
Field Details
-
STANDARD
Standard normal distribution N(0, 1). / 标准正态分布 N(0, 1)
-
-
Method Details
-
of
Creates a normal distribution with the specified mean and standard deviation. 创建具有指定均值和标准差的正态分布- Parameters:
mean- the mean / 均值stdDev- the standard deviation, must be > 0 / 标准差,必须 > 0- Returns:
- a new NormalDistribution instance / 新的正态分布实例
- Throws:
IllegalArgumentException- if stdDev ≤ 0
-
mean
public double mean()Returns the mean of this distribution. 返回此分布的均值- Returns:
- the mean / 均值
-
standardDeviation
public double standardDeviation()Returns the standard deviation of this distribution. 返回此分布的标准差- Returns:
- the standard deviation / 标准差
-
variance
public double variance()Returns the variance of this distribution. 返回此分布的方差- Returns:
- the variance (stdDev^2) / 方差
-
pdf
public double pdf(double x) Computes the probability density function (PDF) at x. 计算在 x 处的概率密度函数值f(x) = (1 / (sigma * sqrt(2*pi))) * exp(-0.5 * ((x - mu) / sigma)^2)
- Parameters:
x- the point at which to evaluate the PDF / 计算 PDF 的点- Returns:
- the density at x / x 处的密度值
-
cdf
public double cdf(double x) Computes the cumulative distribution function (CDF) at x. 计算在 x 处的累积分布函数值F(x) = 0.5 * (1 + erf((x - mu) / (sigma * sqrt(2))))
- Parameters:
x- the point at which to evaluate the CDF / 计算 CDF 的点- Returns:
- the cumulative probability P(X ≤ x) / 累积概率
-
inverseCdf
public double inverseCdf(double p) Computes the inverse CDF (quantile function / percent-point function). 计算逆累积分布函数(分位函数)Uses the rational approximation algorithm by Peter Acklam for the standard normal quantile, then scales by mean and standard deviation.
使用 Peter Acklam 的有理近似算法计算标准正态分位数,然后按均值和标准差缩放。
- Parameters:
p- the cumulative probability, must be in (0, 1) / 累积概率,必须在 (0, 1) 内- Returns:
- the quantile x such that P(X ≤ x) = p / 使得 P(X ≤ x) = p 的分位数
- Throws:
MathException- if p is not in (0, 1)
-
sample
public double sample()Generates one random sample from this distribution using the Box-Muller transform. 使用 Box-Muller 变换从此分布生成一个随机样本- Returns:
- a random sample / 随机样本
-
sample
public double[] sample(int n) -
toString
-