commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Warren Tang (Updated) (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (MATH-691) Statistics.setVarianceImpl makes getStandardDeviation produce NaN
Date Sun, 16 Oct 2011 17:52:11 GMT

     [ https://issues.apache.org/jira/browse/MATH-691?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Warren Tang updated MATH-691:
-----------------------------

    Description: 
Invoking SummaryStatistics.setVarianceImpl(new Variance(true/false) makes getStandardDeviation
produce NaN. The code to reproduce it:

{code:java}
int[] scores = {1, 2, 3, 4};
SummaryStatistics stats = new SummaryStatistics();
stats.setVarianceImpl(new Variance(false)); //use "population variance"
for(int i : scores) {
  stats.addValue(i);
}
double sd = stats.getStandardDeviation();
System.out.println(sd);
{code}

A workaround suggested by Mikkel is:
{code:java}
  double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN());
{code}

  was:
Invoking SummaryStatistics.setVarianceImpl(new Variance(true/false) makes getStandardDeviation
produce NaN. The code to reproduce it:

{code:java}
int[] scores = {1, 2, 3, 4};
SummaryStatistics stats = new SummaryStatistics();
stats.setVarianceImpl(new Variance(false)); //use "population variance"
for(int i : scores) {
  stats.addValue(i);
}
double sd = stats.getStandardDeviation();
System.out.println(sd);
{code}

A workaround suggested by Mikkel is:
{code:java}
  double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN());
{code}
Here is another from Phil:
{code:java}
SummaryStatistics stats = new SummaryStatistics();
Variance variance = (Variance) stats.getVarianceImpl();
variance.setBiasCorrected(false);
{code}

    
> Statistics.setVarianceImpl makes getStandardDeviation produce NaN
> -----------------------------------------------------------------
>
>                 Key: MATH-691
>                 URL: https://issues.apache.org/jira/browse/MATH-691
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: Windows 7 64-bit, java version 1.6.0_23
>            Reporter: Warren Tang
>            Priority: Minor
>   Original Estimate: 5h
>  Remaining Estimate: 5h
>
> Invoking SummaryStatistics.setVarianceImpl(new Variance(true/false) makes getStandardDeviation
produce NaN. The code to reproduce it:
> {code:java}
> int[] scores = {1, 2, 3, 4};
> SummaryStatistics stats = new SummaryStatistics();
> stats.setVarianceImpl(new Variance(false)); //use "population variance"
> for(int i : scores) {
>   stats.addValue(i);
> }
> double sd = stats.getStandardDeviation();
> System.out.println(sd);
> {code}
> A workaround suggested by Mikkel is:
> {code:java}
>   double sd = FastMath.sqrt(stats.getSecondMoment() / stats.getN());
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message