You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2004/03/13 21:02:28 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank Percentile.java
psteitz 2004/03/13 12:02:28
Modified: math/src/java/org/apache/commons/math/stat/univariate/rank
Percentile.java
Log:
Renamed internal field, added algorithm documentation.
Revision Changes Path
1.15 +65 -32 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java
Index: Percentile.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Percentile.java 4 Mar 2004 04:25:09 -0000 1.14
+++ Percentile.java 13 Mar 2004 20:02:28 -0000 1.15
@@ -20,38 +20,51 @@
import org.apache.commons.math.stat.univariate.AbstractUnivariateStatistic;
/**
+ * Provides percentile computation.
+ * <p>
+ * There are several commonly used methods for estimating percentiles (a.k.a. quantiles) based
+ * on sample data. For large samples, the different methods agree closely, but when sample sizes
+ * are small, different methods will give significantly different results. The implementation provided here
+ * follows the first estimation procedure presented
+ * <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc252.htm">here.</a>
+ *
* @version $Revision$ $Date$
*/
public class Percentile extends AbstractUnivariateStatistic implements Serializable {
static final long serialVersionUID = -8091216485095130416L;
- /** */
- private double percentile = 0.0;
+ /** Determines what percentile is computed when evaluate() is activated with no quantile argument */
+ private double quantile = 0.0;
/**
- * Constructs a Percentile with a default percentile
+ * Constructs a Percentile with a default quantile
* value of 50.0.
*/
public Percentile() {
super();
- percentile = 50.0;
+ quantile = 50.0;
}
/**
- * Constructs a Percentile with the specific percentile value.
- * @param p the percentile
+ * Constructs a Percentile with the specific quantile value.
+ * @param p the quantile
*/
public Percentile(final double p) {
- this.percentile = p;
+ this.quantile = p;
}
/**
- * Evaluates the double[] top the specified percentile.
- * This does not alter the interal percentile state of the
- * statistic.
+ * Returns an estimate of the <code>p</code>th percentile of the values
+ * in the <code>values</code> array.
+ * <p>
+ * Calls to this method do not modify the internal <code>quantile</code>
+ * state of this statistic.
+ * <p>
+ * See {@link Percentile} for a description of the percentile estimation algorithm used.
+ *
* @param values Is a double[] containing the values
- * @param p Is the percentile to evaluate to.
+ * @param p Is the quantile to evaluate to.
* @return the result of the evaluation or Double.NaN
* if the array is empty
*/
@@ -60,24 +73,42 @@
}
/**
- * @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int, int)
+ * Returns an estimate of the <code>quantile</code>th percentile of the values
+ * in the <code>values</code> array. The quantile estimated is determined by
+ * the <code>quantile</code> property.
+ * <p>
+ * See {@link Percentile} for a description of the percentile estimation algorithm used.
+ *
+ * @param values array of input values
+ * @param start the first (0-based) element to include in the computation
+ * @param length the number of array elements to include
+ * @return the result of the evaluation or Double.NaN
+ * if the array is empty
+ *
*/
public double evaluate(
final double[] values,
final int start,
final int length) {
- return evaluate(values, start, length, percentile);
+ return evaluate(values, start, length, quantile);
}
- /**
- * Evaluates the double[] top the specified percentile.
- * This does not alter the interal percentile state of the
- * statistic.
+ /**
+ * Returns an estimate of the <code>p</code>th percentile of the values
+ * in the <code>values</code> array, starting with the element in (0-based)
+ * position <code>begin</code> in the array and including <code>length</code>
+ * values.
+ * <p>
+ * Calls to this method do not modify the internal <code>quantile</code>
+ * state of this statistic.
+ * <p>
+ * See {@link Percentile} for a description of the percentile estimation algorithm used.
+ *
* @param values Is a double[] containing the values
- * @param begin processing at this point in the array
- * @param length the number of elements to include
- * @param p Is the percentile to evaluate to.*
+ * @param p Is the quantile to evaluate to.
+ * @param start the first (0-based) element to include in the computation
+ * @param length the number of array elements to include
* @return the result of the evaluation or Double.NaN
* if the array is empty
*/
@@ -90,7 +121,7 @@
test(values, begin, length);
if ((p > 100) || (p <= 0)) {
- throw new IllegalArgumentException("invalid percentile value");
+ throw new IllegalArgumentException("invalid quantile value");
}
double n = (double) length;
if (n == 0) {
@@ -119,21 +150,23 @@
}
/**
- * The default internal state of this percentile can be set.
- * This will return that value.
- * @return percentile
+ * Returns the value of the quantile field (determines what percentile is computed when evaluate()
+ * is called with no quantile argument)
+ *
+ * @return quantile
*/
- public double getPercentile() {
- return percentile;
+ public double getQuantile() {
+ return quantile;
}
/**
- * The default internal state of this percentile can be set.
- * This will setthat value.
- * @param p a value between 0 <= p <= 100
+ * Sets the value of the quantile field (determines what percentile is computed when evaluate()
+ * is called with no quantile argument)
+ *
+ * @param p a value between 0 <= p <= 100
*/
- public void setPercentile(final double p) {
- percentile = p;
+ public void setQuantile(final double p) {
+ quantile = p;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org