Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5746


Ignore:
Timestamp:
03/18/11 09:57:44 (14 years ago)
Author:
gkronber
Message:

#1418 bug fixes and minor changes to improve performance in online evaluators.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineLinearScalingParameterCalculator.cs

    r5722 r5746  
    7878    /// </summary>
    7979    public void Add(double original, double target) {
    80       if (IsValidValue(original) && IsValidValue(target)) {
    81         targetMeanCalculator.Add(target);
    82         originalMeanAndVarianceCalculator.Add(original);
    83         originalTargetCovarianceEvaluator.Add(original, target);
     80      // validity of values is checked in mean clculator and covariance calculator
     81      targetMeanCalculator.Add(target);
     82      originalMeanAndVarianceCalculator.Add(original);
     83      originalTargetCovarianceEvaluator.Add(original, target);
    8484
    85         cnt++;
    86       }
     85      cnt++;
    8786    }
    88 
    89     private static bool IsValidValue(double d) {
    90       return !double.IsInfinity(d) && !double.IsNaN(d) && d > -1.0E07 && d < 1.0E07;  // don't consider very large or very small values for scaling
    91     }
    92 
    9387
    9488    /// <summary>
     
    109103        double originalElement = originalEnumerator.Current;
    110104        double targetElement = targetEnumerator.Current;
    111         calculator.Add(originalElement, targetElement);
     105        // don't consider very large or very small values for scaling
     106        // careful: this also excludes infinity and NaN values
     107        if (originalElement > -1.0E07 && originalElement < 1.0E07) {
     108          calculator.Add(originalElement, targetElement);
     109        }
    112110      }
    113111
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanSquaredErrorEvaluator.cs

    r5564 r5746  
    3030    public double MeanSquaredError {
    3131      get {
    32         if (n < 1)
    33           throw new InvalidOperationException("No elements");
    34         else
    35           return sse / n;
     32        return n > 0 ? sse / n : 0.0;
    3633      }
    3734    }
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineNormalizedMeanSquaredErrorEvaluator.cs

    r5564 r5746  
    3030    public double NormalizedMeanSquaredError {
    3131      get {
    32         return meanSquaredErrorCalculator.Mean / originalVarianceCalculator.Variance;
     32        double var = originalVarianceCalculator.Variance;
     33        double m = meanSquaredErrorCalculator.Mean;
     34        return var > 0 ? m / var : 0.0;
    3335      }
    3436    }
     
    5153
    5254    public void Add(double original, double estimated) {
    53       if (double.IsNaN(estimated) || double.IsInfinity(estimated) ||
    54           double.IsNaN(original) || double.IsInfinity(original)) {
    55         throw new ArgumentException("Mean squared error is not defined for NaN or infinity elements");
    56       } else {
    57         double error = estimated - original;
    58         meanSquaredErrorCalculator.Add(error * error);
    59         originalVarianceCalculator.Add(original);
    60       }
     55      // no need to check for validity of values explicitly as it is checked in the meanAndVariance calculator anyway
     56      double error = estimated - original;
     57      meanSquaredErrorCalculator.Add(error * error);
     58      originalVarianceCalculator.Add(original);
    6159    }
    6260    #endregion
  • branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs

    r5742 r5746  
    5656
    5757    public void Add(double x, double y) {
    58       if (IsInvalidValue(x) || IsInvalidValue(y)) {
    59         throw new ArgumentException("R² is not defined for variables with NaN or infinity values.");
    60       }
     58      // no need to check validity of values explicitly here as it is checked in all three evaluators
    6159      covEvaluator.Add(x, y);
    6260      sxEvaluator.Add(x);
     
    6563
    6664    #endregion
    67 
    68     private static bool IsInvalidValue(double x) {
    69       return double.IsNaN(x) || double.IsInfinity(x);
    70     }
    7165
    7266    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) {
     
    7973        double estimated = secondEnumerator.Current;
    8074        double original = firstEnumerator.Current;
    81         if (!IsInvalidValue(estimated) && !IsInvalidValue(original))
    82           rSquaredEvaluator.Add(original, estimated);
     75        rSquaredEvaluator.Add(original, estimated);
    8376      }
    8477
Note: See TracChangeset for help on using the changeset viewer.