Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/17/12 11:18:40 (12 years ago)
Author:
mkommend
Message:

#1951:

  • Added linear scaling parameter to data analysis problems.
  • Adapted interfaces, evaluators and analyzers accordingly.
  • Added OnlineBoundedMeanSquaredErrorCalculator.
  • Adapted symbolic regression sample unit test.
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineBoundedMeanSquaredErrorCalculator.cs

    r8650 r8664  
    2424
    2525namespace HeuristicLab.Problems.DataAnalysis {
    26   public class OnlineMeanSquaredErrorCalculator : IOnlineCalculator {
     26  public class OnlineBoundedMeanSquaredErrorCalculator : IOnlineCalculator {
    2727
    28     private double sse;
     28    private double errorSum;
    2929    private int n;
    30     public double MeanSquaredError {
     30    public double BoundedMeanSquaredError {
    3131      get {
    32         return n > 0 ? sse / n : 0.0;
     32        return n > 0 ? errorSum / n : 0.0;
    3333      }
    3434    }
    3535
    36     public OnlineMeanSquaredErrorCalculator() {
     36    public double LowerBound { get; private set; }
     37    public double UpperBound { get; private set; }
     38
     39
     40    public OnlineBoundedMeanSquaredErrorCalculator(double lowerBound, double upperbound) {
     41      LowerBound = lowerBound;
     42      UpperBound = upperbound;
    3743      Reset();
    3844    }
     
    4450    }
    4551    public double Value {
    46       get { return MeanSquaredError; }
     52      get { return BoundedMeanSquaredError; }
    4753    }
    4854    public void Reset() {
    4955      n = 0;
    50       sse = 0.0;
     56      errorSum = 0.0;
    5157      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    5258    }
     
    5864      } else {
    5965        double error = estimated - original;
    60         sse += error * error;
     66        if (estimated < LowerBound || estimated > UpperBound)
     67          errorSum += Math.Abs(error);
     68        else
     69          errorSum += error * error;
    6170        n++;
    6271        errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded);        // n >= 1
     
    6574    #endregion
    6675
    67     public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     76    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, double lowerBound, double upperBound, out OnlineCalculatorError errorState) {
    6877      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    6978      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    70       OnlineMeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();
     79      OnlineBoundedMeanSquaredErrorCalculator boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowerBound, upperBound);
    7180
    7281      // always move forward both enumerators (do not use short-circuit evaluation!)
     
    7483        double original = originalEnumerator.Current;
    7584        double estimated = estimatedEnumerator.Current;
    76         mseCalculator.Add(original, estimated);
    77         if (mseCalculator.ErrorState != OnlineCalculatorError.None) break;
     85        boundedMseCalculator.Add(original, estimated);
     86        if (boundedMseCalculator.ErrorState != OnlineCalculatorError.None) break;
    7887      }
    7988
    8089      // check if both enumerators are at the end to make sure both enumerations have the same length
    81       if (mseCalculator.ErrorState == OnlineCalculatorError.None &&
     90      if (boundedMseCalculator.ErrorState == OnlineCalculatorError.None &&
    8291         (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
    8392        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    8493      } else {
    85         errorState = mseCalculator.ErrorState;
    86         return mseCalculator.MeanSquaredError;
     94        errorState = boundedMseCalculator.ErrorState;
     95        return boundedMseCalculator.BoundedMeanSquaredError;
    8796      }
    8897    }
Note: See TracChangeset for help on using the changeset viewer.