commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] [Created] (MATH-588) Weighted Mean evaluation may not have optimal numerics
Date Sun, 12 Jun 2011 18:19:51 GMT
Weighted Mean evaluation may not have optimal numerics

                 Key: MATH-588
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 2.2, 2.1
            Reporter: Phil Steitz
             Fix For: 3.0

I recently got this in a test run
testWeightedConsistency(org.apache.commons.math.stat.descriptive.moment.MeanTest)  Time elapsed:
0 sec  <<< FAILURE!
java.lang.AssertionError: expected:<0.002282165958997601> but was:<0.002282165958997157>
	at org.junit.Assert.failNotEquals(
	at org.junit.Assert.assertEquals(
	at org.apache.commons.math.TestUtils.assertRelativelyEquals(
	at org.apache.commons.math.TestUtils.assertRelativelyEquals(
	at org.apache.commons.math.stat.descriptive.UnivariateStatisticAbstractTest.testWeightedConsistency(

The correction formula used to compute the unweighted mean may not be appropriate or optimal
in the presence of weights:

// Compute initial estimate using definitional formula
double sumw = sum.evaluate(weights,begin,length);
double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

// Compute correction factor in second pass
double correction = 0;
for (int i = begin; i < begin + length; i++) {
  correction += weights[i] * (values[i] - xbarw);
return xbarw + (correction/sumw);

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message