diff --git a/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java b/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java
index e20114bde..d4d9bd4e1 100644
--- a/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java
+++ b/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java
@@ -114,8 +114,7 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
double n = getN();
double coefficientOne = (n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3));
- double termTwo = ((3 * Math.pow(n - 1, 2.0))
- / ((n - 2) * (n - 3)));
+ double termTwo = ((3 * Math.pow(n - 1, 2.0)) / ((n - 2) * (n - 3)));
// Calculate kurtosis
kurtosis = (coefficientOne * accum) - termTwo;
@@ -156,26 +155,19 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
* @see org.apache.commons.math.stat.Univariate#getGeometricMean()
*/
public double getGeometricMean() {
- double gMean = Math.pow(getProduct(),(1.0/getN()));
+ double gMean = Double.NaN;
+
+ if (getN() > 0) {
+ double sumLog = 0.0;
+ for (int i = 0; i < getN(); i++) {
+ sumLog += Math.log(getElement(i));
+ }
+ gMean = Math.exp(sumLog / (double)getN() );
+ }
+
return gMean;
}
- /**
- * Returns the product for this collection of values
- * @see org.apache.commons.math.stat.Univariate#getProduct()
- */
- public double getProduct() {
- double product = Double.NaN;
- if( getN() > 0 ) {
- product = 1.0;
- for( int i = 0; i < getN(); i++) {
- product *= getElement(i);
- }
- }
- return product;
- }
-
-
/**
* Returns the variance for this collection of values
* @see org.apache.commons.math.stat.Univariate#getVariance()
@@ -193,8 +185,8 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
// Calculate the sum of the squares of the distance between each
// value and the mean
- double accum = 0.0;
- for (int i = 0; i < getN(); i++){
+ double accum = 0.0;
+ for (int i = 0; i < getN(); i++) {
accum += Math.pow((getElement(i) - mean), 2.0);
}
@@ -283,22 +275,22 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
}
return accum;
}
-
+
/**
* @see org.apache.commons.math.stat.StoreUnivariate#getSortedValues()
*
- */
+ */
public double[] getSortedValues() {
double[] values = getValues();
Arrays.sort(values);
return values;
}
-
+
/**
* Returns an estimate for the pth percentile of the stored values
* @see org.apache.commons.math.stat.StoreUnivariate#getPercentile(double)
*/
- public double getPercentile(double p) {
+ public double getPercentile(double p) {
if ((p > 100) || (p <= 0)) {
throw new IllegalArgumentException("invalid percentile value");
}
@@ -307,7 +299,7 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
return Double.NaN;
}
if (n == 1) {
- return getElement(0); // always return single value for n = 1
+ return getElement(0); // always return single value for n = 1
}
double pos = p * (n + 1) / 100;
double fpos = Math.floor(pos);
@@ -322,7 +314,7 @@ public abstract class AbstractStoreUnivariate implements StoreUnivariate {
}
double lower = sorted[intPos - 1];
double upper = sorted[intPos];
- return lower + d * (upper - lower);
+ return lower + d * (upper - lower);
}
}
diff --git a/src/java/org/apache/commons/math/stat/Univariate.java b/src/java/org/apache/commons/math/stat/Univariate.java
index fa9017bd6..cb9f1023a 100644
--- a/src/java/org/apache/commons/math/stat/Univariate.java
+++ b/src/java/org/apache/commons/math/stat/Univariate.java
@@ -73,7 +73,7 @@
* @author Phil Steitz
* @author Tim O'Brien
* @author Mark Diggory
- * @version $Revision: 1.3 $ $Date: 2003/06/16 21:24:30 $
+ * @version $Revision: 1.4 $ $Date: 2003/06/21 23:38:27 $
*
*/
public interface Univariate {
@@ -99,12 +99,6 @@ public interface Univariate {
*/
abstract double getGeometricMean();
- /**
- * Returns the product of the available values
- * @return The product or Double.NaN if no values have been added.
- */
- abstract double getProduct();
-
/**
* Returns the variance of the available values.
* @return The variance, Double.NaN if no values have been added
diff --git a/src/java/org/apache/commons/math/stat/UnivariateImpl.java b/src/java/org/apache/commons/math/stat/UnivariateImpl.java
index de1557310..2534c6e5f 100644
--- a/src/java/org/apache/commons/math/stat/UnivariateImpl.java
+++ b/src/java/org/apache/commons/math/stat/UnivariateImpl.java
@@ -71,7 +71,7 @@ import org.apache.commons.math.FixedDoubleArray;
* @author Mark Diggory
* @author Brent Worden
* @author Albert Davidson Chou
- * @version $Revision: 1.13 $ $Date: 2003/06/21 02:54:55 $
+ * @version $Revision: 1.14 $ $Date: 2003/06/21 23:38:27 $
*
*/
public class UnivariateImpl implements Univariate, Serializable {
@@ -249,17 +249,6 @@ public class UnivariateImpl implements Univariate, Serializable {
return min;
}
- /* (non-Javadoc)
- * @see org.apache.commons.math.stat.Univariate#getProduct()
- */
- public double getProduct() {
- if (windowSize != Univariate.INFINITE_WINDOW) {
- return StatUtils.product(doubleArray.getElements());
- }
-
- return sumLog;
- }
-
/* (non-Javadoc)
* @see org.apache.commons.math.stat.Univariate#getGeometricMean()
*/
diff --git a/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java b/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java
index 22faa9293..9a036dcf6 100644
--- a/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java
+++ b/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java
@@ -64,7 +64,7 @@ import junit.framework.TestSuite;
* Test cases for the {@link Univariate} class.
*
* @author Phil Steitz
- * @version $Revision: 1.2 $ $Date: 2003/06/21 23:02:51 $
+ * @version $Revision: 1.3 $ $Date: 2003/06/21 23:38:27 $
*/
public final class ListUnivariateImplTest extends TestCase {
@@ -161,7 +161,6 @@ public final class ListUnivariateImplTest extends TestCase {
u.addValue( 3.0 );
u.addValue( 4.0 );
- //assertEquals( "Product not expected", 24.0, u.getProduct(), Double.MIN_VALUE );
assertEquals( "Geometric mean not expected", 2.213364, u.getGeometricMean(), 0.00001 );
// Now test rolling - UnivariateImpl should discount the contribution
@@ -171,7 +170,6 @@ public final class ListUnivariateImplTest extends TestCase {
}
// Values should be (2,3,4,5,6,7,8,9,10,11)
- //assertEquals( "Product not expected", 39916800.0, u.getProduct(), 0.00001 );
assertEquals( "Geometric mean not expected", 5.755931, u.getGeometricMean(), 0.00001 );
diff --git a/src/test/org/apache/commons/math/stat/UnivariateImplTest.java b/src/test/org/apache/commons/math/stat/UnivariateImplTest.java
index 4a7159518..d3b1ed903 100644
--- a/src/test/org/apache/commons/math/stat/UnivariateImplTest.java
+++ b/src/test/org/apache/commons/math/stat/UnivariateImplTest.java
@@ -62,7 +62,7 @@ import junit.framework.TestSuite;
*
* @author Phil Steitz
* @author Tim Obrien
- * @version $Revision: 1.2 $ $Date: 2003/06/21 02:08:23 $
+ * @version $Revision: 1.3 $ $Date: 2003/06/21 23:38:27 $
*/
public final class UnivariateImplTest extends TestCase {
@@ -175,8 +175,6 @@ public final class UnivariateImplTest extends TestCase {
u.addValue( 3.0 );
u.addValue( 4.0 );
- assertEquals( "Product not expected", 24.0, u.getProduct(),
- Double.MIN_VALUE );
assertEquals( "Geometric mean not expected", 2.213364,
u.getGeometricMean(), 0.00001 );
@@ -187,8 +185,6 @@ public final class UnivariateImplTest extends TestCase {
}
// Values should be (2,3,4,5,6,7,8,9,10,11)
- assertEquals( "Product not expected", 39916800.0,
- u.getProduct(), 0.00001 );
assertEquals( "Geometric mean not expected", 5.755931,
u.getGeometricMean(), 0.00001 );
}