Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/12/15 10:35:02 (9 years ago)
Author:
mkommend
Message:

#2175: Merged trunk changes and extracted parameters of evaluators to their base class.

Location:
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs

    r12147 r12848  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Parameters;
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130
     
    3433  [StorableClass]
    3534  public class PearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    36     private const string useConstantOptimizationParameterName = "Use constant optimization";
    37     public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
    38       get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
    39     }
    40     public bool UseConstantOptimization {
    41       get { return UseConstantOptimizationParameter.Value.Value; }
    42       set { UseConstantOptimizationParameter.Value.Value = value; }
    43     }
    44 
    4535    [StorableConstructor]
    4636    protected PearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
     
    5242    }
    5343
    54     public PearsonRSquaredNestedTreeSizeEvaluator()
    55       : base() {
    56       Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    57     }
     44    public PearsonRSquaredNestedTreeSizeEvaluator() : base() { }
    5845
    5946    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    7158      }
    7259
    73       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     60      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    7461      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    7562      return base.InstrumentedApply();
    7663    }
    7764
    78     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
     65    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    7966      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    80       r2 = Math.Round(r2, 3);
     67      if (decimalPlaces >= 0)
     68        r2 = Math.Round(r2, decimalPlaces);
    8169      return new double[2] { r2, solution.IterateNodesPostfix().Sum(n => n.GetLength()) };
    8270    }
     
    8775      ApplyLinearScalingParameter.ExecutionContext = context;
    8876
    89       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     77      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    9078
    9179      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberOfVariablesEvaluator.cs

    r12147 r12848  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Security.Cryptography;
    2625using HeuristicLab.Common;
    2726using HeuristicLab.Core;
    2827using HeuristicLab.Data;
    2928using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    30 using HeuristicLab.Parameters;
    3129using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3230
     
    3533  [StorableClass]
    3634  public class PearsonRSquaredNumberOfVariablesEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    37     private const string useConstantOptimizationParameterName = "Use constant optimization";
    38     public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
    39       get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
    40     }
    41     public bool UseConstantOptimization {
    42       get { return UseConstantOptimizationParameter.Value.Value; }
    43       set { UseConstantOptimizationParameter.Value.Value = value; }
    44     }
    45 
    4635    [StorableConstructor]
    4736    protected PearsonRSquaredNumberOfVariablesEvaluator(bool deserializing) : base(deserializing) { }
     
    5342    }
    5443
    55     public PearsonRSquaredNumberOfVariablesEvaluator()
    56       : base() {
    57       Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    58     }
     44    public PearsonRSquaredNumberOfVariablesEvaluator() : base() { }
    5945
    6046    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    7157        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
    7258      }
    73       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     59      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    7460      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    7561      return base.InstrumentedApply();
    7662    }
    7763
    78     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
     64    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    7965      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    80       r2 = Math.Round(r2, 3);
     66      if (decimalPlaces >= 0)
     67        r2 = Math.Round(r2, decimalPlaces);
    8168      return new double[2] { r2, solution.IterateNodesPostfix().OfType<VariableTreeNode>().Count() };
    8269    }
     
    8774      ApplyLinearScalingParameter.ExecutionContext = context;
    8875
    89       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     76      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    9077
    9178      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs

    r12147 r12848  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3029
     
    3332  [StorableClass]
    3433  public class PearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    35     private const string useConstantOptimizationParameterName = "Use constant optimization";
    36     public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
    37       get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
    38     }
    39     public bool UseConstantOptimization {
    40       get { return UseConstantOptimizationParameter.Value.Value; }
    41       set { UseConstantOptimizationParameter.Value.Value = value; }
    42     }
    43 
    4434    [StorableConstructor]
    4535    protected PearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { }
     
    5141    }
    5242
    53     public PearsonRSquaredTreeComplexityEvaluator()
    54       : base() {
    55       Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    56     }
    57 
    58     [StorableHook(HookType.AfterDeserialization)]
    59     private void AfterDeserialization() {
    60       if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) {
    61         Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    62       }
    63     }
     43    public PearsonRSquaredTreeComplexityEvaluator() : base() { }
    6444
    6545    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    7656        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
    7757      }
    78       double[] qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling);
     58      double[] qualities = Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling, DecimalPlaces);
    7959      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    8060      return base.InstrumentedApply();
    8161    }
    8262
    83     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
     63    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    8464      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    85       r2 = Math.Round(r2, 3);
     65      if (decimalPlaces >= 0)
     66        r2 = Math.Round(r2, decimalPlaces);
    8667      return new double[2] { r2, SymbolicDataAnalysisModelComplexityAnalyzer.CalculateComplexity(solution.Root.GetSubtree(0).GetSubtree(0)) };
    8768    }
     
    9273      ApplyLinearScalingParameter.ExecutionContext = context;
    9374
    94       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     75      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    9576
    9677      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveEvaluator.cs

    r12130 r12848  
    2222
    2323using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
    2427using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28
    2529namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     30  [StorableClass]
    2631  public abstract class SymbolicRegressionMultiObjectiveEvaluator : SymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionMultiObjectiveEvaluator {
     32    private const string DecimalPlacesParameterName = "Decimal Places";
     33    private const string UseConstantOptimizationParameterName = "Use constant optimization";
     34
     35    public IFixedValueParameter<IntValue> DecimalPlacesParameter {
     36      get { return (IFixedValueParameter<IntValue>)Parameters[DecimalPlacesParameterName]; }
     37    }
     38    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
     39      get { return (IFixedValueParameter<BoolValue>)Parameters[UseConstantOptimizationParameterName]; }
     40    }
     41
     42    public int DecimalPlaces {
     43      get { return DecimalPlacesParameter.Value.Value; }
     44      set { DecimalPlacesParameter.Value.Value = value; }
     45    }
     46    public bool UseConstantOptimization {
     47      get { return UseConstantOptimizationParameter.Value.Value; }
     48      set { UseConstantOptimizationParameter.Value.Value = value; }
     49    }
     50
    2751    [StorableConstructor]
    2852    protected SymbolicRegressionMultiObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     
    3155    }
    3256
    33     protected SymbolicRegressionMultiObjectiveEvaluator() : base() { }
     57    protected SymbolicRegressionMultiObjectiveEvaluator()
     58      : base() {
     59      Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(5)) { Hidden = true });
     60      Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false)));
     61    }
     62
     63    [StorableHook(HookType.AfterDeserialization)]
     64    private void AfterDeserialization() {
     65      if (!Parameters.ContainsKey(UseConstantOptimizationParameterName)) {
     66        Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false)));
     67      }
     68      if (!Parameters.ContainsKey(DecimalPlacesParameterName)) {
     69        Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(-1)) { Hidden = true });
     70      }
     71    }
    3472  }
    3573}
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r12130 r12848  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    4748      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4849      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     50      var problemData = ProblemDataParameter.ActualValue;
     51      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     52      var estimationLimits = EstimationLimitsParameter.ActualValue;
     53      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     54
     55      if (UseConstantOptimization) {
     56        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
     57      }
     58
     59      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    5060      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    5161      return base.InstrumentedApply();
    5262    }
    5363
    54     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    55       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       OnlineCalculatorError errorState;
     64    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     65      var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, solution, lowerEstimationLimit,
     66        upperEstimationLimit, problemData, rows, applyLinearScaling);
    5867
    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       }
    69       if (errorState != OnlineCalculatorError.None) mse = double.NaN;
     68      if (decimalPlaces >= 0)
     69        mse = Math.Round(mse, decimalPlaces);
     70
    7071      return new double[2] { mse, solution.Length };
    7172    }
     
    7677      ApplyLinearScalingParameter.ExecutionContext = context;
    7778
    78       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     79      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    7980
    8081      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r12147 r12848  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3029
     
    3332  [StorableClass]
    3433  public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    35     private const string useConstantOptimizationParameterName = "Use constant optimization";
    36     public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
    37       get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
    38     }
    39     public bool UseConstantOptimization {
    40       get { return UseConstantOptimizationParameter.Value.Value; }
    41       set { UseConstantOptimizationParameter.Value.Value = value; }
    42     }
    43 
    4434    [StorableConstructor]
    4535    protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
     
    5141    }
    5242
    53     public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base()
    54     {
    55       Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    56     }
    57 
    58     [StorableHook(HookType.AfterDeserialization)]
    59     private void AfterDeserialization() {
    60       if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) {
    61         Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    62       }
    63     }
     43    public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() { }
    6444
    6545    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    7656        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
    7757      }
    78       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     58      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    7959      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    8060      return base.InstrumentedApply();
    8161    }
    8262
    83     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
     63    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    8464      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    85       r2 = Math.Round(r2, 3);
     65      if (decimalPlaces >= 0)
     66        r2 = Math.Round(r2, decimalPlaces);
    8667      return new double[2] { r2, solution.Length };
    8768    }
     
    9273      ApplyLinearScalingParameter.ExecutionContext = context;
    9374
    94       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     75      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    9576
    9677      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame

    r12130 r12848  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.7.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.8.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties/AssemblyInfo.cs.frame

    r12130 r12848  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.7.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.8.$WCREV$")]
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r12130 r12848  
    5959      OnlineCalculatorError errorState;
    6060
    61       double r2;
     61      double r;
    6262      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;
     63        var rCalculator = new OnlinePearsonsRCalculator();
     64        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     65        errorState = rCalculator.ErrorState;
     66        r = rCalculator.R;
    6767      } else {
    6868        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    69         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     69        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    7070      }
    7171      if (errorState != OnlineCalculatorError.None) return double.NaN;
    72       return r2;
     72      return r*r;
    7373    }
    7474
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs

    r12547 r12848  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4950      Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
    5051    }
     52
     53    [StorableHook(HookType.AfterDeserialization)]
     54    private void AfterDeserialization() {
     55      // BackwardsCompatibility3.3
     56
     57      #region Backwards compatible code, remove with 3.4
     58      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
     59        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
     60        if (oldParam != null) {
     61          Parameters.Remove(oldParam);
     62          Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     63        }
     64      } else {
     65        // not yet contained
     66        Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     67      }
     68
     69
     70      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
     71        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
     72        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
     73      }
     74      if (Parameters.ContainsKey("ImpactThreshold")) {
     75        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
     76        Parameters.Remove(Parameters["ImpactThreshold"]);
     77      }
     78      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
     79        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
     80        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
     81      }
     82
     83      #endregion
     84    }
    5185  }
    5286}
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r12547 r12848  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
     
    3334  [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")]
    3435  public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
     36    private const string EvaluatorParameterName = "Evaluator";
     37
     38    #region parameter properties
     39    public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
     40      get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
     41    }
     42    #endregion
     43
    3544    protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner)
    3645      : base(original, cloner) {
     
    4554    public SymbolicRegressionPruningOperator(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator)
    4655      : base(impactValuesCalculator) {
     56      Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
     57    }
     58
     59    [StorableHook(HookType.AfterDeserialization)]
     60    private void AfterDeserialization() {
     61      // BackwardsCompatibility3.3
     62      #region Backwards compatible code, remove with 3.4
     63      base.ImpactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
     64      if (!Parameters.ContainsKey(EvaluatorParameterName)) {
     65        Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
     66      }
     67      #endregion
    4768    }
    4869
     
    5273
    5374    protected override double Evaluate(IDataAnalysisModel model) {
    54       var regressionModel = (IRegressionModel)model;
     75      var regressionModel = (ISymbolicRegressionModel)model;
    5576      var regressionProblemData = (IRegressionProblemData)ProblemDataParameter.ActualValue;
    56       var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size);
    57       return Evaluate(regressionModel, regressionProblemData, rows);
    58     }
    59 
    60     private static double Evaluate(IRegressionModel model, IRegressionProblemData problemData,
    61       IEnumerable<int> rows) {
    62       var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
    63       var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    64       OnlineCalculatorError errorState;
    65       var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
    66       if (errorState != OnlineCalculatorError.None) return double.NaN;
    67       return quality;
     77      var evaluator = EvaluatorParameter.ActualValue;
     78      var fitnessEvaluationPartition = FitnessCalculationPartitionParameter.ActualValue;
     79      var rows = Enumerable.Range(fitnessEvaluationPartition.Start, fitnessEvaluationPartition.Size);
     80      return evaluator.Evaluate(this.ExecutionContext, regressionModel.SymbolicExpressionTree, regressionProblemData, rows);
    6881    }
    6982
     
    7285      var model = new SymbolicRegressionModel(clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    7386      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol
    74       double quality = Evaluate(model, problemData, rows);
     87
     88      double qualityForImpactsCalculation = double.NaN; // pass a NaN value initially so the impact calculator will calculate the quality
    7589
    7690      for (int i = 0; i < nodes.Count; ++i) {
     
    7993
    8094        double impactValue, replacementValue;
    81         impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);
     95        double newQualityForImpactsCalculation;
     96        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    8297
    8398        if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     
    90105        i += node.GetLength() - 1; // skip subtrees under the node that was folded
    91106
    92         quality -= impactValue;
     107        qualityForImpactsCalculation = newQualityForImpactsCalculation;
    93108      }
    94109      return model.SymbolicExpressionTree;
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r12130 r12848  
    4848    }
    4949
    50     public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) {
    51       double impactValue, replacementValue;
    52       CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality);
     50    public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) {
     51      double impactValue, replacementValue, newQualityForImpactsCalculation;
     52      CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    5353      return impactValue;
    5454    }
    5555
    5656    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    57       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
    58       double originalQuality = Double.NaN) {
     57      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
     58      double qualityForImpactsCalculation = Double.NaN) {
    5959      var regressionModel = (ISymbolicRegressionModel)model;
    6060      var regressionProblemData = (IRegressionProblemData)problemData;
     
    6464
    6565      OnlineCalculatorError errorState;
    66       if (double.IsNaN(originalQuality)) {
    67         var originalValues = regressionModel.GetEstimatedValues(dataset, rows);
    68         originalQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalValues, out errorState);
    69         if (errorState != OnlineCalculatorError.None) originalQuality = 0.0;
    70       }
     66      if (double.IsNaN(qualityForImpactsCalculation))
     67        qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows);
    7168
    7269      replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows);
     
    8380
    8481      var estimatedValues = tempModel.GetEstimatedValues(dataset, rows);
    85       double newQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
    86       if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
     82      double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
     83      if (errorState != OnlineCalculatorError.None) r = 0.0;
     84      newQualityForImpactsCalculation = r * r;
    8785
    88       impactValue = originalQuality - newQuality;
     86      impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     87    }
     88
     89    public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) {
     90      var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
     91      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     92      OnlineCalculatorError errorState;
     93      var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
     94      var quality = r * r;
     95      if (errorState != OnlineCalculatorError.None) return double.NaN;
     96      return quality;
    8997    }
    9098  }
Note: See TracChangeset for help on using the changeset viewer.