Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/05/10 17:14:22 (14 years ago)
Author:
gkronber
Message:

Improved efficiency of analyzers and evaluators for regression problems. #1074

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs

    r3995 r3996  
    8383
    8484    public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end, double beta, double alpha) {
    85       //IEnumerable<double> estimatedValues = from x in interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start))
    86       //                                      let boundedX = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, x * beta + alpha))
    87       //                                      select double.IsNaN(boundedX) ? upperEstimationLimit : boundedX;
    8885      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start));
    8986      IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, start, end);
    9087      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    9188      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    92       double cnt = 0;
    93       double sse = 0;
     89      OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
    9490
    9591      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    9692        double estimated = estimatedEnumerator.Current * beta + alpha;
    9793        double original = originalEnumerator.Current;
    98         estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));
    9994        if (double.IsNaN(estimated))
    10095          estimated = upperEstimationLimit;
    101         if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) &&
    102             !double.IsNaN(original) && !double.IsInfinity(original)) {
    103           double error = estimated - original;
    104           sse += error * error;
    105           cnt++;
    106         }
     96        else
     97          estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));
     98        mseEvaluator.Add(original, estimated);
    10799      }
    108100
    109101      if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) {
    110102        throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");
    111       } else if (cnt == 0) {
    112         throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");
    113103      } else {
    114         double mse = sse / cnt;
    115         return mse;
     104        return mseEvaluator.MeanSquaredError;
    116105      }
    117106    }
Note: See TracChangeset for help on using the changeset viewer.