mdiggory 2003/06/21 16:38:27 Modified: math/src/java/org/apache/commons/math/stat Univariate.java UnivariateImpl.java AbstractStoreUnivariate.java math/src/test/org/apache/commons/math/stat ListUnivariateImplTest.java UnivariateImplTest.java Log: Removing Product from Univariate Interface, applying sumLog changes to geomean in AbstractStoreUnivariate. Revision Changes Path 1.4 +1 -7 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/Univariate.java Index: Univariate.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/Univariate.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Univariate.java 16 Jun 2003 21:24:30 -0000 1.3 +++ Univariate.java 21 Jun 2003 23:38:27 -0000 1.4 @@ -100,12 +100,6 @@ 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 * or 0.0 for a single value set. 1.14 +1 -12 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/UnivariateImpl.java Index: UnivariateImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/UnivariateImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- UnivariateImpl.java 21 Jun 2003 02:54:55 -0000 1.13 +++ UnivariateImpl.java 21 Jun 2003 23:38:27 -0000 1.14 @@ -250,17 +250,6 @@ } /* (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() */ public double getGeometricMean() { 1.6 +17 -25 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java Index: AbstractStoreUnivariate.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/AbstractStoreUnivariate.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractStoreUnivariate.java 21 Jun 2003 02:16:43 -0000 1.5 +++ AbstractStoreUnivariate.java 21 Jun 2003 23:38:27 -0000 1.6 @@ -114,8 +114,7 @@ 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,25 +155,18 @@ * @see org.apache.commons.math.stat.Univariate#getGeometricMean() */ public double getGeometricMean() { - double gMean = Math.pow(getProduct(),(1.0/getN())); - return gMean; - } + double gMean = Double.NaN; - /** - * 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); + 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 product; + + return gMean; } - /** * Returns the variance for this collection of values @@ -193,8 +185,8 @@ // 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 @@ } 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 @@ 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 @@ } double lower = sorted[intPos - 1]; double upper = sorted[intPos]; - return lower + d * (upper - lower); + return lower + d * (upper - lower); } } 1.3 +1 -3 jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java Index: ListUnivariateImplTest.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/ListUnivariateImplTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ListUnivariateImplTest.java 21 Jun 2003 23:02:51 -0000 1.2 +++ ListUnivariateImplTest.java 21 Jun 2003 23:38:27 -0000 1.3 @@ -161,7 +161,6 @@ 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 @@ } // 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 ); 1.3 +1 -5 jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/UnivariateImplTest.java Index: UnivariateImplTest.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/UnivariateImplTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- UnivariateImplTest.java 21 Jun 2003 02:08:23 -0000 1.2 +++ UnivariateImplTest.java 21 Jun 2003 23:38:27 -0000 1.3 @@ -175,8 +175,6 @@ 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 @@ } // 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 ); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]