mdiggory 2003/08/08 21:03:41
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
FourthMoment.java Mean.java Kurtosis.java
Skewness.java GeometricMean.java FirstMoment.java
ThirdMoment.java Variance.java
StandardDeviation.java SecondMoment.java
math/src/java/org/apache/commons/math/stat/univariate/rank
Median.java Max.java Min.java Percentile.java
math/src/java/org/apache/commons/math/stat/univariate/summary
Sum.java SumOfSquares.java Product.java
SumOfLogs.java
math/src/java/org/apache/commons/math/util
BeanTransformer.java MathUtils.java
math/src/java/org/apache/commons/math/stat/univariate
AbstractStorelessUnivariateStatistic.java
UnivariateStatistic.java
AbstractUnivariateStatistic.java
StorelessUnivariateStatistic.java
math/src/java/org/apache/commons/math/stat
BeanListUnivariateImpl.java StatUtils.java
math/src/java/org/apache/commons/math
MathConfigurationException.java MathException.java
math/src/java/org/apache/commons/math/analysis
BisectionSolver.java
Log:
Just Checkstyle and Javadoc corrections
Revision Changes Path
1.7 +14 -11
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
Index: FourthMoment.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FourthMoment.java 9 Jul 2003 20:04:10 -0000 1.6
+++ FourthMoment.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -54,7 +54,7 @@
package org.apache.commons.math.stat.univariate.moment;
/**
- * The FourthMoment is calculated using the following
+ * The FourthMoment is calculated using the following
* <a href="http://www.spss.com/tech/stat/Algorithms/11.5/descriptives.pdf">
* recursive strategy
* </a>. Both incremental and evaluation strategies currently use this approach.
@@ -64,39 +64,42 @@
/** fourth moment of values that have been added */
protected double m4 = Double.NaN;
-
+
/** temporary internal state made available for higher order moments */
protected double prevM3 = 0.0;
/** temporary internal state made available for higher order moments */
protected double n3 = 0.0;
-
-
+
+
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (n < 1) {
- m4 = m3 = m2 = m1 = 0.0;
+ m4 = 0.0;
+ m3 = 0.0;
+ m2 = 0.0;
+ m1 = 0.0;
}
/* retain previous m3 */
prevM3 = m3;
-
+
/* increment m1, m2 and m3 (and prevM2, _n0, _n1, _n2, _v, _v2) */
super.increment(d);
n3 = (double) (n - 3);
-
+
m4 =
m4
- (4.0 * v * prevM3)
+ (6.0 * v2 * prevM2)
+ ((n0 * n0) - 3 * n1) * (v2 * v2 * n1 * n0);
}
-
+
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return m4;
1.8 +25 -8
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Mean.java
Index: Mean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Mean.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Mean.java 15 Jul 2003 03:36:36 -0000 1.7
+++ Mean.java 9 Aug 2003 04:03:40 -0000 1.8
@@ -53,7 +53,13 @@
*/
package org.apache.commons.math.stat.univariate.moment;
-import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatistic;
+import org
+ .apache
+ .commons
+ .math
+ .stat
+ .univariate
+ .AbstractStorelessUnivariateStatistic;
import org.apache.commons.math.stat.univariate.summary.Sum;
/**
@@ -66,13 +72,19 @@
/** first moment of values that have been added */
protected FirstMoment moment = null;
+ /** */
protected boolean incMoment = true;
+ /** */
public Mean() {
moment = new FirstMoment();
}
- public Mean(FirstMoment m1) {
+ /**
+ * Constructs a Mean with an External Moment.
+ * @param m1 the moment
+ */
+ public Mean(final FirstMoment m1) {
this.moment = m1;
incMoment = false;
}
@@ -80,7 +92,7 @@
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (incMoment) {
moment.increment(d);
}
@@ -96,15 +108,17 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return moment.m1;
}
/*UnvariateStatistic Approach */
- Sum sum = new Sum();
-
+
+ /** */
+ protected Sum sum = new Sum();
+
/**
* Returns the <a href="http://www.xycoon.com/arithmetic_mean.htm">
* arithmetic mean </a> of a double[] of the available values.
@@ -114,7 +128,10 @@
* @return the mean of the values or Double.NaN if the array is empty
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
if (test(values, begin, length)) {
return sum.evaluate(values) / ((double) length);
}
1.7 +32 -17
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
Index: Kurtosis.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Kurtosis.java 9 Jul 2003 20:04:10 -0000 1.6
+++ Kurtosis.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -66,19 +66,30 @@
*/
public class Kurtosis extends AbstractStorelessUnivariateStatistic {
+ /** */
protected FourthMoment moment = null;
+ /** */
protected boolean incMoment = true;
+ /** */
private double kurtosis = Double.NaN;
+ /** */
private int n = 0;
-
+
+ /**
+ * Construct a Kurtosis
+ */
public Kurtosis() {
moment = new FourthMoment();
}
- public Kurtosis(FourthMoment m4) {
+ /**
+ * Construct a Kurtosis with an external moment
+ * @param m4 external Moment
+ */
+ public Kurtosis(final FourthMoment m4) {
incMoment = false;
this.moment = m4;
}
@@ -86,14 +97,14 @@
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (incMoment) {
moment.increment(d);
}
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
if (n < moment.n) {
@@ -118,7 +129,7 @@
}
n = moment.n;
}
-
+
return kurtosis;
}
@@ -135,26 +146,29 @@
/*UnvariateStatistic Approach */
+ /** */
Mean mean = new Mean();
/**
- * This algorithm uses a corrected two pass algorithm of the following
+ * This algorithm uses a corrected two pass algorithm of the following
* <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
* corrected two pass formula (14.1.8)</a>, and also referenced in:
* <p>
* "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
+ * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
* 1983, American Statistician, vol. 37, pp. 242?247.
* </p>
- * Returns the kurtosis for this collection of values. Kurtosis is a
+ * Returns the kurtosis for this collection of values. Kurtosis is a
* measure of the "peakedness" of a distribution.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
* @return the kurtosis of the values or Double.NaN if the array is empty
*/
- public double evaluate(double[] values, int begin, int length) {
- ;
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
// Initialize the kurtosis
double kurt = Double.NaN;
@@ -167,8 +181,9 @@
// Get the mean and the standard deviation
double m = mean.evaluate(values, begin, length);
- // Calc the std, this is implemented here instead of using the
- // standardDeviation method eliminate a duplicate pass to get the
mean
+ // Calc the std, this is implemented here instead
+ // of using the standardDeviation method eliminate
+ // a duplicate pass to get the mean
double accum = 0.0;
double accum2 = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -181,7 +196,7 @@
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1));
- // Sum the ^4 of the distance from the mean divided by the
+ // Sum the ^4 of the distance from the mean divided by the
// standard deviation
double accum3 = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -189,12 +204,12 @@
}
// Get N
- double n = length;
+ double n0 = length;
double coefficientOne =
- (n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3));
+ (n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3));
double termTwo =
- ((3 * Math.pow(n - 1, 2.0)) / ((n - 2) * (n - 3)));
+ ((3 * Math.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3)));
// Calculate kurtosis
kurt = (coefficientOne * accum3) - termTwo;
1.7 +34 -18
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
Index: Skewness.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Skewness.java 9 Jul 2003 20:04:10 -0000 1.6
+++ Skewness.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -62,24 +62,35 @@
.AbstractStorelessUnivariateStatistic;
/**
- *
+ *
* @version $Revision$ $Date$
*/
public class Skewness extends AbstractStorelessUnivariateStatistic {
+ /** */
protected ThirdMoment moment = null;
+ /** */
protected boolean incMoment = true;
+ /** */
protected double skewness = Double.NaN;
+ /** */
private int n = 0;
-
+
+ /**
+ * Constructs a Skewness
+ */
public Skewness() {
moment = new ThirdMoment();
}
- public Skewness(ThirdMoment m3) {
+ /**
+ * Constructs a Skewness with an external moment
+ * @param m3 external moment
+ */
+ public Skewness(final ThirdMoment m3) {
incMoment = false;
this.moment = m3;
}
@@ -87,14 +98,14 @@
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (incMoment) {
moment.increment(d);
}
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
if (n < moment.n) {
@@ -130,29 +141,33 @@
skewness = Double.NaN;
n = 0;
}
-
+
/*UnvariateStatistic Approach */
+ /** */
Mean mean = new Mean();
/**
- * This algorithm uses a corrected two pass algorithm of the following
+ * This algorithm uses a corrected two pass algorithm of the following
* <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
- * corrected two pass formula (14.1.8)</a>, and also referenced in:
+ * corrected two pass formula (14.1.8)</a>, and also referenced in
* <p>
* "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
+ * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
* 1983, American Statistician, vol. 37, pp. 242?247.
* </p>
- * Returns the skewness of a collection of values. Skewness is a
- * measure of the assymetry of a given distribution.
+ * Returns the skewness of a collection of values. Skewness is a
+ * measure of the assymetry of a given distribution.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
* @return the skewness of the values or Double.NaN if the array is empty
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
// Initialize the skewness
double skew = Double.NaN;
@@ -165,8 +180,9 @@
// Get the mean and the standard deviation
double m = mean.evaluate(values, begin, length);
- // Calc the std, this is implemented here instead of using the
- // standardDeviation method eliminate a duplicate pass to get the
mean
+ // Calc the std, this is implemented here instead
+ // of using the standardDeviation method eliminate
+ // a duplicate pass to get the mean
double accum = 0.0;
double accum2 = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -178,7 +194,7 @@
(accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1));
- // Calculate the skew as the sum the cubes of the distance
+ // Calculate the skew as the sum the cubes of the distance
// from the mean divided by the standard deviation.
double accum3 = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -186,10 +202,10 @@
}
// Get N
- double n = length;
+ double n0 = length;
// Calculate skewness
- skew = (n / ((n - 1) * (n - 2))) * accum3;
+ skew = (n0 / ((n0 - 1) * (n0 - 2))) * accum3;
}
}
1.9 +13 -6
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/GeometricMean.java
Index: GeometricMean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/GeometricMean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- GeometricMean.java 9 Jul 2003 20:04:10 -0000 1.8
+++ GeometricMean.java 9 Aug 2003 04:03:40 -0000 1.9
@@ -55,28 +55,32 @@
import org.apache.commons.math.stat.univariate.summary.SumOfLogs;
-/**
+/**
* Returns the <a href="http://www.xycoon.com/geometric_mean.htm">
* geometric mean </a> of the available values
* @version $Revision$ $Date$
*/
public class GeometricMean extends SumOfLogs {
+ /** */
protected int n = 0;
+ /** */
private double geoMean = Double.NaN;
-
+
+ /** */
private double lastSum = 0.0;
+
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
n++;
super.increment(d);
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
if (lastSum != super.getResult() || n == 1) {
@@ -105,7 +109,10 @@
* any of the values are <= 0.
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
return Math.exp(
super.evaluate(values, begin, length) / (double) length);
}
1.6 +13 -16
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FirstMoment.java
Index: FirstMoment.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FirstMoment.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FirstMoment.java 15 Jul 2003 03:36:36 -0000 1.5
+++ FirstMoment.java 9 Aug 2003 04:03:40 -0000 1.6
@@ -57,8 +57,8 @@
/**
* FirstMoment.java
- *
- * The FirstMoment (arithmentic mean) is calculated using the following
+ *
+ * The FirstMoment (arithmentic mean) is calculated using the following
* <a href="http://www.spss.com/tech/stat/Algorithms/11.5/descriptives.pdf">
* recursive strategy
* </a>. Both incremental and evaluation strategies currently use this approach.
@@ -72,29 +72,28 @@
/** first moment of values that have been added */
protected double m1 = Double.NaN;
- /**
+ /**
* temporary internal state made available for
- * higher order moments
+ * higher order moments
*/
protected double dev = 0.0;
- /**
+ /**
* temporary internal state made available for
- * higher order moments
+ * higher order moments
*/
protected double v = 0.0;
- /**
+ /**
* temporary internal state made available for
- * higher order moments
+ * higher order moments
*/
protected double n0 = 0.0;
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#increment(double)
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (n < 1) {
m1 = 0.0;
}
@@ -108,8 +107,7 @@
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#clear()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
*/
public void clear() {
m1 = Double.NaN;
@@ -120,8 +118,7 @@
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return m1;
1.7 +11 -11
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/ThirdMoment.java
Index: ThirdMoment.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/ThirdMoment.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ThirdMoment.java 9 Jul 2003 20:04:10 -0000 1.6
+++ ThirdMoment.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -54,40 +54,40 @@
package org.apache.commons.math.stat.univariate.moment;
/**
- * The ThirdMoment (arithmentic mean) is calculated using the following
+ * The ThirdMoment (arithmentic mean) is calculated using the following
* <a href="http://www.spss.com/tech/stat/Algorithms/11.5/descriptives.pdf">
* recursive strategy
* </a>. Both incremental and evaluation strategies currently use this approach.
* @version $Revision$ $Date$
*/
-public class ThirdMoment extends SecondMoment{
+public class ThirdMoment extends SecondMoment {
/** third moment of values that have been added */
protected double m3 = Double.NaN;
/** temporary internal state made availabel for higher order moments */
protected double v2 = 0.0;
-
+
/** temporary internal state made availabel for higher order moments */
protected double n2 = 0.0;
-
+
/** temporary internal state made availabel for higher order moments */
protected double prevM2 = 0.0;
-
+
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (n < 1) {
m3 = m2 = m1 = 0.0;
}
-
+
/* retain a reference to the last m2*/
prevM2 = m2;
-
+
/* increment m1 and m2 (and _n0, _n1, _v) */
super.increment(d);
-
+
v2 = v * v;
n2 = (double) (n - 2);
@@ -96,7 +96,7 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return m3;
1.8 +43 -20
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
Index: Variance.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Variance.java 15 Jul 2003 03:36:36 -0000 1.7
+++ Variance.java 9 Aug 2003 04:03:40 -0000 1.8
@@ -61,35 +61,57 @@
*/
public class Variance extends AbstractStorelessUnivariateStatistic {
+ /** SecondMoment is used in incremental calculation of Variance*/
protected SecondMoment moment = null;
+ /**
+ * Boolean test to determine if this Variance should also increment
+ * the second moment, this evaluates to false when this Variance is
+ * constructed with an external SecondMoment as a parameter.
+ */
protected boolean incMoment = true;
+ /**
+ * This property maintains the latest calculated
+ * variance for efficiency when getResult() is called
+ * many times between increments.
+ */
protected double variance = Double.NaN;
+ /**
+ * Maintains the current count of inrementations that have occured.
+ * If the external SecondMoment is used, the this is updated from
+ * that moments counter
+ */
protected int n = 0;
-
+
+ /**
+ * Constructs a Variance.
+ */
public Variance() {
moment = new SecondMoment();
}
- public Variance(SecondMoment m2) {
+ /**
+ * Constructs a Variance based on an externalized second moment.
+ * @param m2 the SecondMoment (Thrid or Fourth moments work
+ * here as well.)
+ */
+ public Variance(final SecondMoment m2) {
incMoment = false;
this.moment = m2;
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#increment(double)
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (incMoment) {
moment.increment(d);
}
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
if (n < moment.n) {
@@ -98,7 +120,7 @@
} else if (moment.n <= 1) {
variance = 0.0;
} else {
- variance = moment.m2 / (moment.n0 - 1);
+ variance = moment.m2 / (moment.n0 - 1);
}
n = moment.n;
}
@@ -107,8 +129,7 @@
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#clear()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
*/
public void clear() {
if (incMoment) {
@@ -118,28 +139,30 @@
n = 0;
}
- /*UnvariateStatistic Approach */
- Mean mean = new Mean();
+ /** Mean to be used in UnvariateStatistic evaluation approach. */
+ protected Mean mean = new Mean();
/**
* Returns the variance of the available values. This uses a corrected
- * two pass algorithm of the following
+ * two pass algorithm of the following
* <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
* corrected two pass formula (14.1.8)</a>, and also referenced in:
* <p>
* "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
+ * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
* 1983, American Statistician, vol. 37, pp. 242?247.
* </p>
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
- * @return the result, Double.NaN if no values for an empty array
- * or 0.0 for a single value set.
- * @see org.apache.commons.math.stat.univariate.
- * UnivariateStatistic#evaluate(double[], int, int)
+ * @return the result, Double.NaN if no values for an empty array
+ * or 0.0 for a single value set.
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double var = Double.NaN;
1.7 +23 -10
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java
Index: StandardDeviation.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StandardDeviation.java 9 Jul 2003 20:04:10 -0000 1.6
+++ StandardDeviation.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -54,32 +54,41 @@
package org.apache.commons.math.stat.univariate.moment;
/**
- *
+ *
* @version $Revision$ $Date$
*/
public class StandardDeviation extends Variance {
+ /** */
protected double std = Double.NaN;
+ /** */
private double lastVar = 0.0;
-
+
+ /**
+ * Constructs a StandardDeviation
+ */
public StandardDeviation() {
super();
}
- public StandardDeviation(SecondMoment m2) {
+ /**
+ * Constructs a StandardDeviation with an external moment
+ * @param m2 the external moment
+ */
+ public StandardDeviation(final SecondMoment m2) {
super(m2);
}
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
super.increment(d);
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
if (lastVar != super.getResult()) {
@@ -104,15 +113,19 @@
}
/**
- * Returns the Standard Deviation on an array of values.
+ * Returns the Standard Deviation on an array of values.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
- * @return the result, Double.NaN if no values for an empty array
- * or 0.0 for a single value set.
+ * @return the result, Double.NaN if no values for an empty array
+ * or 0.0 for a single value set.
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
+
double var = super.evaluate(values, begin, length);
if (Double.isNaN(var)) {
1.7 +7 -7
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/SecondMoment.java
Index: SecondMoment.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/SecondMoment.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SecondMoment.java 9 Jul 2003 20:04:10 -0000 1.6
+++ SecondMoment.java 9 Aug 2003 04:03:40 -0000 1.7
@@ -54,7 +54,7 @@
package org.apache.commons.math.stat.univariate.moment;
/**
- * The SecondMoment is calculated using the following
+ * The SecondMoment is calculated using the following
* <a href="http://www.spss.com/tech/stat/Algorithms/11.5/descriptives.pdf">
* recursive strategy
* </a>. Both incremental and evaluation strategies currently use this approach.
@@ -67,20 +67,20 @@
/** temporary internal state made availabel for higher order moments */
protected double n1 = 0.0;
-
+
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (n < 1) {
m1 = m2 = 0.0;
}
-
+
/* increment m1 and _n0, _dev, _v) */
super.increment(d);
n1 = n0 - 1;
-
+
/* increment and return m2 */
m2 += n1 * dev * v;
@@ -96,7 +96,7 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return m2;
1.4 +5 -2
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Median.java
Index: Median.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Median.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Median.java 9 Jul 2003 20:04:12 -0000 1.3
+++ Median.java 9 Aug 2003 04:03:41 -0000 1.4
@@ -59,8 +59,11 @@
*/
public class Median extends Percentile {
+ /**
+ *
+ */
public Median() {
super(50.0);
}
-
+
}
1.7 +9 -5
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Max.java
Index: Max.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Max.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Max.java 9 Jul 2003 20:04:12 -0000 1.6
+++ Max.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -66,12 +66,13 @@
*/
public class Max extends AbstractStorelessUnivariateStatistic {
+ /** */
private double value = Double.NaN;
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
value = Double.isNaN(value) ? d : Math.max(value, d);
}
@@ -83,16 +84,19 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
}
- /* (non-Javadoc)
+ /**
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double max = Double.NaN;
if (test(values, begin, length)) {
max = values[begin];
1.7 +9 -5
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Min.java
Index: Min.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Min.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Min.java 9 Jul 2003 20:04:12 -0000 1.6
+++ Min.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -66,12 +66,13 @@
*/
public class Min extends AbstractStorelessUnivariateStatistic {
+ /** */
private double value = Double.NaN;
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
value = Double.isNaN(value) ? d : Math.min(value, d);
}
@@ -81,9 +82,9 @@
public void clear() {
value = Double.NaN;
}
-
+
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
@@ -92,7 +93,10 @@
/**
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double min = Double.NaN;
if (test(values, begin, length)) {
min = values[begin];
1.5 +32 -23
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java
Index: Percentile.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Percentile.java 9 Jul 2003 20:04:12 -0000 1.4
+++ Percentile.java 9 Aug 2003 04:03:41 -0000 1.5
@@ -61,6 +61,7 @@
*/
public class Percentile extends AbstractUnivariateStatistic {
+ /** */
private double percentile = 0.0;
/**
@@ -71,50 +72,58 @@
super();
percentile = 50.0;
}
-
+
/**
* Constructs a Percentile with the specific percentile value.
- * @param percentile
+ * @param p the percentile
*/
- public Percentile(double percentile) {
- this.percentile = percentile;
+ public Percentile(final double p) {
+ this.percentile = p;
}
/**
- * Evaluates the double[] top the specified percentile.
- * This does not alter the interal percentile state of the
+ * Evaluates the double[] top the specified percentile.
+ * This does not alter the interal percentile state of the
* statistic.
* @param values Is a double[] containing the values
* @param p Is the percentile to evaluate to.
- * @return the result of the evaluation or Double.NaN
+ * @return the result of the evaluation or Double.NaN
* if the array is empty
*/
- public double evaluate(double[] values, double p) {
- return evaluate(values, 0,values.length, p);
+ public double evaluate(final double[] values, final double p) {
+ return evaluate(values, 0, values.length, p);
}
-
+
/**
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int start, int length) {
+ public double evaluate(
+ final double[] values,
+ final int start,
+ final int length) {
+
return evaluate(values, start, length, percentile);
}
/**
- * Evaluates the double[] top the specified percentile.
- * This does not alter the interal percentile state of the
+ * Evaluates the double[] top the specified percentile.
+ * This does not alter the interal percentile state of the
* statistic.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
- * @param p Is the percentile to evaluate to.*
- * @return the result of the evaluation or Double.NaN
+ * @param p Is the percentile to evaluate to.*
+ * @return the result of the evaluation or Double.NaN
* if the array is empty
*/
- public double evaluate(double[] values, int begin, int length, double p) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length,
+ final double p) {
+
+ test(values, begin, length);
- test(values,begin,length);
-
if ((p > 100) || (p <= 0)) {
throw new IllegalArgumentException("invalid percentile value");
}
@@ -130,9 +139,9 @@
int intPos = (int) fpos;
double dif = pos - fpos;
double[] sorted = new double[length];
- System.arraycopy(values, begin,sorted, 0, length);
+ System.arraycopy(values, begin, sorted, 0, length);
Arrays.sort(sorted);
-
+
if (pos < 1) {
return sorted[0];
}
@@ -143,7 +152,7 @@
double upper = sorted[intPos];
return lower + dif * (upper - lower);
}
-
+
/**
* The default internal state of this percentile can be set.
* This will return that value.
@@ -158,7 +167,7 @@
* This will setthat value.
* @param p a value between 0 <= p <= 100
*/
- public void setPercentile(double p) {
+ public void setPercentile(final double p) {
percentile = p;
}
1.9 +10 -11
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java
Index: Sum.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Sum.java 15 Jul 2003 03:38:50 -0000 1.8
+++ Sum.java 9 Aug 2003 04:03:41 -0000 1.9
@@ -66,10 +66,9 @@
private double value = Double.NaN;
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#increment(double)
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (Double.isNaN(value)) {
value = d;
} else {
@@ -78,16 +77,14 @@
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
}
/**
- * @see org.apache.commons.math.stat.univariate.
- * StorelessUnivariateStatistic#clear()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
*/
public void clear() {
value = Double.NaN;
@@ -99,10 +96,12 @@
* @param begin processing at this point in the array
* @param length processing at this point in the array
* @return the sum of the values or Double.NaN if the array is empty
- * @see org.apache.commons.math.stat.univariate.
- * UnivariateStatistic#evaluate(double[], int, int)
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double sum = Double.NaN;
if (test(values, begin, length)) {
sum = 0.0;
1.7 +8 -6
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java
Index: SumOfSquares.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SumOfSquares.java 9 Jul 2003 20:04:13 -0000 1.6
+++ SumOfSquares.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -74,8 +74,8 @@
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
- if (Double.isNaN(value )) {
+ public void increment(final double d) {
+ if (Double.isNaN(value)) {
value = d * d;
} else {
value += d * d;
@@ -83,7 +83,7 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
@@ -104,7 +104,10 @@
* @return the sum of the squared values or Double.NaN if the array is empty
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double sumSq = Double.NaN;
if (test(values, begin, length)) {
sumSq = 0.0;
@@ -114,6 +117,5 @@
}
return sumSq;
}
-
}
1.7 +7 -4
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java
Index: Product.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Product.java 9 Jul 2003 20:04:13 -0000 1.6
+++ Product.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -74,7 +74,7 @@
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (Double.isNaN(value)) {
value = d;
} else {
@@ -83,7 +83,7 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
@@ -104,7 +104,10 @@
* @return the product values or Double.NaN if the array is empty
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double product = Double.NaN;
if (test(values, begin, length)) {
product = 1.0;
1.7 +10 -5
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfLogs.java
Index: SumOfLogs.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfLogs.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SumOfLogs.java 9 Jul 2003 20:04:13 -0000 1.6
+++ SumOfLogs.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -71,11 +71,13 @@
*/
private double value = Double.NaN;
+ /** */
private boolean init = true;
+
/**
* @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
*/
- public void increment(double d) {
+ public void increment(final double d) {
if (init) {
value = Math.log(d);
init = false;
@@ -85,7 +87,7 @@
}
/**
- * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getValue()
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
*/
public double getResult() {
return value;
@@ -98,7 +100,7 @@
value = Double.NaN;
init = true;
}
-
+
/**
* Returns the sum of the natural logs for this collection of values
* @param values Is a double[] containing the values
@@ -107,7 +109,10 @@
* @return the sumLog value or Double.NaN if the array is empty
* @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
double sumLog = Double.NaN;
if (test(values, begin, length)) {
sumLog = 0.0;
1.4 +7 -7
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/BeanTransformer.java
Index: BeanTransformer.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/BeanTransformer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BeanTransformer.java 9 Jul 2003 20:04:12 -0000 1.3
+++ BeanTransformer.java 9 Aug 2003 04:03:41 -0000 1.4
@@ -68,7 +68,7 @@
private String propertyName;
/**
- * Create a BeanTransformer
+ * Create a BeanTransformer
*/
public BeanTransformer() {
super();
@@ -76,16 +76,16 @@
/**
* Create a BeanTransformer with a specific PropertyName.
- * @param propertyName The property.
+ * @param property The property.
*/
- public BeanTransformer(String propertyName) {
- this.propertyName = propertyName;
+ public BeanTransformer(final String property) {
+ this.propertyName = property;
}
/**
* @see
org.apache.commons.math.util.NumberTransformer#transform(java.lang.Object)
*/
- public double transform(Object o) {
+ public double transform(final Object o) {
double d = Double.NaN;
try {
d =
@@ -113,7 +113,7 @@
* Set the propertyString
* @param string The string to set the property to.
*/
- public void setPropertyName(String string) {
+ public void setPropertyName(final String string) {
propertyName = string;
}
1.3 +99 -104
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/MathUtils.java
Index: MathUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/MathUtils.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MathUtils.java 7 Jul 2003 23:19:22 -0000 1.2
+++ MathUtils.java 9 Aug 2003 04:03:41 -0000 1.3
@@ -59,53 +59,53 @@
*
* @version $Revision$ $Date$
*/
-public class MathUtils {
+public final class MathUtils {
+
+ /**
+ * Private Constructor
+ */
+ private MathUtils() {
+ }
/**
* For a double precision value x, this method returns +1.0 if x >= 0
* and -1.0 if x < 0.
- *
- * @author Albert Davidson Chou
* @param x the value, a double
* @return +1.0 or -1.0, depending on the the sign of x
*/
- public static double sign( double x ) {
- if ( x >= 0.0 ) {
- return 1.0 ;
+ public static double sign(final double x) {
+ if (x >= 0.0) {
+ return 1.0;
} else {
- return -1.0 ;
+ return -1.0;
}
}
/**
* For a float value x, this method returns +1.0F if x >= 0
* and -1.0F if x < 0.
- *
- * @author Albert Davidson Chou
* @param x the value, a float
* @return +1.0F or -1.0F, depending on the the sign of x
*/
- public static float sign( float x ) {
- if ( x >= 0.0F ) {
- return 1.0F ;
+ public static float sign(final float x) {
+ if (x >= 0.0F) {
+ return 1.0F;
} else {
- return -1.0F ;
+ return -1.0F;
}
}
/**
* For a byte value x, this method returns (byte)(+1) if x >= 0
* and (byte)(-1) if x < 0.
- *
- * @author Albert Davidson Chou
* @param x the value, a byte
* @return (byte)(+1) or (byte)(-1), depending on the the sign of x
*/
- public static byte sign( byte x ) {
- if ( x >= (byte)0 ) {
- return (byte)1 ;
+ public static byte sign(final byte x) {
+ if (x >= (byte) 0) {
+ return (byte) 1;
} else {
- return (byte)(-1) ;
+ return (byte) (-1);
}
}
@@ -113,15 +113,14 @@
* For a short value x, this method returns (short)(+1) if x >= 0
* and (short)(-1) if x < 0.
*
- * @author Albert Davidson Chou
* @param x the value, a short
* @return (short)(+1) or (short)(-1), depending on the the sign of x
*/
- public static short sign( short x ) {
- if ( x >= (short)0 ) {
- return (short)1 ;
+ public static short sign(final short x) {
+ if (x >= (short) 0) {
+ return (short) 1;
} else {
- return (short)(-1) ;
+ return (short) (-1);
}
}
@@ -129,67 +128,65 @@
* For an int value x, this method returns +1 if x >= 0
* and -1 if x < 0.
*
- * @author Albert Davidson Chou
* @param x the value, an int
* @return +1 or -1, depending on the the sign of x
*/
- public static int sign( int x ) {
- if ( x >= 0 ) {
- return 1 ;
+ public static int sign(final int x) {
+ if (x >= 0) {
+ return 1;
} else {
- return -1 ;
+ return -1;
}
}
-
+
/**
* For a long value x, this method returns +1L if x >= 0
* and -1L if x < 0.
*
- * @author Albert Davidson Chou
* @param x the value, a long
* @return +1L or -1L, depending on the the sign of x
*/
- public static long sign( long x ) {
- if ( x >= 0L ) {
- return 1L ;
+ public static long sign(final long x) {
+ if (x >= 0L) {
+ return 1L;
} else {
- return -1L ;
+ return -1L;
}
}
- /**
- * Returns an exact representation of the
- * <a href="http://mathworld.wolfram.com/BinomialCoefficient.html">
- * Binomial Coefficient</a>, "<code>n choose k</code>",
- * the number of <code>k</code>-element subsets that can be selected from
- * an <code>n</code>-element set.
- * <p>
- * <Strong>Preconditions</strong>:<ul>
- * <li> <code>0 < k <= n </code> (otherwise
- * <li> <code>0 < k <= n </code> (otherwise
- * <code>IllegalArgumentException</code> is thrown)</li>
- * <li> The result is small enough to fit into a <code>long</code>. The
- * largest value of <code>n</code> for which all coefficients are
- * <code> < Long.MAX_VALUE</code> is 66. If the computed value
- * <li> The result is small enough to fit into a <code>long</code>. The
- * largest value of <code>n</code> for which all coefficients are
- * <code> < Long.MAX_VALUE</code> is 66. If the computed value
- * exceeds <code>Long.MAX_VALUE</code> an <code>ArithMeticException
- * </code> is thrown.</li>
- * </ul>
- *
- *
- * @param n the size of the set
- * @param k the size of the subsets to be counted
- * @return <code>n choose k</code>
- */
- public static long binomialCoefficient(int n, int k) {
+ /**
+ * Returns an exact representation of the
+ * <a href="http://mathworld.wolfram.com/BinomialCoefficient.html">
+ * Binomial Coefficient</a>, "<code>n choose k</code>",
+ * the number of <code>k</code>-element subsets that can be selected from
+ * an <code>n</code>-element set.
+ * <p>
+ * <Strong>Preconditions</strong>:<ul>
+ * <li> <code>0 < k <= n </code> (otherwise
+ * <li> <code>0 < k <= n </code> (otherwise
+ * <code>IllegalArgumentException</code> is thrown)</li>
+ * <li> The result is small enough to fit into a <code>long</code>. The
+ * largest value of <code>n</code> for which all coefficients are
+ * <code> < Long.MAX_VALUE</code> is 66. If the computed value
+ * <li> The result is small enough to fit into a <code>long</code>. The
+ * largest value of <code>n</code> for which all coefficients are
+ * <code> < Long.MAX_VALUE</code> is 66. If the computed value
+ * exceeds <code>Long.MAX_VALUE</code> an <code>ArithMeticException
+ * </code> is thrown.</li>
+ * </ul>
+ *
+ *
+ * @param n the size of the set
+ * @param k the size of the subsets to be counted
+ * @return <code>n choose k</code>
+ */
+ public static long binomialCoefficient(final int n, final int k) {
if (n < k) {
- throw new IllegalArgumentException
- ("must have n >= k for binomial coefficient (n,k)");
+ throw new IllegalArgumentException(
+ "must have n >= k for binomial coefficient (n,k)");
}
- if (n <= 0) {
- throw new IllegalArgumentException
- ("must have n > 0 for binomial coefficient (n,k)");
+ if (n <= 0) {
+ throw new IllegalArgumentException(
+ "must have n > 0 for binomial coefficient (n,k)");
}
if ((n == k) || (k == 0)) {
return 1;
@@ -200,8 +197,8 @@
long result = Math.round(binomialCoefficientDouble(n, k));
if (result == Long.MAX_VALUE) {
- throw new ArithmeticException
- ("result too large to represent in a long integer");
+ throw new ArithmeticException(
+ "result too large to represent in a long integer");
}
return result;
}
@@ -226,8 +223,8 @@
* @param k the size of the subsets to be counted
* @return <code>n choose k</code>
*/
- public static double binomialCoefficientDouble(int n, int k) {
- return Math.floor(Math.exp(binomialCoefficientLog(n, k)) + .5);
+ public static double binomialCoefficientDouble(final int n, final int k) {
+ return Math.floor(Math.exp(binomialCoefficientLog(n, k)) + 0.5);
}
/**
@@ -246,14 +243,14 @@
* @param k the size of the subsets to be counted
* @return <code>n choose k</code>
*/
- public static double binomialCoefficientLog(int n, int k) {
+ public static double binomialCoefficientLog(final int n, final int k) {
if (n < k) {
- throw new IllegalArgumentException
- ("must have n >= k for binomial coefficient (n,k)");
+ throw new IllegalArgumentException(
+ "must have n >= k for binomial coefficient (n,k)");
}
- if (n <= 0) {
- throw new IllegalArgumentException
- ("must have n > 0 for binomial coefficient (n,k)");
+ if (n <= 0) {
+ throw new IllegalArgumentException(
+ "must have n > 0 for binomial coefficient (n,k)");
}
if ((n == k) || (k == 0)) {
return 0;
@@ -295,11 +292,11 @@
* @param n argument
* @return <code>n!</code>
*/
- public static long factorial(int n) {
+ public static long factorial(final int n) {
long result = Math.round(factorialDouble(n));
if (result == Long.MAX_VALUE) {
- throw new ArithmeticException
- ("result too large to represent in a long integer");
+ throw new ArithmeticException(
+ "result too large to represent in a long integer");
}
return result;
}
@@ -323,33 +320,31 @@
* @param n argument
* @return <code>n!</code>
*/
- public static double factorialDouble(int n) {
- if (n <= 0) {
- throw new IllegalArgumentException
- ("must have n > 0 for n!");
+ public static double factorialDouble(final int n) {
+ if (n <= 0) {
+ throw new IllegalArgumentException("must have n > 0 for n!");
}
return Math.floor(Math.exp(factorialLog(n)) + 0.5);
}
- /**
- * Returns the natural <code>log</code> of <code>n</code>
- * <a href="http://mathworld.wolfram.com/Factorial.html">
- * Factorial</a>, or <code>n!</code>,
- * the product of the numbers <code>1,...,n</code>, as as
- * <code>double</code>.
- * <p>
- * <Strong>Preconditions</strong>:<ul>
- * <li> <code>n > 0</code> (otherwise
- * <code>IllegalArgumentException</code> is thrown)</li>
- * </ul>
- *
- * @param n argument
- * @return <code>n!</code>
- */
- public static double factorialLog(int n) {
- if (n <= 0) {
- throw new IllegalArgumentException
- ("must have n > 0 for n!");
+ /**
+ * Returns the natural <code>log</code> of <code>n</code>
+ * <a href="http://mathworld.wolfram.com/Factorial.html">
+ * Factorial</a>, or <code>n!</code>,
+ * the product of the numbers <code>1,...,n</code>, as as
+ * <code>double</code>.
+ * <p>
+ * <Strong>Preconditions</strong>:<ul>
+ * <li> <code>n > 0</code> (otherwise
+ * <code>IllegalArgumentException</code> is thrown)</li>
+ * </ul>
+ *
+ * @param n argument
+ * @return <code>n!</code>
+ */
+ public static double factorialLog(final int n) {
+ if (n <= 0) {
+ throw new IllegalArgumentException("must have n > 0 for n!");
}
double logSum = 0;
for (int i = 2; i <= n; i++) {
1.7 +23 -6
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java
Index: AbstractStorelessUnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractStorelessUnivariateStatistic.java 30 Jul 2003 21:58:11 -0000 1.6
+++ AbstractStorelessUnivariateStatistic.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -66,14 +66,16 @@
implements StorelessUnivariateStatistic {
/**
- * This implements the AbstractUnivariateStatistic impl to funnel
+ * This implements the AbstractUnivariateStatistic impl to funnel
* calculation off to the instantanious increment method. In most cases of
- * StorelessUnivariateStatistic this is never really used because more
+ * StorelessUnivariateStatistic this is never really used because more
* efficient algorithms are available for that statistic.
- * @see org.apache.commons.math.stat.univariate.
- * UnivariateStatistic#evaluate(double[], int, int)
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public double evaluate(double[] values, int begin, int length) {
+ public double evaluate(
+ final double[] values,
+ final int begin,
+ final int length) {
if (this.test(values, begin, length)) {
this.clear();
int l = begin + length;
@@ -83,5 +85,20 @@
}
return getResult();
}
+
+ /**
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#clear()
+ */
+ public abstract void clear();
+
+ /**
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#getResult()
+ */
+ public abstract double getResult();
+
+ /**
+ * @see
org.apache.commons.math.stat.univariate.StorelessUnivariateStatistic#increment(double)
+ */
+ public abstract void increment(final double d);
}
1.6 +9 -9
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/UnivariateStatistic.java
Index: UnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/UnivariateStatistic.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UnivariateStatistic.java 15 Jul 2003 03:37:10 -0000 1.5
+++ UnivariateStatistic.java 9 Aug 2003 04:03:41 -0000 1.6
@@ -54,31 +54,31 @@
package org.apache.commons.math.stat.univariate;
/**
- * UnivariateStatistic interface provides methods to evaluate
- * double[] based content using an implemented statistical approach.
- * The interface provides two "stateless" simple methods to calculate
+ * UnivariateStatistic interface provides methods to evaluate
+ * double[] based content using an implemented statistical approach.
+ * The interface provides two "stateless" simple methods to calculate
* a statistic from a double[] based parameter.
* @version $Revision$ $Date$
*/
public interface UnivariateStatistic {
-
+
/**
* Evaluates the double[] returning the result of the evaluation.
* @param values Is a double[] containing the values
- * @return the result of the evaluation or Double.NaN
+ * @return the result of the evaluation or Double.NaN
* if the array is empty
*/
double evaluate(double[] values);
/**
- * Evaluates part of a double[] returning the result
+ * Evaluates part of a double[] returning the result
* of the evaluation.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
- * @return the result of the evaluation or Double.NaN
+ * @return the result of the evaluation or Double.NaN
* if the array is empty
*/
- double evaluate(double[] values, int begin, int length);
+ double evaluate(double[] values, int begin, int length);
}
1.6 +19 -12
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java
Index: AbstractUnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractUnivariateStatistic.java 15 Jul 2003 03:37:10 -0000 1.5
+++ AbstractUnivariateStatistic.java 9 Aug 2003 04:03:41 -0000 1.6
@@ -56,7 +56,7 @@
/**
* Abstract Implementation for UnivariateStatistics.
* Provides the ability to extend polymophically so that
- * indiviual statistics do not need to implement these methods.
+ * indiviual statistics do not need to implement these methods.
* @version $Revision$ $Date$
*/
public abstract class AbstractUnivariateStatistic
@@ -65,36 +65,43 @@
/**
* This implementation provides a simple wrapper around the double[]
* and passes the request onto the evaluate(DoubleArray da) method.
- *
- * @see org.apache.commons.math.stat.univariate.
- * UnivariateStatistic#evaluate(double[])
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[])
*/
- public double evaluate(double[] values) {
+ public double evaluate(final double[] values) {
return evaluate(values, 0, values.length);
}
/**
* Subclasses of AbstractUnivariateStatistc need to implement this method.
- * @see org.apache.commons.math.stat.univariate.
- * UnivariateStatistic#evaluate(double[], int, int)
+ * @see
org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[], int,
int)
*/
- public abstract double evaluate(double[] values, int begin, int length);
+ public abstract double evaluate(
+ final double[] values,
+ final int begin,
+ final int length);
/**
- * this protected test method used by all methods to verify the content
+ * this protected test method used by all methods to verify the content
* of the array and indicies are correct.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
+ * @return this is used to determine if the array is of 0 length or not,
+ * it is used by an individual statistic to determine if continuation
+ * of a statistical calculation should continue or return NaN.
*/
- protected boolean test(double[] values, int begin, int length) {
+ protected boolean test(
+ final double[] values,
+ final int begin,
+ final int length) {
if (length > values.length) {
throw new IllegalArgumentException("length > values.length");
}
if (begin + length > values.length) {
- throw new IllegalArgumentException("begin + length > values.length");
+ throw new IllegalArgumentException(
+ "begin + length > values.length");
}
if (values == null) {
1.7 +6 -6
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java
Index: StorelessUnivariateStatistic.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/StorelessUnivariateStatistic.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StorelessUnivariateStatistic.java 15 Jul 2003 03:37:10 -0000 1.6
+++ StorelessUnivariateStatistic.java 9 Aug 2003 04:03:41 -0000 1.7
@@ -56,11 +56,11 @@
/**
* Extends the capabilities of UnivariateStatistic with a statefull incremental
* strategy through three methods for calculating a statistic without having to
- * maintain a double[] of the values. Because a StorelessUnivariateStatistic
- * does not require that a double[] storage structure be maintained with the
- * values in it, there are only a subset of known statistics can actually be
- * implemented using it. If a Statistic cannot be implemented in a Storeless
- * approach it should implement the UnivariateStatistic interface directly
+ * maintain a double[] of the values. Because a StorelessUnivariateStatistic
+ * does not require that a double[] storage structure be maintained with the
+ * values in it, there are only a subset of known statistics can actually be
+ * implemented using it. If a Statistic cannot be implemented in a Storeless
+ * approach it should implement the UnivariateStatistic interface directly
* instead.
* @version $Revision$ $Date$
*/
1.4 +4 -4
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java
Index: BeanListUnivariateImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BeanListUnivariateImpl.java 9 Jul 2003 21:45:23 -0000 1.3
+++ BeanListUnivariateImpl.java 9 Aug 2003 04:03:41 -0000 1.4
@@ -108,9 +108,9 @@
this.transformer = new BeanTransformer(propertyName);
}
- /**
- * @see org.apache.commons.math.Univariate#addValue(double)
- */
+ /**
+ * @see org.apache.commons.math.Univariate#addValue(double)
+ */
public void addValue(double v) {
String msg =
"The BeanListUnivariateImpl does not accept values "
1.15 +81 -40
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java
Index: StatUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- StatUtils.java 9 Jul 2003 21:45:23 -0000 1.14
+++ StatUtils.java 9 Aug 2003 04:03:41 -0000 1.15
@@ -59,14 +59,20 @@
* identified in the javadoc for each method, Double.NaN.
* @version $Revision$ $Date$
*/
-public class StatUtils {
+public final class StatUtils {
+
+ /**
+ * Private Constructor
+ */
+ private StatUtils() {
+ }
/**
* The sum of the values that have been added to Univariate.
* @param values Is a double[] containing the values
* @return the sum of the values or Double.NaN if the array is empty
*/
- public static double sum(double[] values) {
+ public static double sum(final double[] values) {
return sum(values, 0, values.length);
}
@@ -77,7 +83,10 @@
* @param length processing at this point in the array
* @return the sum of the values or Double.NaN if the array is empty
*/
- public static double sum(double[] values, int begin, int length) {
+ public static double sum(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double accum = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -91,7 +100,7 @@
* @param values Is a double[] containing the values
* @return the sum of the squared values or Double.NaN if the array is empty
*/
- public static double sumSq(double[] values) {
+ public static double sumSq(final double[] values) {
return sumSq(values, 0, values.length);
}
@@ -102,7 +111,10 @@
* @param length processing at this point in the array
* @return the sum of the squared values or Double.NaN if the array is empty
*/
- public static double sumSq(double[] values, int begin, int length) {
+ public static double sumSq(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double accum = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -116,7 +128,7 @@
* @param values Is a double[] containing the values
* @return the product values or Double.NaN if the array is empty
*/
- public static double product(double[] values) {
+ public static double product(final double[] values) {
return product(values, 0, values.length);
}
@@ -127,7 +139,10 @@
* @param length processing at this point in the array
* @return the product values or Double.NaN if the array is empty
*/
- public static double product(double[] values, int begin, int length) {
+ public static double product(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double product = 1.0;
for (int i = begin; i < begin + length; i++) {
@@ -141,7 +156,7 @@
* @param values Is a double[] containing the values
* @return the sumLog value or Double.NaN if the array is empty
*/
- public static double sumLog(double[] values) {
+ public static double sumLog(final double[] values) {
return sumLog(values, 0, values.length);
}
@@ -152,7 +167,10 @@
* @param length processing at this point in the array
* @return the sumLog value or Double.NaN if the array is empty
*/
- public static double sumLog(double[] values, int begin, int length) {
+ public static double sumLog(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double sumLog = 0.0;
for (int i = begin; i < begin + length; i++) {
@@ -163,60 +181,66 @@
/**
* Returns the <a href=http://www.xycoon.com/arithmetic_mean.htm>
- * arithmetic mean </a> of the available values
+ * arithmetic mean </a> of the available values
* @param values Is a double[] containing the values
* @return the mean of the values or Double.NaN if the array is empty
*/
- public static double mean(double[] values) {
+ public static double mean(final double[] values) {
return sum(values) / (double) values.length;
}
/**
* Returns the <a href=http://www.xycoon.com/arithmetic_mean.htm>
- * arithmetic mean </a> of the available values
+ * arithmetic mean </a> of the available values
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
* @return the mean of the values or Double.NaN if the array is empty
*/
- public static double mean(double[] values, int begin, int length) {
+ public static double mean(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
return sum(values, begin, length) / ((double) length);
}
/**
* Returns the variance of the available values. This uses a corrected
- * two pass algorithm of the following
+ * two pass algorithm of the following
* <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
* corrected two pass formula (14.1.8)</a>, and also referenced in:<p/>
* "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
+ * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
* 1983, American Statistician, vol. 37, pp. 242?247.
- *
+ *
* @param values Is a double[] containing the values
- * @return the result, Double.NaN if no values for an empty array
- * or 0.0 for a single value set.
+ * @return the result, Double.NaN if no values for an empty array
+ * or 0.0 for a single value set.
*/
- public static double variance(double[] values) {
+ public static double variance(final double[] values) {
return variance(values, 0, values.length);
}
/**
* Returns the variance of the available values. This uses a corrected
- * two pass algorithm of the following
+ * two pass algorithm of the following
* <a href="http://lib-www.lanl.gov/numerical/bookcpdf/c14-1.pdf">
* corrected two pass formula (14.1.8)</a>, and also referenced in:<p/>
* "Algorithms for Computing the Sample Variance: Analysis and
- * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
+ * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
* 1983, American Statistician, vol. 37, pp. 242?247.
- *
+ *
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
- * @return the result, Double.NaN if no values for an empty array
- * or 0.0 for a single value set.
+ * @return the result, Double.NaN if no values for an empty array
+ * or 0.0 for a single value set.
*/
- public static double variance(double[] values, int begin, int length) {
+ public static double variance(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double variance = Double.NaN;
@@ -231,7 +255,7 @@
accum2 += (values[i] - mean);
}
variance =
- (accum - (Math.pow(accum2, 2) / ((double)length)))
+ (accum - (Math.pow(accum2, 2) / ((double) length)))
/ (double) (length - 1);
}
return variance;
@@ -242,7 +266,7 @@
* @param values Is a double[] containing the values
* @return the maximum of the values or Double.NaN if the array is empty
*/
- public static double max(double[] values) {
+ public static double max(final double[] values) {
return max(values, 0, values.length);
}
@@ -253,14 +277,19 @@
* @param length processing at this point in the array
* @return the maximum of the values or Double.NaN if the array is empty
*/
- public static double max(double[] values, int begin, int length) {
+ public static double max(
+ final double[] values,
+ final int begin,
+ final int length) {
testInput(values, begin, length);
double max = Double.NaN;
for (int i = begin; i < begin + length; i++) {
if (i == 0) {
max = values[i];
} else {
- max = (max > values[i]) ? max : values[i];
+ if (max < values[i]) {
+ max = values[i];
+ }
}
}
return max;
@@ -271,7 +300,7 @@
* @param values Is a double[] containing the values
* @return the minimum of the values or Double.NaN if the array is empty
*/
- public static double min(double[] values) {
+ public static double min(final double[] values) {
return min(values, 0, values.length);
}
@@ -282,7 +311,11 @@
* @param length processing at this point in the array
* @return the minimum of the values or Double.NaN if the array is empty
*/
- public static double min(double[] values, int begin, int length) {
+ public static double min(
+ final double[] values,
+ final int begin,
+ final int length) {
+
testInput(values, begin, length);
double min = Double.NaN;
@@ -290,29 +323,37 @@
if (i == 0) {
min = values[i];
} else {
- min = (min < values[i]) ? min : values[i];
+ if (min > values[i]) {
+ min = values[i];
+ }
}
}
return min;
}
/**
- * Private testInput method used by all methods to verify the content
+ * Private testInput method used by all methods to verify the content
* of the array and indicies are correct.
* @param values Is a double[] containing the values
* @param begin processing at this point in the array
* @param length processing at this point in the array
*/
- private static void testInput(double[] values, int begin, int length) {
+ private static void testInput(
+ final double[] values,
+ final int begin,
+ final int length) {
- if (length > values.length)
+ if (length > values.length) {
throw new IllegalArgumentException("length > values.length");
+ }
- if (begin + length > values.length)
- throw new IllegalArgumentException("begin + length > values.length");
+ if (begin + length > values.length) {
+ throw new IllegalArgumentException(
+ "begin + length > values.length");
+ }
- if (values == null)
+ if (values == null) {
throw new IllegalArgumentException("input value array is null");
-
+ }
}
}
1.6 +6 -5
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathConfigurationException.java
Index: MathConfigurationException.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathConfigurationException.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MathConfigurationException.java 30 Jul 2003 21:58:10 -0000 1.5
+++ MathConfigurationException.java 9 Aug 2003 04:03:41 -0000 1.6
@@ -55,7 +55,6 @@
/**
* Signals a configuration problem with any of the factory methods.
- *
* @version $Revision$ $Date$
*/
public class MathConfigurationException extends MathException {
@@ -71,7 +70,7 @@
* Construct an exception with the given message.
* @param message message describing the problem
*/
- public MathConfigurationException(String message) {
+ public MathConfigurationException(final String message) {
super(message);
}
@@ -80,7 +79,9 @@
* @param message message describing the problem
* @param throwable caught exception causing this problem
*/
- public MathConfigurationException(String message, Throwable throwable) {
+ public MathConfigurationException(
+ final String message,
+ final Throwable throwable) {
super(message, throwable);
}
@@ -88,7 +89,7 @@
* Construct an exception with the given root cause.
* @param throwable caught exception causing this problem
*/
- public MathConfigurationException(Throwable throwable) {
+ public MathConfigurationException(final Throwable throwable) {
super(throwable);
}
}
1.5 +5 -6
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathException.java
Index: MathException.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathException.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MathException.java 9 Jul 2003 20:02:44 -0000 1.4
+++ MathException.java 9 Aug 2003 04:03:41 -0000 1.5
@@ -55,13 +55,12 @@
/**
* A generic exception indicating problems in the math package.
- *
* @version $Revision$ $Date$
*/
public class MathException extends Exception {
/**
- *
+ * Constructs a MathException
*/
public MathException() {
super();
@@ -70,7 +69,7 @@
/**
* @param message message describing the problem
*/
- public MathException(String message) {
+ public MathException(final String message) {
super(message);
}
@@ -78,14 +77,14 @@
* @param message message describing the problem
* @param throwable caught exception causing this problem
*/
- public MathException(String message, Throwable throwable) {
+ public MathException(final String message, final Throwable throwable) {
super(message, throwable);
}
/**
* @param throwable caught exception causing this problem
*/
- public MathException(Throwable throwable) {
+ public MathException(final Throwable throwable) {
super(throwable);
}
1.3 +1 -2
jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/BisectionSolver.java
Index: BisectionSolver.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/BisectionSolver.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BisectionSolver.java 9 Jul 2003 20:02:43 -0000 1.2
+++ BisectionSolver.java 9 Aug 2003 04:03:41 -0000 1.3
@@ -59,7 +59,6 @@
* Provide the bisection algorithm for solving for zeros of real univariate
* functions. It will only search for one zero in the given interval. The
* function is supposed to be continuous but not necessarily smooth.
- *
* @version $Revision$ $Date$
*/
public class BisectionSolver extends UnivariateRealSolverImpl {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]