Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8664


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.
Location:
trunk/sources
Files:
43 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r7259 r8664  
    6565      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6666      EstimationLimitsParameter.ExecutionContext = context;
     67      ApplyLinearScalingParameter.ExecutionContext = context;
    6768
    6869      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     
    7071      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7172      EstimationLimitsParameter.ExecutionContext = null;
     73      ApplyLinearScalingParameter.ExecutionContext = null;
    7274
    7375      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r6740 r8664  
    2626      IEnumerable<int> rows = GenerateRowsToEvaluate();
    2727      var solution = SymbolicExpressionTreeParameter.ActualValue;
    28       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     28      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    2929      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    3030      return base.Apply();
    3131    }
    3232
    33     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     33    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    3434      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    35       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     35      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    3636      OnlineCalculatorError errorState;
    37       double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState);
    38       if (errorState != OnlineCalculatorError.None) r2 = 0.0;
    39       return new double[] { r2, solution.Length };
     37
     38      double r2;
     39      if (applyLinearScaling) {
     40        var r2Calculator = new OnlinePearsonsRSquaredCalculator();
     41        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
     42        errorState = r2Calculator.ErrorState;
     43        r2 = r2Calculator.RSquared;
     44      } else {
     45        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     46        r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     47      }
     48
     49      if (errorState != OnlineCalculatorError.None) r2 = double.NaN;
     50      return new double[2] { r2, solution.Length };
    4051
    4152    }
     
    4556      EstimationLimitsParameter.ExecutionContext = context;
    4657
    47       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     58      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    4859
    4960      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs

    r8594 r8664  
    6868      Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
    6969
     70      ApplyLinearScalingParameter.Value.Value = false;
    7071      EstimationLimitsParameter.Hidden = true;
    7172
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3938    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    4039    private const string EstimationLimitsParameterName = "EstimationLimits";
    41     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4240
    4341    #region parameter properties
     
    5755      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    5856    }
    59     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    60       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    61     }
    62     #endregion
    63 
    64     #region properties
    65     public BoolValue ApplyLinearScaling {
    66       get { return ApplyLinearScalingParameter.Value; }
    67     }
    6857    #endregion
    6958
     
    7766      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    7867      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    79       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    8068    }
    8169    public override IDeepCloneable Clone(Cloner cloner) {
     
    9179    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    9280      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    93       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     81      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    9482
    9583      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3736    private const string ModelCreatorParameterName = "ModelCreator";
    3837    private const string EstimationLimitsParameterName = "EstimationLimits";
    39     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4038
    4139    #region parameter properties
    4240    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4341      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    44     }
    45     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    46       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4742    }
    4843    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     
    5449    #endregion
    5550
    56     #region properties
    57     public BoolValue ApplyLinearScaling {
    58       get { return ApplyLinearScalingParameter.Value; }
    59     }
    60     #endregion
    6151    [StorableConstructor]
    6252    private SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    6555      : base() {
    6656      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The loewr and upper limit for the estimated values produced by the symbolic classification model."));
    67       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    6857      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6958    }
     
    7261    }
    7362
    74     [StorableHook(HookType.AfterDeserialization)]
    75     private void AfterDeserialization() {
    76       if (!Parameters.ContainsKey(ModelCreatorParameterName))
    77         Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    78     }
    7963
    8064    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) {
    8165      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    82       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     66      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    8367
    8468      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs

    r7259 r8664  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualityParameter.ActualValue = new DoubleValue(quality);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     54    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     57      OnlineCalculatorError errorState;
    5858
    59       double minClassValue = problemData.ClassValues.OrderBy(x => x).First();
    60       double maxClassValue = problemData.ClassValues.OrderBy(x => x).Last();
     59      double lowestClassValue = problemData.ClassValues.OrderBy(x => x).First();
     60      double upmostClassValue = problemData.ClassValues.OrderByDescending(x => x).First();
    6161
    62       IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    63       IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    64       double errorSum = 0.0;
    65       int n = 0;
    66 
    67       // always move forward both enumerators (do not use short-circuit evaluation!)
    68       while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    69         double estimated = estimatedEnumerator.Current;
    70         double original = originalEnumerator.Current;
    71         double error = estimated - original;
    72 
    73         if (estimated < minClassValue || estimated > maxClassValue)
    74           errorSum += Math.Abs(error);
    75         else
    76           errorSum += Math.Pow(error, 2);
    77         n++;
     62      double boundedMse;
     63      if (applyLinearScaling) {
     64        var boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowestClassValue, upmostClassValue);
     65        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, boundedMseCalculator, problemData.Dataset.Rows);
     66        errorState = boundedMseCalculator.ErrorState;
     67        boundedMse = boundedMseCalculator.BoundedMeanSquaredError;
     68      } else {
     69        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     70        boundedMse = OnlineBoundedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, lowestClassValue, upmostClassValue, out errorState);
    7871      }
    79 
    80       // check if both enumerators are at the end to make sure both enumerations have the same length
    81       if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) {
    82         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    83       } else {
    84         return errorSum / n;
    85       }
     72      if (errorState != OnlineCalculatorError.None) return Double.NaN;
     73      return boundedMse;
    8674    }
    8775
     
    8977      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    9078      EstimationLimitsParameter.ExecutionContext = context;
     79      ApplyLinearScalingParameter.ExecutionContext = context;
    9180
    92       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     81      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    9382
    9483      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    9584      EstimationLimitsParameter.ExecutionContext = null;
     85      ApplyLinearScalingParameter.ExecutionContext = null;
    9686
    9787      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7259 r8664  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    4748      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4849      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     50      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5051      QualityParameter.ActualValue = new DoubleValue(quality);
    5152      return base.Apply();
    5253    }
    5354
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     55    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5556      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     57      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5858      OnlineCalculatorError errorState;
    59       double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState);
    60       if (errorState != OnlineCalculatorError.None) return double.NaN;
    61       else return mse;
     59
     60      double mse;
     61      if (applyLinearScaling) {
     62        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
     64        errorState = mseCalculator.ErrorState;
     65        mse = mseCalculator.MeanSquaredError;
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     68        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     69      }
     70      if (errorState != OnlineCalculatorError.None) return Double.NaN;
     71      return mse;
    6272    }
    6373
     
    6575      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6676      EstimationLimitsParameter.ExecutionContext = context;
     77      ApplyLinearScalingParameter.ExecutionContext = context;
    6778
    68       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     79      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6980
    7081      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7182      EstimationLimitsParameter.ExecutionContext = null;
     83      ApplyLinearScalingParameter.ExecutionContext = null;
    7284
    7385      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs

    r8646 r8664  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualityParameter.ActualValue = new DoubleValue(quality);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     54    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5857      OnlineCalculatorError errorState;
    59       double r2 = OnlinePearsonsRSquaredCalculator.Calculate(boundedEstimationValues, originalValues, out errorState);
    60       if (errorState != OnlineCalculatorError.None) return 0.0;
    61       else return r2;
     58
     59      double r2;
     60      if (applyLinearScaling) {
     61        var r2Calculator = new OnlinePearsonsRSquaredCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
     63        errorState = r2Calculator.ErrorState;
     64        r2 = r2Calculator.RSquared;
     65      } else {
     66        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     67        r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     68      }
     69      if (errorState != OnlineCalculatorError.None) return double.NaN;
     70      return r2;
    6271    }
    6372
     
    6574      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6675      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    6777
    68       double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     78      double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6979
    7080      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7181      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    7283
    7384      return r2;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs

    r8594 r8664  
    8686      EstimationLimitsParameter.ExecutionContext = context;
    8787      ModelCreatorParameter.ExecutionContext = context;
     88      ApplyLinearScalingParameter.ExecutionContext = context;
    8889
    8990      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     91      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, problemData, problemData.TargetVariable);
    9092      model.RecalculateModelParameters(problemData, rows);
    9193      double penalty = Calculate(model, problemData, rows);
     
    9496      EstimationLimitsParameter.ExecutionContext = null;
    9597      ModelCreatorParameter.ExecutionContext = null;
     98      ApplyLinearScalingParameter.ExecutionContext = null;
    9699
    97100      return penalty;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r8594 r8664  
    6666      Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
    6767
     68      ApplyLinearScalingParameter.Value.Value = false;
    6869      EstimationLimitsParameter.Hidden = true;
    6970
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3938    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    4039    private const string EstimationLimitsParameterName = "UpperEstimationLimit";
    41     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4240    #region parameter properties
    4341    public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
     
    5654      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    5755    }
    58     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    59       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    60     }
    6156    #endregion
    62     #region properties
    63     public BoolValue ApplyLinearScaling {
    64       get { return ApplyLinearScalingParameter.Value; }
    65     }
    66     #endregion
     57
    6758
    6859    [StorableConstructor]
     
    7566      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    7667      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    77       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    7868    }
    7969
     
    8979    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    9080      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    91       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     81      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    9282
    9383      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3433  [StorableClass]
    3534  public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution>, ISymbolicClassificationModelCreatorOperator {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3735    private const string ModelCreatorParameterName = "ModelCreator";
    3836    #region parameter properties
    39     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    40       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    41     }
    4237    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
    4338      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     
    4843    #endregion
    4944
    50     #region properties
    51     public BoolValue ApplyLinearScaling {
    52       get { return ApplyLinearScalingParameter.Value; }
    53     }
    54     #endregion
    55 
    5645    [StorableConstructor]
    5746    private SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    5948    public SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer()
    6049      : base() {
    61       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    6250      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6351    }
     
    7462    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    7563      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    76       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     64      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    7765
    7866      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3635  ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3736    private const string EstimationLimitsParameterName = "EstimationLimits";
    38     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3937    private const string ModelCreatorParameterName = "ModelCreator";
    4038
     
    4240    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4341      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    44     }
    45     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    46       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4742    }
    4843    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     
    5449    #endregion
    5550
    56     #region properties
    57     public BoolValue ApplyLinearScaling {
    58       get { return ApplyLinearScalingParameter.Value; }
    59     }
    60     #endregion
    6151    [StorableConstructor]
    6252    private SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    6555      : base() {
    6656      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    67       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    6857      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6958    }
     
    8069    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    8170      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    82       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     71      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    8372
    8473      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r8594 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3433  [StorableClass]
    3534  public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, ISymbolicClassificationModelCreatorOperator {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3735    private const string ModelCreatorParameterName = "ModelCreator";
    3836    #region parameter properties
    39     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    40       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    41     }
    4237    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
    4338      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     
    4843    #endregion
    4944
    50     #region properties
    51     public BoolValue ApplyLinearScaling {
    52       get { return ApplyLinearScalingParameter.Value; }
    53     }
    54     #endregion
    55 
    5645    [StorableConstructor]
    5746    private SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    5948    public SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer()
    6049      : base() {
    61       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    6250      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6351    }
     
    7462    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    7563      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    76       if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
     64      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    7765
    7866      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs

    r8623 r8664  
    6262      return CreateClassificationSolution(problemData);
    6363    }
    64 
    65     #region scaling
    66     public static void Scale(ISymbolicClassificationModel model, IClassificationProblemData problemData) {
    67       var dataset = problemData.Dataset;
    68       var targetVariable = problemData.TargetVariable;
    69       var rows = problemData.TrainingIndices;
    70       var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);
    71       var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    72       double alpha;
    73       double beta;
    74       OnlineCalculatorError errorState;
    75       OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState);
    76       if (errorState != OnlineCalculatorError.None) return;
    77 
    78       ConstantTreeNode alphaTreeNode = null;
    79       ConstantTreeNode betaTreeNode = null;
    80       // check if model has been scaled previously by analyzing the structure of the tree
    81       var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);
    82       if (startNode.GetSubtree(0).Symbol is Addition) {
    83         var addNode = startNode.GetSubtree(0);
    84         if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {
    85           alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;
    86           var mulNode = addNode.GetSubtree(0);
    87           if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {
    88             betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;
    89           }
    90         }
    91       }
    92       // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes
    93       if (alphaTreeNode != null && betaTreeNode != null) {
    94         betaTreeNode.Value *= beta;
    95         alphaTreeNode.Value *= beta;
    96         alphaTreeNode.Value += alpha;
    97       } else {
    98         var mainBranch = startNode.GetSubtree(0);
    99         startNode.RemoveSubtree(0);
    100         var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);
    101         startNode.AddSubtree(scaledMainBranch);
    102       }
    103     }
    104 
    105     private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {
    106       if (alpha.IsAlmost(0.0)) {
    107         return treeNode;
    108       } else {
    109         var addition = new Addition();
    110         var node = addition.CreateTreeNode();
    111         var alphaConst = MakeConstant(alpha);
    112         node.AddSubtree(treeNode);
    113         node.AddSubtree(alphaConst);
    114         return node;
    115       }
    116     }
    117 
    118     private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
    119       if (beta.IsAlmost(1.0)) {
    120         return treeNode;
    121       } else {
    122         var multipliciation = new Multiplication();
    123         var node = multipliciation.CreateTreeNode();
    124         var betaConst = MakeConstant(beta);
    125         node.AddSubtree(treeNode);
    126         node.AddSubtree(betaConst);
    127         return node;
    128       }
    129     }
    130 
    131     private static ISymbolicExpressionTreeNode MakeConstant(double c) {
    132       var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
    133       node.Value = c;
    134       return node;
    135     }
    136     #endregion
    13764  }
    13865}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r8639 r8664  
    5151    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    5252      var model = new SymbolicRegressionModel(tree, Content.Model.Interpreter, Content.Model.LowerEstimationLimit, Content.Model.UpperEstimationLimit);
    53       SymbolicRegressionModel.Scale(model, Content.ProblemData);
     53      SymbolicRegressionModel.Scale(model, Content.ProblemData, Content.ProblemData.TargetVariable);
    5454      Content.Model = model;
    5555    }
     
    122122
    123123    protected override void btnOptimizeConstants_Click(object sender, EventArgs e) {
    124       SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(Content.Model.Interpreter, Content.Model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices, 0.001, 0, 0.0001);
     124      var model = Content.Model;
     125      SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(Content.Model.Interpreter, Content.Model.SymbolicExpressionTree, Content.ProblemData, Content.ProblemData.TrainingIndices,
     126        applyLinearScaling: true, improvement: 0.001, iterations: 0, differentialStep: 0.0001, upperEstimationLimit: model.UpperEstimationLimit, lowerEstimationLimit: model.LowerEstimationLimit);
    125127      UpdateModel(Content.Model.SymbolicExpressionTree);
    126128    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r7259 r8664  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
     54    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5857      OnlineCalculatorError errorState;
    59       double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState);
     58
     59      double mse;
     60      if (applyLinearScaling) {
     61        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
     63        errorState = mseCalculator.ErrorState;
     64        mse = mseCalculator.MeanSquaredError;
     65      } else {
     66        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     67        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     68      }
    6069      if (errorState != OnlineCalculatorError.None) mse = double.NaN;
    6170      return new double[2] { mse, solution.Length };
     
    6574      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6675      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    6777
    68       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     78      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6979
    7080      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7181      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    7283
    7384      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r7259 r8664  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
     54    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5757      OnlineCalculatorError errorState;
    58       double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState);
    59       if (errorState != OnlineCalculatorError.None) r2 = 0.0;
    60       return new double[] { r2, solution.Length };
     58
     59      double r2;
     60      if (applyLinearScaling) {
     61        var r2Calculator = new OnlinePearsonsRSquaredCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
     63        errorState = r2Calculator.ErrorState;
     64        r2 = r2Calculator.RSquared;
     65      } else {
     66        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     67        r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     68      }
     69
     70      if (errorState != OnlineCalculatorError.None) r2 = double.NaN;
     71      return new double[2] { r2, solution.Length };
    6172    }
    6273
     
    6475      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6576      EstimationLimitsParameter.ExecutionContext = context;
     77      ApplyLinearScalingParameter.ExecutionContext = context;
    6678
    67       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     79      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6880
    6981      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7082      EstimationLimitsParameter.ExecutionContext = null;
     83      ApplyLinearScalingParameter.ExecutionContext = null;
    7184
    7285      return quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r8175 r8664  
    6565      EstimationLimitsParameter.Hidden = true;
    6666
     67      ApplyLinearScalingParameter.Value.Value = true;
    6768      Maximization = new BoolArray(new bool[] { true, false });
    6869      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3837    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3938    private const string EstimationLimitsParameterName = "EstimationLimits";
    40     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4139    #region parameter properties
    4240    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
     
    4846    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4947      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    50     }
    51     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    52       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    53     }
    54     #endregion
    55 
    56     #region properties
    57     public BoolValue ApplyLinearScaling {
    58       get { return ApplyLinearScalingParameter.Value; }
    5948    }
    6049    #endregion
     
    6857      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6958      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    70       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    7159    }
    7260
     
    7765    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    7866      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    79       if (ApplyLinearScaling.Value)
    80         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     67      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    8168      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    8269    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3635    ISymbolicDataAnalysisBoundedOperator {
    3736    private const string EstimationLimitsParameterName = "EstimationLimits";
    38     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3937
    4038    #region parameter properties
     
    4240      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4341    }
    44     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    45       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    46     }
    4742    #endregion
    4843
    49     #region properties
    50     public BoolValue ApplyLinearScaling {
    51       get { return ApplyLinearScalingParameter.Value; }
    52     }
    53     #endregion
    5444    [StorableConstructor]
    5545    private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    5848      : base() {
    5949      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    60       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    6150    }
    6251    public override IDeepCloneable Clone(Cloner cloner) {
     
    6655    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    6756      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    68       if (ApplyLinearScaling.Value)
    69         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     57      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    7058      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    7159    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r8053 r8664  
    106106        IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value);
    107107        quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue,
    108            constantOptimizationRows, ConstantOptimizationImprovement.Value, ConstantOptimizationIterations.Value, 0.001,
     108           constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationImprovement.Value, ConstantOptimizationIterations.Value, 0.001,
    109109           EstimationLimitsParameter.ActualValue.Upper, EstimationLimitsParameter.ActualValue.Lower,
    110110          EvaluatedTreesParameter.ActualValue, EvaluatedTreeNodesParameter.ActualValue);
    111111        if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
    112112          var evaluationRows = GenerateRowsToEvaluate();
    113           quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows);
     113          quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
    114114        }
    115115      } else {
    116116        var evaluationRows = GenerateRowsToEvaluate();
    117         quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows);
     117        quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
    118118      }
    119119      QualityParameter.ActualValue = new DoubleValue(quality);
     
    145145      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    146146      EstimationLimitsParameter.ExecutionContext = context;
    147 
    148       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     147      ApplyLinearScalingParameter.ExecutionContext = context;
     148
     149      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    149150
    150151      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    151152      EstimationLimitsParameter.ExecutionContext = null;
     153      ApplyLinearScalingParameter.ExecutionContext = context;
    152154
    153155      return r2;
     
    155157
    156158    public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData,
    157       IEnumerable<int> rows, double improvement, int iterations, double differentialStep, double upperEstimationLimit = double.MaxValue, double lowerEstimationLimit = double.MinValue, IntValue evaluatedTrees = null, IntValue evaluatedTreeNodes = null) {
     159      IEnumerable<int> rows, bool applyLinearScaling, double improvement, int iterations, double differentialStep, double upperEstimationLimit = double.MaxValue, double lowerEstimationLimit = double.MinValue, IntValue evaluatedTrees = null, IntValue evaluatedTreeNodes = null) {
    158160      List<SymbolicExpressionTreeTerminalNode> terminalNodes = tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>().ToList();
    159161      double[] c = new double[terminalNodes.Count];
     
    179181      alglib.minlmcreatev(1, c, diffstep, out state);
    180182      alglib.minlmsetcond(state, epsg, epsf, epsx, maxits);
    181       alglib.minlmoptimize(state, CreateCallBack(interpreter, tree, problemData, rows, upperEstimationLimit, lowerEstimationLimit, treeLength, evaluatedTrees, evaluatedTreeNodes), null, terminalNodes);
     183      alglib.minlmoptimize(state, CreateCallBack(interpreter, tree, problemData, rows, applyLinearScaling, upperEstimationLimit, lowerEstimationLimit, treeLength, evaluatedTrees, evaluatedTreeNodes), null, terminalNodes);
    182184      alglib.minlmresults(state, out c, out report);
    183185
     
    192194    }
    193195
    194     private static alglib.ndimensional_fvec CreateCallBack(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows, double upperEstimationLimit, double lowerEstimationLimit, int treeLength, IntValue evaluatedTrees = null, IntValue evaluatedTreeNodes = null) {
     196    private static alglib.ndimensional_fvec CreateCallBack(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, double upperEstimationLimit, double lowerEstimationLimit, int treeLength, IntValue evaluatedTrees = null, IntValue evaluatedTreeNodes = null) {
    195197      return (double[] arg, double[] fi, object obj) => {
    196198        // update constants of tree
     
    203205        }
    204206
    205         double quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows);
     207        double quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    206208
    207209        fi[0] = 1 - quality;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r8639 r8664  
    3030namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3131  [StorableClass]
    32   public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {
    33     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    34     public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
    35       get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    36     }
    37     public bool ApplyLinearScaling {
    38       get { return ApplyLinearScalingParameter.Value.Value; }
    39       set { ApplyLinearScalingParameter.Value.Value = value; }
    40     }
    41 
     32  public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 
    4233    [StorableConstructor]
    4334    protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
    4435    protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
    45     protected SymbolicRegressionSingleObjectiveEvaluator()
    46       : base() {
    47       Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(true)));
    48       ApplyLinearScalingParameter.Hidden = true;
    49     }
    50 
    51     [StorableHook(HookType.AfterDeserialization)]
    52     private void AfterDeserialization() {
    53       if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
    54         Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating.", new BoolValue(false)));
    55         ApplyLinearScalingParameter.Hidden = true;
    56       }
    57     }
    58 
    59     [ThreadStatic]
    60     private static double[] cache;
    61 
    62     protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
    63       double lowerEstimationLimit, double upperEstimationLimit,
    64       IOnlineCalculator calculator, int maxRows) {
    65       if (cache == null || cache.GetLength(0) < maxRows) {
    66         cache = new double[maxRows];
    67       }
    68 
    69       //calculate linear scaling
    70       //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements
    71       //this is not true if the cache is used
    72       int i = 0;
    73       var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
    74       var targetValuesEnumerator = targetValues.GetEnumerator();
    75       var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
    76       while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
    77         double target = targetValuesEnumerator.Current;
    78         double estimated = estimatedValuesEnumerator.Current;
    79         cache[i] = estimated;
    80         if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
    81           linearScalingCalculator.Add(estimated, target);
    82         i++;
    83       }
    84       if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
    85         throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
    86 
    87       double alpha = linearScalingCalculator.Alpha;
    88       double beta = linearScalingCalculator.Beta;
    89       if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
    90         alpha = 0.0;
    91         beta = 1.0;
    92       }
    93 
    94       //calculate the quality by using the passed online calculator
    95       targetValuesEnumerator = targetValues.GetEnumerator();
    96       var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
    97         .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
    98 
    99       while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
    100         calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
    101       }
    102     }
     36    protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}   
    10337  }
    10438}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r8113 r8664  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
     
    4746      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4847
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScaling);
     48      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5049      QualityParameter.ActualValue = new DoubleValue(quality);
    5150
     
    6867        mse = OnlineMaxAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6968      }
    70       if (errorState != OnlineCalculatorError.None) return Double.NaN;
    71       else return mse;
     69      if (errorState != OnlineCalculatorError.None) return double.NaN;
     70      return mse;
    7271    }
    7372
     
    7574      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    7675      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    7777
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScaling);
     78      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    7979
    8080      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    8181      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    8283
    8384      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r8634 r8664  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
     
    4746      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4847
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScaling);
     48      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5049      QualityParameter.ActualValue = new DoubleValue(quality);
    5150
     
    6867        mae = OnlineMeanAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6968      }
    70       if (errorState != OnlineCalculatorError.None) return Double.NaN;
    71       else return mae;
     69      if (errorState != OnlineCalculatorError.None) return double.NaN;
     70      return mae;
    7271    }
    7372
     
    7574      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    7675      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    7777
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScaling);
     78      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    7979
    8080      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    8181      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    8283
    8384      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r8113 r8664  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
     
    4746      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4847
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScaling);
     48      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5049      QualityParameter.ActualValue = new DoubleValue(quality);
    5150
     
    6867        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6968      }
    70       if (errorState != OnlineCalculatorError.None) return Double.NaN;
    71       else return mse;
     69      if (errorState != OnlineCalculatorError.None) return double.NaN;
     70      return mse;
    7271    }
    7372
     
    7574      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    7675      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    7777
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScaling);
     78      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    7979
    8080      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    8181      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    8283
    8384      return mse;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r7672 r8664  
    4848      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4949
    50       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     50      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5151      QualityParameter.ActualValue = new DoubleValue(quality);
    5252
     
    5454    }
    5555
    56     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
     56    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5757      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    58       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     58      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5959      OnlineCalculatorError errorState;
    60       double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState);
    61       if (errorState != OnlineCalculatorError.None) return 0.0;
    62       else return r2;
     60
     61      double r2;
     62      if (applyLinearScaling) {
     63        var r2Calculator = new OnlinePearsonsRSquaredCalculator();
     64        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
     65        errorState = r2Calculator.ErrorState;
     66        r2 = r2Calculator.RSquared;
     67      } else {
     68        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     69        r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     70      }
     71      if (errorState != OnlineCalculatorError.None) return double.NaN;
     72      return r2;
    6373    }
    6474
     
    6676      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6777      EstimationLimitsParameter.ExecutionContext = context;
     78      ApplyLinearScalingParameter.ExecutionContext = context;
    6879
    69       double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     80      double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    7081
    7182      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7283      EstimationLimitsParameter.ExecutionContext = null;
     84      ApplyLinearScalingParameter.ExecutionContext = null;
    7385
    7486      return r2;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r8175 r8664  
    6161      EstimationLimitsParameter.Hidden = true;
    6262
     63
     64      ApplyLinearScalingParameter.Value.Value = true;
    6365      Maximization.Value = true;
    6466      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3837    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3938    private const string EstimationLimitsParameterName = "EstimationLimits";
    40     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4139    #region parameter properties
    4240    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
     
    4846    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4947      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    50     }
    51     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    52       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    53     }
    54     #endregion
    55 
    56     #region properties
    57     public BoolValue ApplyLinearScaling {
    58       get { return ApplyLinearScalingParameter.Value; }
    5948    }
    6049    #endregion
     
    6857      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6958      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    70       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    7159    }
    7260    public override IDeepCloneable Clone(Cloner cloner) {
     
    7664    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    7765      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    78       if (ApplyLinearScaling.Value)
    79         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     66      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    8067      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    8168    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r8169 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HeuristicLab.Parameters;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
     
    3432  [StorableClass]
    3533  public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IRegressionProblemData, ISymbolicRegressionSolution> {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    37     #region parameter properties
    38     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    39       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    40     }
    41     #endregion
    42 
    43     #region properties
    44     public BoolValue ApplyLinearScaling {
    45       get { return ApplyLinearScalingParameter.Value; }
    46     }
    47     #endregion
    4834
    4935    [StorableConstructor]
    5036    private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
    5137    private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    52     public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer()
    53       : base() {
    54       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    55     }
     38    public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer() : base() { }
    5639    public override IDeepCloneable Clone(Cloner cloner) {
    5740      return new SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(this, cloner);
     
    6043    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    6144      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    62       if (ApplyLinearScaling.Value)
    63         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     45      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    6446      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    6547    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3635    ISymbolicDataAnalysisBoundedOperator {
    3736    private const string EstimationLimitsParameterName = "EstimationLimits";
    38     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    3937
    4038    #region parameter properties
    4139    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4240      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    43     }
    44     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    45       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    46     }
    47     #endregion
    48 
    49     #region properties
    50     public BoolValue ApplyLinearScaling {
    51       get { return ApplyLinearScalingParameter.Value; }
    5241    }
    5342    #endregion
     
    5948      : base() {
    6049      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    61       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    6250    }
    6351
     
    6856    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    6957      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    70       if (ApplyLinearScaling.Value)
    71         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     58      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    7259      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    7360    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r8169 r8664  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HeuristicLab.Parameters;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
     
    3432  [StorableClass]
    3533  public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    37     #region parameter properties
    38     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    39       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    40     }
    41     #endregion
    42 
    43     #region properties
    44     public BoolValue ApplyLinearScaling {
    45       get { return ApplyLinearScalingParameter.Value; }
    46     }
    47     #endregion
    48 
    4934    [StorableConstructor]
    5035    private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
    5136    private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    52     public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()
    53       : base() {
    54       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
    55     }
     37    public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer() : base() { }
     38
    5639    public override IDeepCloneable Clone(Cloner cloner) {
    5740      return new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(this, cloner);
     
    6043    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    6144      var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    62       if (ApplyLinearScaling.Value)
    63         SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue);
     45      if (ApplyLinearScalingParameter.ActualValue.Value) SymbolicRegressionModel.Scale(model, ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariable);
    6446      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    6547    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r8639 r8664  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
     
    7069      return CreateRegressionSolution(problemData);
    7170    }
    72 
    73     public static void Scale(SymbolicRegressionModel model, IRegressionProblemData problemData) {
    74       var dataset = problemData.Dataset;
    75       var targetVariable = problemData.TargetVariable;
    76       var rows = problemData.TrainingIndices;
    77       var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);
    78       var targetValues = dataset.GetDoubleValues(targetVariable, rows);
    79 
    80       var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
    81       var targetValuesEnumerator = targetValues.GetEnumerator();
    82       var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
    83       while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
    84         double target = targetValuesEnumerator.Current;
    85         double estimated = estimatedValuesEnumerator.Current;
    86         if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
    87           linearScalingCalculator.Add(estimated, target);
    88       }
    89       if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
    90         throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
    91 
    92       double alpha = linearScalingCalculator.Alpha;
    93       double beta = linearScalingCalculator.Beta;
    94       if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return;
    95 
    96       ConstantTreeNode alphaTreeNode = null;
    97       ConstantTreeNode betaTreeNode = null;
    98       // check if model has been scaled previously by analyzing the structure of the tree
    99       var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);
    100       if (startNode.GetSubtree(0).Symbol is Addition) {
    101         var addNode = startNode.GetSubtree(0);
    102         if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {
    103           alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;
    104           var mulNode = addNode.GetSubtree(0);
    105           if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {
    106             betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;
    107           }
    108         }
    109       }
    110       // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes
    111       if (alphaTreeNode != null && betaTreeNode != null) {
    112         betaTreeNode.Value *= beta;
    113         alphaTreeNode.Value *= beta;
    114         alphaTreeNode.Value += alpha;
    115       } else {
    116         var mainBranch = startNode.GetSubtree(0);
    117         startNode.RemoveSubtree(0);
    118         var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);
    119         startNode.AddSubtree(scaledMainBranch);
    120       }
    121     }
    122 
    123     private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {
    124       if (alpha.IsAlmost(0.0)) {
    125         return treeNode;
    126       } else {
    127         var addition = new Addition();
    128         var node = addition.CreateTreeNode();
    129         var alphaConst = MakeConstant(alpha);
    130         node.AddSubtree(treeNode);
    131         node.AddSubtree(alphaConst);
    132         return node;
    133       }
    134     }
    135 
    136     private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
    137       if (beta.IsAlmost(1.0)) {
    138         return treeNode;
    139       } else {
    140         var multipliciation = new Multiplication();
    141         var node = multipliciation.CreateTreeNode();
    142         var betaConst = MakeConstant(beta);
    143         node.AddSubtree(treeNode);
    144         node.AddSubtree(betaConst);
    145         return node;
    146       }
    147     }
    148 
    149     private static ISymbolicExpressionTreeNode MakeConstant(double c) {
    150       var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
    151       node.Value = c;
    152       return node;
    153     }
    15471  }
    15572}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveAnalyzer.cs

    r7259 r8664  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2925using HeuristicLab.Parameters;
    3026using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    3227
    3328namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3934    private const string QualitiesParameterName = "Qualities";
    4035    private const string MaximizationParameterName = "Maximization";
     36    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4137    #region parameter properties
    4238    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
     
    4541    public ILookupParameter<BoolArray> MaximizationParameter {
    4642      get { return (ILookupParameter<BoolArray>)Parameters[MaximizationParameterName]; }
     43    }
     44    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     45      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4746    }
    4847    #endregion
     
    6463      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>(QualitiesParameterName, "The qualities of the trees that should be analyzed."));
    6564      Parameters.Add(new LookupParameter<BoolArray>(MaximizationParameterName, "The directions of optimization for each dimension."));
     65      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     66    }
     67
     68    [StorableHook(HookType.AfterDeserialization)]
     69    private void AfterDeserialization() {
     70      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>)
     71        Parameters.Remove(ApplyLinearScalingParameterName);
     72      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     73        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    6674    }
    6775  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveAnalyzer.cs

    r7259 r8664  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2925using HeuristicLab.Parameters;
    3026using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    3227
    3328namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3934    private const string QualityParameterName = "Quality";
    4035    private const string MaximizationParameterName = "Maximization";
     36    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     37
    4138    #region parameter properties
    4239    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     
    4542    public ILookupParameter<BoolValue> MaximizationParameter {
    4643      get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
     44    }
     45    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     46      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    4747    }
    4848    #endregion
     
    6464      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the trees that should be analyzed."));
    6565      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
     66      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     67    }
     68
     69    [StorableHook(HookType.AfterDeserialization)]
     70    private void AfterDeserialization() {
     71      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))
     72        Parameters.Remove(ApplyLinearScalingParameterName);
     73      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     74        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    6675    }
    6776  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs

    r7259 r8664  
    4444    private const string EvaluationPartitionParameterName = "EvaluationPartition";
    4545    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
     46    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4647
    4748    public override bool CanChangeName { get { return false; } }
     
    7071      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
    7172    }
     73    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     74      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     75    }
    7276    #endregion
    7377
     
    8791      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
    8892      Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
     93      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
     94    }
     95
     96    [StorableHook(HookType.AfterDeserialization)]
     97    private void AfterDeserialization() {
     98      if (Parameters.ContainsKey(ApplyLinearScalingParameterName) && !(Parameters[ApplyLinearScalingParameterName] is LookupParameter<BoolValue>))
     99        Parameters.Remove(ApplyLinearScalingParameterName);
     100      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName))
     101        Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the individual should be linearly scaled before evaluating."));
    89102    }
    90103
     
    94107
    95108    protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
    96 
    97 
    98109      IEnumerable<int> rows;
    99110      int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
     
    115126      return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
    116127    }
     128
     129    [ThreadStatic]
     130    private static double[] cache;
     131    protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues,
     132      double lowerEstimationLimit, double upperEstimationLimit,
     133      IOnlineCalculator calculator, int maxRows) {
     134      if (cache == null || cache.GetLength(0) < maxRows) {
     135        cache = new double[maxRows];
     136      }
     137
     138      //calculate linear scaling
     139      //the static methods of the calculator could not be used as it performs a check if the enumerators have an equal amount of elements
     140      //this is not true if the cache is used
     141      int i = 0;
     142      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     143      var targetValuesEnumerator = targetValues.GetEnumerator();
     144      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     145      while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
     146        double target = targetValuesEnumerator.Current;
     147        double estimated = estimatedValuesEnumerator.Current;
     148        cache[i] = estimated;
     149        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     150          linearScalingCalculator.Add(estimated, target);
     151        i++;
     152      }
     153      if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
     154        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     155
     156      double alpha = linearScalingCalculator.Alpha;
     157      double beta = linearScalingCalculator.Beta;
     158      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) {
     159        alpha = 0.0;
     160        beta = 1.0;
     161      }
     162
     163      //calculate the quality by using the passed online calculator
     164      targetValuesEnumerator = targetValues.GetEnumerator();
     165      var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha)
     166        .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator();
     167
     168      while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) {
     169        calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current);
     170      }
     171    }
    117172  }
    118173}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisEvaluator.cs

    r7259 r8664  
    2929    IValueLookupParameter<IntRange> EvaluationPartitionParameter { get; }
    3030    IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter { get; }
     31    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3132
    3233    IValueLookupParameter<T> ProblemDataParameter { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisMultiObjectiveAnalyzer.cs

    r7259 r8664  
    2121using HeuristicLab.Core;
    2222using HeuristicLab.Data;
    23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    24 using HeuristicLab.Optimization;
    25 using HeuristicLab.Parameters;
    2623namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2724  public interface ISymbolicDataAnalysisMultiObjectiveAnalyzer : ISymbolicDataAnalysisAnalyzer {
    2825    IScopeTreeLookupParameter<DoubleArray> QualitiesParameter { get; }
    2926    ILookupParameter<BoolArray> MaximizationParameter { get; }
     27    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3028
    3129  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisSingleObjectiveAnalyzer.cs

    r7259 r8664  
    2828    IScopeTreeLookupParameter<DoubleValue> QualityParameter { get; }
    2929    ILookupParameter<BoolValue> MaximizationParameter { get; }
     30    ILookupParameter<BoolValue> ApplyLinearScalingParameter { get; }
    3031  }
    3132}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r7259 r8664  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
    2324using HeuristicLab.Common;
     
    6667      this.interpreter = interpreter;
    6768    }
     69
     70    #region Scaling
     71    public static void Scale(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, string targetVariable) {
     72      var dataset = problemData.Dataset;
     73      var rows = problemData.TrainingIndices;
     74      var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);
     75      var targetValues = dataset.GetDoubleValues(targetVariable, rows);
     76
     77      var linearScalingCalculator = new OnlineLinearScalingParameterCalculator();
     78      var targetValuesEnumerator = targetValues.GetEnumerator();
     79      var estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     80      while (targetValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
     81        double target = targetValuesEnumerator.Current;
     82        double estimated = estimatedValuesEnumerator.Current;
     83        if (!double.IsNaN(estimated) && !double.IsInfinity(estimated))
     84          linearScalingCalculator.Add(estimated, target);
     85      }
     86      if (linearScalingCalculator.ErrorState == OnlineCalculatorError.None && (targetValuesEnumerator.MoveNext() || estimatedValuesEnumerator.MoveNext()))
     87        throw new ArgumentException("Number of elements in target and estimated values enumeration do not match.");
     88
     89      double alpha = linearScalingCalculator.Alpha;
     90      double beta = linearScalingCalculator.Beta;
     91      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return;
     92
     93      ConstantTreeNode alphaTreeNode = null;
     94      ConstantTreeNode betaTreeNode = null;
     95      // check if model has been scaled previously by analyzing the structure of the tree
     96      var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);
     97      if (startNode.GetSubtree(0).Symbol is Addition) {
     98        var addNode = startNode.GetSubtree(0);
     99        if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {
     100          alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;
     101          var mulNode = addNode.GetSubtree(0);
     102          if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {
     103            betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;
     104          }
     105        }
     106      }
     107      // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes
     108      if (alphaTreeNode != null && betaTreeNode != null) {
     109        betaTreeNode.Value *= beta;
     110        alphaTreeNode.Value *= beta;
     111        alphaTreeNode.Value += alpha;
     112      } else {
     113        var mainBranch = startNode.GetSubtree(0);
     114        startNode.RemoveSubtree(0);
     115        var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);
     116        startNode.AddSubtree(scaledMainBranch);
     117      }
     118    }
     119
     120    private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {
     121      if (alpha.IsAlmost(0.0)) {
     122        return treeNode;
     123      } else {
     124        var addition = new Addition();
     125        var node = addition.CreateTreeNode();
     126        var alphaConst = MakeConstant(alpha);
     127        node.AddSubtree(treeNode);
     128        node.AddSubtree(alphaConst);
     129        return node;
     130      }
     131    }
     132
     133    private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
     134      if (beta.IsAlmost(1.0)) {
     135        return treeNode;
     136      } else {
     137        var multipliciation = new Multiplication();
     138        var node = multipliciation.CreateTreeNode();
     139        var betaConst = MakeConstant(beta);
     140        node.AddSubtree(treeNode);
     141        node.AddSubtree(betaConst);
     142        return node;
     143      }
     144    }
     145
     146    private static ISymbolicExpressionTreeNode MakeConstant(double c) {
     147      var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
     148      node.Value = c;
     149      return node;
     150    }
     151    #endregion
    68152  }
    69153}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r8203 r8664  
    5353    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
    5454    private const string ValidationPartitionParameterName = "ValidationPartition";
     55    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    5556
    5657    private const string ProblemDataParameterDescription = "";
     
    6465    private const string FitnessCalculationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to calculate the fitness of an individual.";
    6566    private const string ValidationPartitionParameterDescription = "The partition of the problem data training partition, that should be used to select the best model from (optional).";
     67    private const string ApplyLinearScalingParameterDescription = "Flag that indicates if the individual should be linearly scaled before evaluating.";
    6668    #endregion
    6769
     
    100102      get { return (IFixedValueParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
    101103    }
     104    public IFixedValueParameter<BoolValue> ApplyLinearScalingParameter {
     105      get { return (IFixedValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     106    }
    102107    #endregion
    103108
     
    144149    public IntRange ValidationPartition {
    145150      get { return ValidationPartitionParameter.Value; }
     151    }
     152    public BoolValue ApplyLinearScaling {
     153      get { return ApplyLinearScalingParameter.Value; }
    146154    }
    147155    #endregion
     
    151159    [StorableHook(HookType.AfterDeserialization)]
    152160    private void AfterDeserialization() {
     161      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     162        Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
     163        ApplyLinearScalingParameter.Hidden = true;
     164      }
     165
    153166      RegisterEventHandlers();
    154167    }
     
    170183      Parameters.Add(new FixedValueParameter<IntRange>(ValidationPartitionParameterName, ValidationPartitionParameterDescription));
    171184      Parameters.Add(new FixedValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, RelativeNumberOfEvaluatedSamplesParameterDescription, new PercentValue(1)));
     185      Parameters.Add(new FixedValueParameter<BoolValue>(ApplyLinearScalingParameterName, ApplyLinearScalingParameterDescription, new BoolValue(false)));
    172186
    173187      SymbolicExpressionTreeInterpreterParameter.Hidden = true;
    174188      MaximumFunctionArgumentsParameter.Hidden = true;
    175189      MaximumFunctionDefinitionsParameter.Hidden = true;
     190      ApplyLinearScalingParameter.Hidden = true;
    176191
    177192      SymbolicExpressionTreeGrammar = new TypeCoherentExpressionGrammar();
     
    274289
    275290      foreach (var op in operators.OfType<ISymbolicExpressionTreeGrammarBasedOperator>()) {
    276         op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameterName;
     291        op.SymbolicExpressionTreeGrammarParameter.ActualName = SymbolicExpressionTreeGrammarParameter.Name;
    277292      }
    278293      foreach (var op in operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()) {
    279         op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameterName;
    280         op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameterName;
     294        op.MaximumSymbolicExpressionTreeDepthParameter.ActualName = MaximumSymbolicExpressionTreeDepthParameter.Name;
     295        op.MaximumSymbolicExpressionTreeLengthParameter.ActualName = MaximumSymbolicExpressionTreeLengthParameter.Name;
    281296      }
    282297      foreach (var op in operators.OfType<ISymbolicExpressionTreeArchitectureAlteringOperator>()) {
    283         op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameterName;
    284         op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameterName;
     298        op.MaximumFunctionArgumentsParameter.ActualName = MaximumFunctionArgumentsParameter.Name;
     299        op.MaximumFunctionDefinitionsParameter.ActualName = MaximumFunctionDefinitionsParameter.Name;
    285300      }
    286301      foreach (var op in operators.OfType<ISymbolicDataAnalysisEvaluator<T>>()) {
     
    289304        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
    290305        op.RelativeNumberOfEvaluatedSamplesParameter.ActualName = RelativeNumberOfEvaluatedSamplesParameter.Name;
     306        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
    291307      }
    292308      foreach (var op in operators.OfType<ISymbolicExpressionTreeCrossover>()) {
     
    300316        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    301317      }
     318      foreach (var op in operators.OfType<ISymbolicDataAnalysisSingleObjectiveAnalyzer>()) {
     319        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
     320      }
     321      foreach (var op in operators.OfType<ISymbolicDataAnalysisMultiObjectiveAnalyzer>()) {
     322        op.ApplyLinearScalingParameter.ActualName = ApplyLinearScalingParameter.Name;
     323      }
    302324      foreach (var op in operators.OfType<ISymbolicDataAnalysisAnalyzer>()) {
    303325        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     
    308330      }
    309331      foreach (var op in operators.OfType<ISymbolicDataAnalysisInterpreterOperator>()) {
    310         op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameterName;
     332        op.SymbolicDataAnalysisTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
    311333      }
    312334      foreach (var op in operators.OfType<ISymbolicDataAnalysisExpressionCrossover<T>>()) {
    313         op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameterName;
     335        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
    314336        op.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
    315337        op.EvaluationPartitionParameter.ActualName = FitnessCalculationPartitionParameter.Name;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r8600 r8664  
    151151    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    152152    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
     153    <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" />
    153154    <Compile Include="OnlineCalculators\HoeffdingsDependenceCalculator.cs" />
    154155    <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" />
     
    280281  -->
    281282  <PropertyGroup>
    282    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     283    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    283284set ProjectDir=$(ProjectDir)
    284285set SolutionDir=$(SolutionDir)
     
    287288call PreBuildEvent.cmd
    288289</PreBuildEvent>
    289 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     290    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
    290291export ProjectDir=$(ProjectDir)
    291292export SolutionDir=$(SolutionDir)
  • 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    }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/SamplesTest.cs

    r8596 r8664  
    234234      ga.SetSeedRandomly.Value = false;
    235235      RunAlgorithm(ga);
    236       Assert.AreEqual(0.84966698918060757, GetDoubleResult(ga, "BestQuality"), 1E-8);
    237       Assert.AreEqual(0.59815405391256571, GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);
     236      Assert.AreEqual(0.847170741142629, GetDoubleResult(ga, "BestQuality"), 1E-8);
     237      Assert.AreEqual(0.58487147022708, GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);
    238238      Assert.AreEqual(0, GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8);
    239239      Assert.AreEqual(50950, GetIntResult(ga, "EvaluatedSolutions"));
Note: See TracChangeset for help on using the changeset viewer.