Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4126


Ignore:
Timestamp:
08/01/10 18:11:15 (14 years ago)
Author:
gkronber
Message:

Added check in correlation coefficient calculation to prevent division by zero. #1116

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlinePearsonsRSquaredEvaluator.cs

    r4122 r4126  
    3131    public double RSquared {
    3232      get {
    33         double r = covEvaluator.Covariance / (Math.Sqrt(sxEvaluator.PopulationVariance) * Math.Sqrt(syEvaluator.PopulationVariance));
    34         return r * r;
     33        double xVar = sxEvaluator.PopulationVariance;
     34        double yVar = syEvaluator.PopulationVariance;
     35        if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) {
     36          return 0.0;
     37        } else {
     38          double r = covEvaluator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar));
     39          return r * r;
     40        }
    3541      }
    3642    }
Note: See TracChangeset for help on using the changeset viewer.