Class Percentile
java.lang.Object
cloud.opencode.base.math.stats.Percentile
Dedicated percentile calculator with configurable interpolation strategy.
支持可配置插值策略的专用百分位数计算器
Instances are immutable and thread-safe. The input data is copied and sorted upon creation.
实例不可变且线程安全。输入数据在创建时被复制并排序。
Usage example:
Percentile p = Percentile.of(new double[]{1, 2, 3, 4, 5});
double median = p.value(50);
double q1 = p.quartile(1);
double q3withMethod = p.value(75, Percentile.Method.HIGHER);
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumInterpolation method for percentile calculation. -
Method Summary
Modifier and TypeMethodDescriptionstatic Percentileof(double[] data) Creates a percentile calculator from the given data.doublequartile(int q) Computes a quartile value (Q1, Q2, or Q3).doublevalue(double p) Computes the p-th percentile using the default LINEAR interpolation method.doublevalue(double p, Percentile.Method method) Computes the p-th percentile using the specified interpolation method.
-
Method Details
-
of
Creates a percentile calculator from the given data. 根据给定数据创建百分位数计算器- Parameters:
data- the input data array (will be copied) / 输入数据数组(将被复制)- Returns:
- a new
Percentileinstance / 新的百分位数计算器实例 - Throws:
IllegalArgumentException- if data is null or empty
-
value
public double value(double p) Computes the p-th percentile using the default LINEAR interpolation method. 使用默认的 LINEAR 插值方法计算第 p 百分位数- Parameters:
p- the percentile in [0, 100] / 百分位数,范围 [0, 100]- Returns:
- the percentile value / 百分位数值
- Throws:
IllegalArgumentException- if p is out of range
-
value
Computes the p-th percentile using the specified interpolation method. 使用指定的插值方法计算第 p 百分位数- Parameters:
p- the percentile in [0, 100] / 百分位数,范围 [0, 100]method- the interpolation method / 插值方法- Returns:
- the percentile value / 百分位数值
- Throws:
IllegalArgumentException- if p is out of range or method is null
-
quartile
public double quartile(int q) Computes a quartile value (Q1, Q2, or Q3). 计算四分位数值(Q1、Q2 或 Q3)- Parameters:
q- the quartile number: 1 (Q1=25th), 2 (Q2=50th median), or 3 (Q3=75th) / 四分位数编号- Returns:
- the quartile value / 四分位数值
- Throws:
IllegalArgumentException- if q is not 1, 2, or 3
-