Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8113


Ignore:
Timestamp:
06/26/12 08:27:57 (12 years ago)
Author:
gkronber
Message:

#1788 changed symbolic regression evaluators to bound estimated values after scaling instead of before.

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r7677 r8113  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    5960    private static double[] cache;
    6061
    61     protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) {
     62    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
     63      double lowerEstimationLimit, double upperEstimationLimit,
     64      IOnlineCalculator calculator, int maxRows) {
    6265      if (cache == null || cache.GetLength(0) < maxRows) {
    6366        cache = new double[maxRows];
     
    8386      //calculate the quality by using the passed online calculator
    8487      targetValuesEnumerator = targetValues.GetEnumerator();
    85       i = 0;
    86       while (targetValuesEnumerator.MoveNext()) {
    87         double target = targetValuesEnumerator.Current;
    88         double estimated = cache[i] * beta + alpha;
    89         calculator.Add(target, estimated);
    90         i++;
     88      var scaledBoundedEstimatedValuesEnumerator = (from r in Enumerable.Range(0, i)
     89                                                    select cache[r] * beta + alpha)
     90        .LimitToRange(lowerEstimationLimit, upperEstimationLimit)
     91        .GetEnumerator();
     92      while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
     93        calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
    9194      }
    9295    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r7677 r8113  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var maeCalculator = new OnlineMaxAbsoluteErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows);
    6564        errorState = maeCalculator.ErrorState;
    6665        mse = maeCalculator.MaxAbsoluteError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6868        mse = OnlineMaxAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     69      }
    7070      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7171      else return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r7677 r8113  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var maeCalculator = new OnlineMeanAbsoluteErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows);
    6564        errorState = maeCalculator.ErrorState;
    6665        mse = maeCalculator.MeanAbsoluteError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit,
     68                                                                                  upperEstimationLimit);
    6869        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     70      }
    7071      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7172      else return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7677 r8113  
    5656      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5757      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    58       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    5958      OnlineCalculatorError errorState;
    6059
     
    6261      if (applyLinearScaling) {
    6362        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
    64         CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows);
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
    6564        errorState = mseCalculator.ErrorState;
    6665        mse = mseCalculator.MeanSquaredError;
    67       } else
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6868        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    69 
     69      }
    7070      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    7171      else return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs

    r7259 r8113  
    2424namespace HeuristicLab.Problems.DataAnalysis {
    2525  [Flags]
    26   public enum OnlineCalculatorError { 
     26  public enum OnlineCalculatorError {
    2727    /// <summary>
    2828    /// No error occurred
    2929    /// </summary>
    30     None = 0, 
     30    None = 0,
    3131    /// <summary>
    3232    /// An invalid value has been added (often +/- Infinity and NaN are invalid values)
    3333    /// </summary>
    34     InvalidValueAdded = 1, 
     34    InvalidValueAdded = 1,
    3535    /// <summary>
    3636    /// The number of elements added to the evaluator is not sufficient to calculate the result value
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineLinearScalingParameterCalculator.cs

    r7259 r8113  
    5555    }
    5656
    57     private int cnt;
    5857    private OnlineMeanAndVarianceCalculator targetMeanCalculator;
    5958    private OnlineMeanAndVarianceCalculator originalMeanAndVarianceCalculator;
     
    6867
    6968    public void Reset() {
    70       cnt = 0;
    7169      targetMeanCalculator.Reset();
    7270      originalMeanAndVarianceCalculator.Reset();
     
    8583      originalTargetCovarianceCalculator.Add(original, target);
    8684
    87       cnt++;
    8885    }
    8986
Note: See TracChangeset for help on using the changeset viewer.