Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/30/12 22:48:32 (13 years ago)
Author:
mkommend
Message:

#1788: Implemente new symbolic regression evaluators.

File:
1 copied

Legend:

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

    r7672 r7677  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3029
    3130namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    32   [Item("Mean squared error Evaluator", "Calculates the mean squared error of a symbolic regression solution.")]
     31  [Item("Mean absolute error Evaluator", "Calculates the mean absolute error of a symbolic regression solution.")]
    3332  [StorableClass]
    34   public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
     33  public class SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3534    public override bool Maximization { get { return false; } }
    36     [ThreadStatic]
    37     private static double[] estimatedValuesCache;
    38 
    3935    [StorableConstructor]
    40     protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }
    41     protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner)
     36    protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(bool deserializing) : base(deserializing) { }
     37    protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator original, Cloner cloner)
    4238      : base(original, cloner) {
    4339    }
    4440    public override IDeepCloneable Clone(Cloner cloner) {
    45       return new SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(this, cloner);
     41      return new SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(this, cloner);
    4642    }
    47     public SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator() : base() { }
     43    public SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator() : base() { }
    4844
    4945    public override IOperation Apply() {
     
    5955    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    6056      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    61       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     57      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    6258      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6359      OnlineCalculatorError errorState;
     
    6561      double mse;
    6662      if (applyLinearScaling) {
    67         //int i = 0;
    68         //int rowCount = rows.Count();
    69         //if (estimatedValuesCache == null) estimatedValuesCache = new double[problemData.Dataset.Rows];
    70         //foreach (var value in boundedEstimatedValues) {
    71         //  estimatedValuesCache[i] = value;
    72         //  i++;
    73         //}
    74 
    75         double alpha, beta;
    76         OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, originalValues, out alpha, out beta, out errorState);
    77         mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues.Select(value => value * beta + alpha), out errorState);
     63        var maeCalculator = new OnlineMeanAbsoluteErrorCalculator();
     64        CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);
     65        errorState = maeCalculator.ErrorState;
     66        mse = maeCalculator.MeanAbsoluteError;
    7867      } else
    79         mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues, out errorState);
     68        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    8069
    8170      if (errorState != OnlineCalculatorError.None) return Double.NaN;
Note: See TracChangeset for help on using the changeset viewer.