Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 64731 invoked from network); 9 Feb 2008 23:43:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Feb 2008 23:43:13 -0000 Received: (qmail 51286 invoked by uid 500); 9 Feb 2008 23:43:05 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 51218 invoked by uid 500); 9 Feb 2008 23:43:05 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 51209 invoked by uid 99); 9 Feb 2008 23:43:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Feb 2008 15:43:05 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Feb 2008 23:42:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D3D671A9832; Sat, 9 Feb 2008 15:42:46 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r620221 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/stat/descriptive/ java/org/apache/commons/math/stat/descriptive/moment/ site/xdoc/ test/org/apache/commons/math/stat/descriptive/ Date: Sat, 09 Feb 2008 23:42:46 -0000 To: commits@commons.apache.org From: psteitz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080209234246.D3D671A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: psteitz Date: Sat Feb 9 15:42:44 2008 New Revision: 620221 URL: http://svn.apache.org/viewvc?rev=620221&view=rev Log: Added getSumOfLogs method to SummaryStatistics and made sum of logs instance used by GeometricMean configurable. JIRA: MATH-191 Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SummaryStatisticsTest.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=620221&r1=620220&r2=620221&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Sat Feb 9 15:42:44 2008 @@ -120,7 +120,7 @@ protected SumOfLogs sumLog = new SumOfLogs(); /** geoMean of values that have been added */ - protected GeometricMean geoMean = new GeometricMean(); + protected GeometricMean geoMean = new GeometricMean(sumLog); /** mean of values that have been added */ protected Mean mean = new Mean(); @@ -174,16 +174,18 @@ minImpl.increment(value); maxImpl.increment(value); sumLogImpl.increment(value); - geoMean.increment(value); secondMoment.increment(value); - // If mean or variance have been overridden, - // need to increment these, since they don't have secondMoment + // If mean, variance or geomean have been overridden, + // need to increment these if (!(meanImpl instanceof Mean)) { meanImpl.increment(value); } if (!(varianceImpl instanceof Variance)) { varianceImpl.increment(value); } + if (!(geoMeanImpl instanceof GeometricMean)) { + geoMeanImpl.increment(value); + } n++; } @@ -297,6 +299,17 @@ } /** + * Returns the sum of the logs of the values that have been added. + *

+ * Double.NaN is returned if no values have been added.

+ * + * @return the sum of logs + */ + public double getSumOfLogs() { + return sumLogImpl.getResult(); + } + + /** * Generates a text report displaying * summary statistics from values that * have been added. @@ -313,6 +326,7 @@ outBuffer.append("variance: " + getVariance() + "\n"); outBuffer.append("sum of squares: " + getSumsq() + "\n"); outBuffer.append("standard deviation: " + getStandardDeviation() + "\n"); + outBuffer.append("sum of logs: " + getSumOfLogs() + "\n"); return outBuffer.toString(); } @@ -505,6 +519,7 @@ StorelessUnivariateStatistic sumLogImpl) { checkEmpty(); this.sumLogImpl = sumLogImpl; + geoMean.setSumLogImpl(sumLogImpl); } /** Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java?rev=620221&r1=620220&r2=620221&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java Sat Feb 9 15:42:44 2008 @@ -17,6 +17,7 @@ package org.apache.commons.math.stat.descriptive.moment; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; +import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; /** @@ -49,7 +50,7 @@ private static final long serialVersionUID = -8178734905303459453L; /** Wrapped SumOfLogs instance */ - private SumOfLogs sumOfLogs; + private StorelessUnivariateStatistic sumOfLogs; /** * Create a GeometricMean instance @@ -59,6 +60,13 @@ } /** + * Create a GeometricMean instance using the given SumOfLogs instance + */ + public GeometricMean(SumOfLogs sumOfLogs) { + this.sumOfLogs = sumOfLogs; + } + + /** * @see org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic#increment(double) */ public void increment(final double d) { @@ -110,6 +118,42 @@ */ public long getN() { return sumOfLogs.getN(); + } + + /** + *

Sets the implementation for the sum of logs.

+ *

This method must be activated before any data has been added - i.e., + * before {@link #addValue(double) addValue} has been used to add data; + * otherwise an IllegalStateException will be thrown.

+ * + * @param sumLogImpl the StorelessUnivariateStatistic instance to use + * for computing the log sum + * @throws IllegalStateException if data has already been added + * (i.e if n > 0) + */ + public void setSumLogImpl( + StorelessUnivariateStatistic sumLogImpl) { + checkEmpty(); + this.sumOfLogs = sumLogImpl; + } + + /** + * Returns the currently configured sum of logs implementation + * + * @return the StorelessUnivariateStatistic implementing the log sum + */ + public StorelessUnivariateStatistic getSumLogImpl() { + return sumOfLogs; + } + + /** + * Throws IllegalStateException if n > 0. + */ + private void checkEmpty() { + if (getN() > 0) { + throw new IllegalStateException( + "Implementation must be configured before values are added."); + } } } Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=620221&r1=620220&r2=620221&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sat Feb 9 15:42:44 2008 @@ -162,7 +162,11 @@ covariance) - Added multivariate summary statistics + Added multivariate summary statistics. + + + Added getSumOfLogs method to SummaryStatistics and made SumOfLogs + instance used by GeometricMean configurable.