You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/11/26 17:23:02 UTC
svn commit: r1206477 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
Author: psteitz
Date: Sat Nov 26 16:23:02 2011
New Revision: 1206477
URL: http://svn.apache.org/viewvc?rev=1206477&view=rev
Log:
Keep math-supplied statistics tied to their internal moments.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java?rev=1206477&r1=1206476&r2=1206477&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java Sat Nov 26 16:23:02 2011
@@ -88,10 +88,10 @@ public class SummaryStatistics implement
protected GeometricMean geoMean = new GeometricMean(sumLog);
/** mean of values that have been added */
- protected Mean mean = new Mean();
+ protected Mean mean = new Mean(secondMoment);
/** variance of values that have been added */
- protected Variance variance = new Variance();
+ protected Variance variance = new Variance(secondMoment);
/** Sum statistic implementation - can be reset by setter. */
private StorelessUnivariateStatistic sumImpl = sum;
@@ -202,11 +202,7 @@ public class SummaryStatistics implement
* @return the mean
*/
public double getMean() {
- if (mean == meanImpl) {
- return new Mean(secondMoment).getResult();
- } else {
- return meanImpl.getResult();
- }
+ return meanImpl.getResult();
}
/**
@@ -236,11 +232,7 @@ public class SummaryStatistics implement
* @return the variance
*/
public double getVariance() {
- if (varianceImpl == variance) {
- return new Variance(secondMoment).getResult();
- } else {
- return varianceImpl.getResult();
- }
+ return varianceImpl.getResult();
}
/**
@@ -661,20 +653,29 @@ public class SummaryStatistics implement
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
dest.maxImpl = source.maxImpl.copy();
- dest.meanImpl = source.meanImpl.copy();
dest.minImpl = source.minImpl.copy();
dest.sumImpl = source.sumImpl.copy();
- dest.varianceImpl = source.varianceImpl.copy();
dest.sumLogImpl = source.sumLogImpl.copy();
dest.sumsqImpl = source.sumsqImpl.copy();
+ dest.secondMoment = source.secondMoment.copy();
+ dest.n = source.n;
+
+ // Keep commons-math supplied statistics with embedded moments in synch
+ if (source.getVarianceImpl() instanceof Variance) {
+ dest.varianceImpl = new Variance(dest.secondMoment);
+ } else {
+ dest.varianceImpl = source.varianceImpl.copy();
+ }
+ if (source.meanImpl instanceof Mean) {
+ dest.meanImpl = new Mean(dest.secondMoment);
+ } else {
+ dest.meanImpl = source.meanImpl.copy();
+ }
if (source.getGeoMeanImpl() instanceof GeometricMean) {
- // Keep geoMeanImpl, sumLogImpl in synch
dest.geoMeanImpl = new GeometricMean((SumOfLogs) dest.sumLogImpl);
} else {
dest.geoMeanImpl = source.geoMeanImpl.copy();
}
- SecondMoment.copy(source.secondMoment, dest.secondMoment);
- dest.n = source.n;
// Make sure that if stat == statImpl in source, same
// holds in dest; otherwise copy stat