Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/09/10 17:28:32 (15 years ago)
Author:
gkronber
Message:

Added first version of architecture altering operators for ADFs. #290 (Implement ADFs)

File:
1 edited

Legend:

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

    r3253 r3294  
    3939    }
    4040
    41     public static double Calculate(DoubleMatrix values) {
    42       double sse = 0;
    43       double cnt = 0;
    44       for (int i = 0; i < values.Rows; i++) {
    45         double estimated = values[i, ESTIMATION_INDEX];
    46         double target = values[i, ORIGINAL_INDEX];
    47         if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
    48             !double.IsNaN(target) && !double.IsInfinity(target)) {
    49           double error = estimated - target;
     41    public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) {
     42      double sse = 0.0;
     43      int cnt = 0;
     44      var originalEnumerator = original.GetEnumerator();
     45      var estimatedEnumerator = estimated.GetEnumerator();
     46      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     47        double e = estimatedEnumerator.Current;
     48        double o = originalEnumerator.Current;
     49        if (!double.IsNaN(e) && !double.IsInfinity(e) &&
     50            !double.IsNaN(o) && !double.IsInfinity(o)) {
     51          double error = e - o;
    5052          sse += error * error;
    5153          cnt++;
    5254        }
    5355      }
    54       if (cnt > 0) {
     56      if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) {
     57        throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");
     58      } else if (cnt == 0) {
     59        throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");
     60      } else {
    5561        double mse = sse / cnt;
    5662        return mse;
    57       } else {
    58         throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");
    5963      }
     64    }
     65
     66    public static double Calculate(DoubleMatrix values) {
     67      var original = from row in Enumerable.Range(0, values.Rows)
     68                     select values[row, ORIGINAL_INDEX];
     69      var estimated = from row in Enumerable.Range(0, values.Rows)
     70                      select values[row, ORIGINAL_INDEX];
     71      return Calculate(original, estimated);
    6072    }
    6173  }
Note: See TracChangeset for help on using the changeset viewer.