Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/15 16:49:13 (9 years ago)
Author:
bburlacu
Message:

#2480: Implemented the necessary changes in the evaluators, and removed obsolete code from the phenotypic diversity analyzer.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators
Files:
7 edited

Legend:

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

    r12012 r12973  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    32   [Item("Log Residual Evaluator", "Evaluator for symbolic regression models that calculates the mean of logarithmic absolute residuals avg(log( 1 + abs(y' - y)))" + 
     32  [Item("Log Residual Evaluator", "Evaluator for symbolic regression models that calculates the mean of logarithmic absolute residuals avg(log( 1 + abs(y' - y)))" +
    3333                                  "This evaluator does not perform linear scaling!" +
    3434                                  "This evaluator can be useful if the modeled function contains discontinuities (e.g. 1/x). " +
     
    5757      IEnumerable<int> rows = GenerateRowsToEvaluate();
    5858
    59       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     59      var problemData = ProblemDataParameter.ActualValue;
     60      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     61      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     62      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     63      var estimationLimits = EstimationLimitsParameter.ActualValue;
     64
     65      if (SaveEstimatedValuesToScope) {
     66        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     67        var scope = ExecutionContext.Scope;
     68        if (scope.Variables.ContainsKey("EstimatedValues"))
     69          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     70        else
     71          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     72      }
     73
     74      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper);
    6075      QualityParameter.ActualValue = new DoubleValue(quality);
    6176
     
    6681      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    6782      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     83      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit);
     84    }
     85
     86    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit) {
    6887      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6988
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs

    r12012 r12973  
    5050      IEnumerable<int> rows = GenerateRowsToEvaluate();
    5151
    52       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     52      var problemData = ProblemDataParameter.ActualValue;
     53      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     54      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     55      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     56      var estimationLimits = EstimationLimitsParameter.ActualValue;
     57
     58      if (SaveEstimatedValuesToScope) {
     59        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     60        var scope = ExecutionContext.Scope;
     61        if (scope.Variables.ContainsKey("EstimatedValues"))
     62          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     63        else
     64          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     65      }
     66
     67      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper);
    5368      QualityParameter.ActualValue = new DoubleValue(quality);
    5469
     
    5974      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    6075      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     76      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit);
     77    }
     78
     79    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit) {
    6180      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6281
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r12012 r12973  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2522using HeuristicLab.Common;
    2623using HeuristicLab.Core;
     
    3027namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3128  [StorableClass]
    32   public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 
     29  public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {
     30    private const string SaveEstimatedValuesToScopeParameterName = "SaveEstimatedValuesToScope";
     31
     32    public IFixedValueParameter<BoolValue> SaveEstimatedValuesToScopeParameter {
     33      get { return (IFixedValueParameter<BoolValue>)Parameters[SaveEstimatedValuesToScopeParameterName]; }
     34    }
     35
     36    public bool SaveEstimatedValuesToScope { get { return SaveEstimatedValuesToScopeParameter.Value.Value; } }
     37
    3338    [StorableConstructor]
    3439    protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
    3540    protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
    36     protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}   
     41
     42    protected SymbolicRegressionSingleObjectiveEvaluator() : base() {
     43      Parameters.Add(new FixedValueParameter<BoolValue>(SaveEstimatedValuesToScopeParameterName, new BoolValue(false)));
     44      SaveEstimatedValuesToScopeParameter.Hidden = true;
     45    }
    3746  }
    3847}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r12012 r12973  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    4647      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4748
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     49      var problemData = ProblemDataParameter.ActualValue;
     50      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     51      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     52      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     53      var estimationLimits = EstimationLimitsParameter.ActualValue;
     54
     55      if (SaveEstimatedValuesToScope) {
     56        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     57        var scope = ExecutionContext.Scope;
     58        if (scope.Variables.ContainsKey("EstimatedValues"))
     59          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     60        else
     61          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     62      }
     63
     64      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value);
    4965      QualityParameter.ActualValue = new DoubleValue(quality);
    5066
     
    5571      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5672      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     73      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);
     74    }
     75
     76    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {
    5777      OnlineCalculatorError errorState;
    5878
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r12012 r12973  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    4647      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4748
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     49      var problemData = ProblemDataParameter.ActualValue;
     50      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     51      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     52      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     53      var estimationLimits = EstimationLimitsParameter.ActualValue;
     54
     55      if (SaveEstimatedValuesToScope) {
     56        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     57        var scope = ExecutionContext.Scope;
     58        if (scope.Variables.ContainsKey("EstimatedValues"))
     59          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     60        else
     61          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     62      }
     63
     64      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value);
    4965      QualityParameter.ActualValue = new DoubleValue(quality);
    5066
     
    5571      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5672      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     73      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);
     74    }
     75
     76    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {
    5777      OnlineCalculatorError errorState;
    5878
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r12012 r12973  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    4647      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4748
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     49      var problemData = ProblemDataParameter.ActualValue;
     50      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     51      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     52      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     53      var estimationLimits = EstimationLimitsParameter.ActualValue;
     54
     55      if (SaveEstimatedValuesToScope) {
     56        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     57        var scope = ExecutionContext.Scope;
     58        if (scope.Variables.ContainsKey("EstimatedValues"))
     59          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     60        else
     61          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     62      }
     63
     64      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value);
    4965      QualityParameter.ActualValue = new DoubleValue(quality);
    5066
     
    5571      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5672      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     73      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);
     74    }
     75
     76    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {
    5777      OnlineCalculatorError errorState;
    5878
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r12641 r12973  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    4849      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4950
    50       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     51      var problemData = ProblemDataParameter.ActualValue;
     52      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     53      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).ToArray();
     54      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     55      var estimationLimits = EstimationLimitsParameter.ActualValue;
     56
     57      if (SaveEstimatedValuesToScope) {
     58        var boundedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper).ToArray();
     59        var scope = ExecutionContext.Scope;
     60        if (scope.Variables.ContainsKey("EstimatedValues"))
     61          scope.Variables["EstimatedValues"].Value = new DoubleArray(boundedValues);
     62        else
     63          scope.Variables.Add(new Core.Variable("EstimatedValues", new DoubleArray(boundedValues)));
     64      }
     65
     66      double quality = Calculate(targetValues, estimatedValues, estimationLimits.Lower, estimationLimits.Upper, problemData, ApplyLinearScalingParameter.ActualValue.Value);
    5167      QualityParameter.ActualValue = new DoubleValue(quality);
    5268
     
    5773      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    5874      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     75      return Calculate(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, problemData, applyLinearScaling);
     76    }
     77
     78    private static double Calculate(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, bool applyLinearScaling) {
    5979      OnlineCalculatorError errorState;
    6080
     
    7090      }
    7191      if (errorState != OnlineCalculatorError.None) return double.NaN;
    72       return r*r;
     92      return r * r;
    7393    }
    7494
Note: See TracChangeset for help on using the changeset viewer.