Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18103 for branches


Ignore:
Timestamp:
12/02/21 17:23:10 (3 years ago)
Author:
dpiringe
Message:

#3136

  • refactor the evaluation logic of NMSESingleObjectiveConstraintsEvaluator
  • refactor the new method Evaluate for PearsonRSquaredAverageSimilarityEvaluator
  • change the parameter order of some evaluate/calculate methods
Location:
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSingleObjectiveEvaluator.cs

    r18095 r18103  
    2828  public interface ISymbolicRegressionSingleObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> {
    2929    double Evaluate(
    30       IRegressionProblemData problemData,
    31       ISymbolicExpressionTree tree,
    32       ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    33       IEnumerable<int> rows = null,
     30      ISymbolicExpressionTree tree,
     31      IRegressionProblemData problemData,
     32      IEnumerable<int> rows,
     33      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    3434      bool applyLinearScaling = true,
    3535      double lowerEstimationLimit = double.MinValue,
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredAverageSimilarityEvaluator.cs

    r17180 r18103  
    7070    public override IOperation InstrumentedApply() {
    7171      IEnumerable<int> rows = GenerateRowsToEvaluate();
    72       var solution = SymbolicExpressionTreeParameter.ActualValue;
     72      var tree = SymbolicExpressionTreeParameter.ActualValue;
    7373      var problemData = ProblemDataParameter.ActualValue;
    7474      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     
    7777
    7878      if (UseConstantOptimization) {
    79         SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
     79        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
    8080      }
    8181
    82       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling);
     82      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     83        tree, problemData, rows, interpreter, applyLinearScaling,
     84        estimationLimits.Lower, estimationLimits.Upper);
    8385
    8486      if (DecimalPlaces >= 0)
     
    107109      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
    108110
    109       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, applyLinearScaling);
     111      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     112        tree, problemData, rows,
     113        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     114        applyLinearScaling,
     115        estimationLimits.Lower, estimationLimits.Upper);
    110116
    111117      lock (locker) {
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs

    r17180 r18103  
    6363    }
    6464
    65     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    66       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     65    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     66      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     67         tree, problemData, rows,
     68         interpreter, applyLinearScaling,
     69         lowerEstimationLimit, upperEstimationLimit);
    6770      if (decimalPlaces >= 0)
    6871        r2 = Math.Round(r2, decimalPlaces);
    69       return new double[2] { r2, solution.IterateNodesPostfix().Sum(n => n.GetLength()) }; // sum of the length of the whole sub-tree for each node
     72      return new double[2] { r2, tree.IterateNodesPostfix().Sum(n => n.GetLength()) }; // sum of the length of the whole sub-tree for each node
    7073    }
    7174
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberOfVariablesEvaluator.cs

    r17180 r18103  
    6262    }
    6363
    64     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    65       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     64    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     65      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     66        tree, problemData, rows, interpreter, applyLinearScaling,
     67        lowerEstimationLimit, upperEstimationLimit);
    6668      if (decimalPlaces >= 0)
    6769        r2 = Math.Round(r2, decimalPlaces);
    68       return new double[2] { r2, solution.IterateNodesPostfix().OfType<IVariableTreeNode>().Count() }; // count the number of variables
     70      return new double[2] { r2, tree.IterateNodesPostfix().OfType<IVariableTreeNode>().Count() }; // count the number of variables
    6971    }
    7072
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs

    r17180 r18103  
    6161    }
    6262
    63     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    64       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     63    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     64      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     65         tree, problemData, rows,
     66         interpreter, applyLinearScaling,
     67         lowerEstimationLimit, upperEstimationLimit);
    6568      if (decimalPlaces >= 0)
    6669        r2 = Math.Round(r2, decimalPlaces);
    67       return new double[2] { r2, SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity(solution) };
     70      return new double[2] { r2, SymbolicDataAnalysisModelComplexityCalculator.CalculateComplexity(tree) };
    6871    }
    6972
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r17180 r18103  
    4747    public override IOperation InstrumentedApply() {
    4848      IEnumerable<int> rows = GenerateRowsToEvaluate();
    49       var solution = SymbolicExpressionTreeParameter.ActualValue;
     49      var tree = SymbolicExpressionTreeParameter.ActualValue;
    5050      var problemData = ProblemDataParameter.ActualValue;
    5151      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     
    5454
    5555      if (UseConstantOptimization) {
    56         SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
     56        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
    5757      }
    5858
    59       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
     59      double[] qualities = Calculate(
     60        tree, ProblemDataParameter.ActualValue,
     61        rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     62        ApplyLinearScalingParameter.ActualValue.Value,
     63        EstimationLimitsParameter.ActualValue.Lower,
     64        EstimationLimitsParameter.ActualValue.Upper,
     65        DecimalPlaces);
    6066      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    6167      return base.InstrumentedApply();
    6268    }
    6369
    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);
     70    public static double[] Calculate(
     71      ISymbolicExpressionTree tree,
     72      IRegressionProblemData problemData,
     73      IEnumerable<int> rows,
     74      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     75      bool applyLinearScaling,
     76      double lowerEstimationLimit, double upperEstimationLimit,
     77      int decimalPlaces) {
     78      var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(
     79        tree, problemData, rows,
     80        interpreter, applyLinearScaling,
     81        lowerEstimationLimit,
     82        upperEstimationLimit);
    6783
    6884      if (decimalPlaces >= 0)
    6985        mse = Math.Round(mse, decimalPlaces);
    7086
    71       return new double[2] { mse, solution.Length };
     87      return new double[2] { mse, tree.Length };
    7288    }
    7389
     
    7793      ApplyLinearScalingParameter.ExecutionContext = context;
    7894
    79       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
     95      double[] quality = Calculate(
     96        tree, problemData, rows,
     97        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     98        ApplyLinearScalingParameter.ActualValue.Value,
     99        EstimationLimitsParameter.ActualValue.Lower,
     100        EstimationLimitsParameter.ActualValue.Upper, DecimalPlaces);
    80101
    81102      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r17180 r18103  
    6161    }
    6262
    63     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
    64       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     63    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     64      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     65        tree, problemData, rows, interpreter, applyLinearScaling,
     66        lowerEstimationLimit, upperEstimationLimit);
    6567      if (decimalPlaces >= 0)
    6668        r2 = Math.Round(r2, decimalPlaces);
    67       return new double[2] { r2, solution.Length };
     69      return new double[2] { r2, tree.Length };
    6870    }
    6971
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs

    r18095 r18103  
    125125      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
    126126
    127       if (OptimizeParameters) {
    128         SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, rows,
    129           false, ConstantOptimizationIterations, true,
    130           estimationLimits.Lower, estimationLimits.Upper);
    131       } else {
    132         if (applyLinearScaling) {
    133           var rootNode = new ProgramRootSymbol().CreateTreeNode();
    134           var startNode = new StartSymbol().CreateTreeNode();
    135           var offset = tree.Root.GetSubtree(0) //Start
    136                                 .GetSubtree(0); //Offset
    137           var scaling = offset.GetSubtree(0);
    138 
    139           //Check if tree contains offset and scaling nodes
    140           if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication))
    141             throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar.");
    142 
    143           var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone();
    144           rootNode.AddSubtree(startNode);
    145           startNode.AddSubtree(t);
    146           var newTree = new SymbolicExpressionTree(rootNode);
    147 
    148           //calculate alpha and beta for scaling
    149           var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
    150 
    151           var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    152           OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
    153             out var errorState);
    154 
    155           if (errorState == OnlineCalculatorError.None) {
    156             //Set alpha and beta to the scaling nodes from ia grammar
    157             var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode;
    158             offsetParameter.Value = alpha;
    159             var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode;
    160             scalingParameter.Value = beta;
    161           }
    162         } // else: alpha and beta are evolved
     127      var quality = Evaluate(tree, problemData, rows, interpreter, applyLinearScaling, estimationLimits.Lower, estimationLimits.Upper);
     128      QualityParameter.ActualValue = new DoubleValue(quality);
     129
     130      return base.InstrumentedApply();
     131    }
     132
     133    private static void CalcLinearScalingTerms(
     134      ISymbolicExpressionTree tree,
     135      IRegressionProblemData problemData,
     136      IEnumerable<int> rows,
     137      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter) {
     138      var rootNode = new ProgramRootSymbol().CreateTreeNode();
     139      var startNode = new StartSymbol().CreateTreeNode();
     140      var offset = tree.Root.GetSubtree(0) //Start
     141                            .GetSubtree(0); //Offset
     142      var scaling = offset.GetSubtree(0);
     143
     144      //Check if tree contains offset and scaling nodes
     145      if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication))
     146        throw new ArgumentException($"Shape Constraints Evaluation can only be used with LinearScalingGrammar.");
     147
     148      var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone();
     149      rootNode.AddSubtree(startNode);
     150      startNode.AddSubtree(t);
     151      var newTree = new SymbolicExpressionTree(rootNode);
     152
     153      //calculate alpha and beta for scaling
     154      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
     155
     156      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     157      OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
     158        out var errorState);
     159      if (errorState == OnlineCalculatorError.None) {
     160        //Set alpha and beta to the scaling nodes from ia grammar
     161        var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode;
     162        offsetParameter.Value = alpha;
     163        var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode;
     164        scalingParameter.Value = beta;
    163165      }
    164 
    165       var quality = Calculate(interpreter, tree, estimationLimits.Lower, estimationLimits.Upper, problemData, rows,
    166         BoundsEstimator, UseSoftConstraints, PenalityFactor);
    167       QualityParameter.ActualValue = new DoubleValue(quality);
    168 
    169       return base.InstrumentedApply();
    170166    }
    171167
    172168    public static double Calculate(
     169      ISymbolicExpressionTree tree,
     170      IRegressionProblemData problemData, IEnumerable<int> rows,
    173171      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    174       ISymbolicExpressionTree tree,
    175172      double lowerEstimationLimit, double upperEstimationLimit,
    176       IRegressionProblemData problemData, IEnumerable<int> rows,
    177173      IBoundsEstimator estimator,
    178174      bool useSoftConstraints = false, double penaltyFactor = 1.0) {
    179175
     176      var constraints = Enumerable.Empty<ShapeConstraint>();
     177      if (problemData is ShapeConstrainedRegressionProblemData scProbData)
     178        constraints = scProbData.ShapeConstraints.EnabledConstraints;
     179
    180180      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
     181      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    181182      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    182       var constraints = Enumerable.Empty<ShapeConstraint>();
    183       if (problemData is ShapeConstrainedRegressionProblemData scProbData) {
    184         constraints = scProbData.ShapeConstraints.EnabledConstraints;
    185       }
     183      var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out var errorState);
     184      if (errorState != OnlineCalculatorError.None)
     185        return 1.0;
     186
     187      if (!constraints.Any())
     188        return nmse;
     189
    186190      var intervalCollection = problemData.VariableRanges;
    187 
    188       var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    189       var nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues,
    190         out var errorState);
    191 
    192       if (errorState != OnlineCalculatorError.None) {
     191      var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, tree);
     192
     193      // infinite/NaN constraints
     194      if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x)))
    193195        return 1.0;
     196     
     197      // hard constraints
     198      if (!useSoftConstraints) {
     199        if (constraintViolations.Any(x => x > 0.0))
     200          return 1.0;
     201        return nmse;
    194202      }
    195203
    196       var constraintViolations = IntervalUtil.GetConstraintViolations(constraints, estimator, intervalCollection, tree);
    197 
    198       if (constraintViolations.Any(x => double.IsNaN(x) || double.IsInfinity(x))) {
    199         return 1.0;
    200       }
    201 
    202       if (useSoftConstraints) {
    203         if (penaltyFactor < 0.0)
    204           throw new ArgumentException("The parameter has to be >= 0.0.", nameof(penaltyFactor));
    205 
    206         var weightedViolationsAvg = constraints
    207           .Zip(constraintViolations, (c, v) => c.Weight * v)
    208           .Average();
    209 
    210         return Math.Min(nmse, 1.0) + penaltyFactor * weightedViolationsAvg;
    211       } else if (constraintViolations.Any(x => x > 0.0)) {
    212         return 1.0;
    213       }
    214 
    215       return nmse;
     204      // soft constraints
     205      if (penaltyFactor < 0.0)
     206        throw new ArgumentException("The parameter has to be >= 0.0.", nameof(penaltyFactor));
     207
     208      var weightedViolationsAvg = constraints
     209        .Zip(constraintViolations, (c, v) => c.Weight * v)
     210        .Average();
     211
     212      return Math.Min(nmse, 1.0) + penaltyFactor * weightedViolationsAvg;
    216213    }
    217214
     
    223220      ApplyLinearScalingParameter.ExecutionContext = context;
    224221
    225       var nmse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
    226         EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
    227         problemData, rows, BoundsEstimator, UseSoftConstraints, PenalityFactor);
     222      var nmse = Calculate(
     223        tree, problemData, rows,
     224        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     225        EstimationLimitsParameter.ActualValue.Lower,
     226        EstimationLimitsParameter.ActualValue.Upper,
     227        BoundsEstimator,
     228        UseSoftConstraints,
     229        PenalityFactor);
    228230
    229231      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    234236    }
    235237
    236     public override double Evaluate(IRegressionProblemData problemData,
    237       ISymbolicExpressionTree solution,
     238    public override double Evaluate(
     239      ISymbolicExpressionTree tree,
     240      IRegressionProblemData problemData,
     241      IEnumerable<int> rows,
    238242      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    239       IEnumerable<int> rows = null,
    240243      bool applyLinearScaling = true,
    241244      double lowerEstimationLimit = double.MinValue,
    242245      double upperEstimationLimit = double.MaxValue) {
    243246
    244       if (OptimizeParameters) {
     247      if (OptimizeParameters)
    245248        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(
    246           interpreter,
    247           solution,
    248           problemData,
    249           rows,
    250           false,
     249          interpreter, tree,
     250          problemData, rows,
     251          applyLinearScaling: false, // OptimizeConstants deletes the scaling terms -> wrong estimations
    251252          ConstantOptimizationIterations,
    252           true,
     253          updateVariableWeights: true,
    253254          lowerEstimationLimit,
    254255          upperEstimationLimit);
    255       } else {
    256         if (applyLinearScaling) {
    257           var rootNode = new ProgramRootSymbol().CreateTreeNode();
    258           var startNode = new StartSymbol().CreateTreeNode();
    259           var offset = solution.Root.GetSubtree(0) //Start
    260                                     .GetSubtree(0); //Offset
    261           var scaling = offset.GetSubtree(0);
    262 
    263           //Check if tree contains offset and scaling nodes
    264           if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication))
    265             throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar.");
    266 
    267           var t = (ISymbolicExpressionTreeNode)scaling.GetSubtree(0).Clone();
    268           rootNode.AddSubtree(startNode);
    269           startNode.AddSubtree(t);
    270           var newTree = new SymbolicExpressionTree(rootNode);
    271 
    272           //calculate alpha and beta for scaling
    273           var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
    274 
    275           var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    276           OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out var alpha, out var beta,
    277             out var errorState);
    278 
    279           if (errorState == OnlineCalculatorError.None) {
    280             //Set alpha and beta to the scaling nodes from ia grammar
    281             var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode;
    282             offsetParameter.Value = alpha;
    283             var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode;
    284             scalingParameter.Value = beta;
    285           }
    286         } // else: alpha and beta are evolved
    287       }
     256     
     257      if (applyLinearScaling) // extra scaling terms, which are included in tree
     258        CalcLinearScalingTerms(tree, problemData, rows, interpreter);
     259
    288260      return Calculate(
    289         interpreter,
    290         solution,
     261        tree, problemData,
     262        rows, interpreter,
    291263        lowerEstimationLimit,
    292264        upperEstimationLimit,
    293         problemData,
    294         rows ?? problemData.TrainingIndices,
    295265        BoundsEstimator,
    296266        UseSoftConstraints,
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r18099 r18103  
    149149    private static readonly object locker = new object();
    150150    public override IOperation InstrumentedApply() {
    151       var solution = SymbolicExpressionTreeParameter.ActualValue;
     151      var tree = SymbolicExpressionTreeParameter.ActualValue;
    152152      double quality;
    153153      if (RandomParameter.ActualValue.NextDouble() < ConstantOptimizationProbability.Value) {
    154154        IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value);
    155155        var counter = new EvaluationsCounter();
    156         quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue,
     156        quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, ProblemDataParameter.ActualValue,
    157157           constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateConstantsInTree: UpdateConstantsInTree, counter: counter);
    158158
    159159        if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
    160160          var evaluationRows = GenerateRowsToEvaluate();
    161           quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
     161          quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     162            tree, ProblemDataParameter.ActualValue,
     163            evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     164            ApplyLinearScalingParameter.ActualValue.Value,
     165            EstimationLimitsParameter.ActualValue.Lower,
     166            EstimationLimitsParameter.ActualValue.Upper);
    162167        }
    163168
     
    171176      } else {
    172177        var evaluationRows = GenerateRowsToEvaluate();
    173         quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
     178        quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     179          tree, ProblemDataParameter.ActualValue,
     180          evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     181          ApplyLinearScalingParameter.ActualValue.Value,
     182          EstimationLimitsParameter.ActualValue.Lower,
     183          EstimationLimitsParameter.ActualValue.Upper);
    174184      }
    175185      QualityParameter.ActualValue = new DoubleValue(quality);
     
    178188    }
    179189
    180     public override double Evaluate(IRegressionProblemData problemData,
    181       ISymbolicExpressionTree solution,
     190    public override double Evaluate(
     191      ISymbolicExpressionTree tree,
     192      IRegressionProblemData problemData,
     193      IEnumerable<int> rows,
    182194      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    183       IEnumerable<int> rows = null,
    184195      bool applyLinearScaling = true,
    185196      double lowerEstimationLimit = double.MinValue,
    186197      double upperEstimationLimit = double.MaxValue) {
    187198
    188 
    189       var random = RandomParameter?.Value ?? new MersenneTwister((uint)DateTime.Now.Millisecond);
    190       double quality;
     199      var random = RandomParameter.ActualValue;
     200      double quality = double.NaN;
    191201
    192202      var propability = random.NextDouble();
    193203      if (propability < ConstantOptimizationProbability.Value) {
    194         var counter = new EvaluationsCounter();
     204        IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value);
    195205        quality = OptimizeConstants(
    196           interpreter,
    197           solution,
    198           problemData,
    199           rows ?? problemData.TrainingIndices,
    200           applyLinearScaling,
    201           ConstantOptimizationIterations.Value,
    202           updateVariableWeights: UpdateVariableWeights,
    203           lowerEstimationLimit: lowerEstimationLimit,
    204           upperEstimationLimit: upperEstimationLimit,
    205           updateConstantsInTree: UpdateConstantsInTree,
    206           counter: counter);
    207 
    208         if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { //TODO: remove this?
    209           var evaluationRows = GenerateRowsToEvaluate();
    210           quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
    211             interpreter,
    212             solution,
    213             lowerEstimationLimit,
    214             upperEstimationLimit,
    215             problemData,
    216             evaluationRows,
    217             applyLinearScaling);
    218         }
    219 
    220       } else {
    221         var evaluationRows = GenerateRowsToEvaluate();
     206          interpreter, tree,
     207          problemData, constantOptimizationRows,
     208          applyLinearScaling,
     209          ConstantOptimizationIterations.Value,
     210          updateVariableWeights: UpdateVariableWeights,
     211          lowerEstimationLimit: lowerEstimationLimit,
     212          upperEstimationLimit: upperEstimationLimit,
     213          updateConstantsInTree: UpdateConstantsInTree);
     214      }
     215      if (double.IsNaN(quality) || ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
    222216        quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
    223           interpreter,
    224           solution,
     217          tree, problemData,
     218          rows, interpreter,
     219          applyLinearScaling,
    225220          lowerEstimationLimit,
    226           upperEstimationLimit,
    227           problemData,
    228           evaluationRows,
    229           applyLinearScaling);
     221          upperEstimationLimit);
    230222      }
    231223      return quality;
     
    242234      // because Evaluate() is used to get the quality of evolved models on
    243235      // different partitions of the dataset (e.g., best validation model)
    244       double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     236      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     237        tree, problemData, rows,
     238        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     239        ApplyLinearScalingParameter.ActualValue.Value,
     240        EstimationLimitsParameter.ActualValue.Lower,
     241        EstimationLimitsParameter.ActualValue.Upper);
    245242
    246243      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    290287      }
    291288
    292       double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     289      double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     290        tree, problemData, rows,
     291        interpreter, applyLinearScaling,
     292        lowerEstimationLimit,
     293        upperEstimationLimit);
    293294
    294295      if (counter == null) counter = new EvaluationsCounter();
     
    348349        } else UpdateConstants(tree, c, updateVariableWeights);
    349350      }
    350       var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     351      var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     352        tree, problemData, rows,
     353        interpreter, applyLinearScaling,
     354        lowerEstimationLimit, upperEstimationLimit);
    351355
    352356      if (!updateConstantsInTree) UpdateConstants(tree, initialConstants, updateVariableWeights);
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionLogResidualEvaluator.cs

    r18095 r18103  
    5454
    5555    public override IOperation InstrumentedApply() {
    56       var solution = SymbolicExpressionTreeParameter.ActualValue;
     56      var tree = SymbolicExpressionTreeParameter.ActualValue;
    5757      IEnumerable<int> rows = GenerateRowsToEvaluate();
    5858
    59       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     59      double quality = Calculate(
     60        tree, ProblemDataParameter.ActualValue,
     61        rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     62        EstimationLimitsParameter.ActualValue.Lower,
     63        EstimationLimitsParameter.ActualValue.Upper);
    6064      QualityParameter.ActualValue = new DoubleValue(quality);
    6165
     
    6367    }
    6468
    65     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
    66       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
     69    public static double Calculate(
     70      ISymbolicExpressionTree tree,
     71      IRegressionProblemData problemData,
     72      IEnumerable<int> rows,
     73      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     74      double lowerEstimationLimit,
     75      double upperEstimationLimit) {
     76      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    6777      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    6878      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     
    8393      EstimationLimitsParameter.ExecutionContext = context;
    8494
    85       double mlr = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     95      double mlr = Calculate(
     96        tree, problemData, rows,
     97        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     98        EstimationLimitsParameter.ActualValue.Lower,
     99        EstimationLimitsParameter.ActualValue.Upper);
    86100
    87101      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    91105    }
    92106
    93     public override double Evaluate(IRegressionProblemData problemData,
    94       ISymbolicExpressionTree solution,
     107    public override double Evaluate(
     108      ISymbolicExpressionTree tree,
     109      IRegressionProblemData problemData,
     110      IEnumerable<int> rows,
    95111      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    96       IEnumerable<int> rows = null,
    97112      bool applyLinearScaling = true,
    98113      double lowerEstimationLimit = double.MinValue,
    99114      double upperEstimationLimit = double.MaxValue) {
    100       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices);
     115      return Calculate(tree, problemData, rows, interpreter, lowerEstimationLimit, upperEstimationLimit);
    101116    }
    102117  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs

    r18095 r18103  
    4747
    4848    public override IOperation InstrumentedApply() {
    49       var solution = SymbolicExpressionTreeParameter.ActualValue;
     49      var tree = SymbolicExpressionTreeParameter.ActualValue;
    5050      IEnumerable<int> rows = GenerateRowsToEvaluate();
    5151
    52       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     52      double quality = Calculate(
     53        tree, ProblemDataParameter.ActualValue, rows,
     54        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     55        EstimationLimitsParameter.ActualValue.Lower,
     56        EstimationLimitsParameter.ActualValue.Upper);
    5357      QualityParameter.ActualValue = new DoubleValue(quality);
    5458
     
    5660    }
    5761
    58     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows) {
    59       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
     62    public static double Calculate(
     63      ISymbolicExpressionTree tree,
     64      IRegressionProblemData problemData,
     65      IEnumerable<int> rows,
     66      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     67      double lowerEstimationLimit, double upperEstimationLimit) {
     68      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    6069      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    6170      IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     
    7685      EstimationLimitsParameter.ExecutionContext = context;
    7786
    78       double mre = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     87      double mre = Calculate(
     88        tree, problemData, rows,
     89        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     90        EstimationLimitsParameter.ActualValue.Lower,
     91        EstimationLimitsParameter.ActualValue.Upper);
    7992
    8093      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    8497    }
    8598
    86     public override double Evaluate(IRegressionProblemData problemData,
    87       ISymbolicExpressionTree solution,
     99    public override double Evaluate(
     100      ISymbolicExpressionTree tree,
     101      IRegressionProblemData problemData,
     102      IEnumerable<int> rows,
    88103      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    89       IEnumerable<int> rows = null,
    90104      bool applyLinearScaling = true,
    91105      double lowerEstimationLimit = double.MinValue,
    92106      double upperEstimationLimit = double.MaxValue) {
    93       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices);
     107      return Calculate(tree, problemData, rows, interpreter, lowerEstimationLimit, upperEstimationLimit);
    94108    }
    95109  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r18095 r18103  
    3333    protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}
    3434    public abstract double Evaluate(
     35      ISymbolicExpressionTree tree,
    3536      IRegressionProblemData problemData,
    36       ISymbolicExpressionTree tree,
     37      IEnumerable<int> rows,
    3738      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    38       IEnumerable<int> rows = null,
    3939      bool applyLinearScaling = true,
    4040      double lowerEstimationLimit = double.MinValue,
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r18095 r18103  
    4343
    4444    public override IOperation InstrumentedApply() {
    45       var solution = SymbolicExpressionTreeParameter.ActualValue;
     45      var tree = SymbolicExpressionTreeParameter.ActualValue;
    4646      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4747
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     48      double quality = Calculate(
     49        tree, ProblemDataParameter.ActualValue,
     50        rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     51        ApplyLinearScalingParameter.ActualValue.Value,
     52        EstimationLimitsParameter.ActualValue.Lower,
     53        EstimationLimitsParameter.ActualValue.Upper);
    4954      QualityParameter.ActualValue = new DoubleValue(quality);
    5055
     
    5257    }
    5358
    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);
     59    public static double Calculate(
     60      ISymbolicExpressionTree tree,
     61      IRegressionProblemData problemData,
     62      IEnumerable<int> rows,
     63      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     64      bool applyLinearScaling,
     65      double lowerEstimationLimit,
     66      double upperEstimationLimit) {
     67      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    5668      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5769      OnlineCalculatorError errorState;
     
    7688      ApplyLinearScalingParameter.ExecutionContext = context;
    7789
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     90      double mse = Calculate(
     91        tree, problemData, rows,
     92        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     93        ApplyLinearScalingParameter.ActualValue.Value,
     94        EstimationLimitsParameter.ActualValue.Lower,
     95        EstimationLimitsParameter.ActualValue.Upper);
    7996
    8097      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    85102    }
    86103
    87     public override double Evaluate(IRegressionProblemData problemData,
    88       ISymbolicExpressionTree solution,
     104    public override double Evaluate(
     105      ISymbolicExpressionTree tree,
     106      IRegressionProblemData problemData,
     107      IEnumerable<int> rows,
    89108      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    90       IEnumerable<int> rows = null,
    91109      bool applyLinearScaling = true,
    92110      double lowerEstimationLimit = double.MinValue,
    93111      double upperEstimationLimit = double.MaxValue) {
    94       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);
     112      return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit);
    95113    }
    96114  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r18095 r18103  
    4343
    4444    public override IOperation InstrumentedApply() {
    45       var solution = SymbolicExpressionTreeParameter.ActualValue;
     45      var tree = SymbolicExpressionTreeParameter.ActualValue;
    4646      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4747
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     48      double quality = Calculate(tree,
     49        ProblemDataParameter.ActualValue, rows,
     50        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     51        ApplyLinearScalingParameter.ActualValue.Value,
     52        EstimationLimitsParameter.ActualValue.Lower,
     53        EstimationLimitsParameter.ActualValue.Upper);
    4954      QualityParameter.ActualValue = new DoubleValue(quality);
    5055
     
    5257    }
    5358
    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);
     59    public static double Calculate(
     60      ISymbolicExpressionTree tree,
     61      IRegressionProblemData problemData,
     62      IEnumerable<int> rows,
     63      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     64      bool applyLinearScaling,
     65      double lowerEstimationLimit,
     66      double upperEstimationLimit) {
     67      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    5668      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5769      OnlineCalculatorError errorState;
     
    7688      ApplyLinearScalingParameter.ExecutionContext = context;
    7789
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     90      double mse = Calculate(
     91        tree, problemData, rows,
     92        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     93        ApplyLinearScalingParameter.ActualValue.Value,
     94        EstimationLimitsParameter.ActualValue.Lower,
     95        EstimationLimitsParameter.ActualValue.Upper);
    7996
    8097      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    85102    }
    86103
    87     public override double Evaluate(IRegressionProblemData problemData,
    88       ISymbolicExpressionTree solution,
     104    public override double Evaluate(
     105      ISymbolicExpressionTree tree,
     106      IRegressionProblemData problemData,
     107      IEnumerable<int> rows,
    89108      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    90       IEnumerable<int> rows = null,
    91109      bool applyLinearScaling = true,
    92110      double lowerEstimationLimit = double.MinValue,
    93111      double upperEstimationLimit = double.MaxValue) {
    94       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);
     112      return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit);
    95113    }
    96114  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r18095 r18103  
    4343
    4444    public override IOperation InstrumentedApply() {
    45       var solution = SymbolicExpressionTreeParameter.ActualValue;
     45      var tree = SymbolicExpressionTreeParameter.ActualValue;
    4646      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4747
    48       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     48      double quality = Calculate(
     49        tree, ProblemDataParameter.ActualValue,
     50        rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     51        ApplyLinearScalingParameter.ActualValue.Value,         
     52        EstimationLimitsParameter.ActualValue.Lower,
     53        EstimationLimitsParameter.ActualValue.Upper);
    4954      QualityParameter.ActualValue = new DoubleValue(quality);
    5055
     
    5257    }
    5358
    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);
     59    public static double Calculate(
     60      ISymbolicExpressionTree tree,
     61      IRegressionProblemData problemData,
     62      IEnumerable<int> rows,
     63      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     64      bool applyLinearScaling,
     65      double lowerEstimationLimit, double upperEstimationLimit) {
     66      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    5667      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5768      OnlineCalculatorError errorState;
     
    7687      ApplyLinearScalingParameter.ExecutionContext = context;
    7788
    78       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     89      double mse = Calculate(       
     90        tree, problemData, rows,
     91        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     92        ApplyLinearScalingParameter.ActualValue.Value,
     93        EstimationLimitsParameter.ActualValue.Lower,
     94        EstimationLimitsParameter.ActualValue.Upper);
    7995
    8096      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    85101    }
    86102
    87     public override double Evaluate(IRegressionProblemData problemData,
    88       ISymbolicExpressionTree solution,
     103    public override double Evaluate(
     104      ISymbolicExpressionTree tree,
     105      IRegressionProblemData problemData,
     106      IEnumerable<int> rows,
    89107      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    90       IEnumerable<int> rows = null,
    91108      bool applyLinearScaling = true,
    92109      double lowerEstimationLimit = double.MinValue,
    93110      double upperEstimationLimit = double.MaxValue) {
    94       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);
     111      return Calculate(tree, problemData, rows, interpreter, applyLinearScaling, lowerEstimationLimit, upperEstimationLimit);
    95112    }
    96113  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r18095 r18103  
    4848      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4949
    50       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     50      double quality = Calculate(
     51        solution, ProblemDataParameter.ActualValue,
     52        rows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     53        ApplyLinearScalingParameter.ActualValue.Value,
     54        EstimationLimitsParameter.ActualValue.Lower,
     55        EstimationLimitsParameter.ActualValue.Upper);
    5156      QualityParameter.ActualValue = new DoubleValue(quality);
    5257
     
    5459    }
    5560
    56     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    57       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
     61    //TODO: refactor like evaluate method
     62    public static double Calculate(
     63      ISymbolicExpressionTree tree,
     64      IRegressionProblemData problemData,
     65      IEnumerable<int> rows,
     66      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     67      bool applyLinearScaling,
     68      double lowerEstimationLimit,
     69      double upperEstimationLimit) {
     70      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
    5871      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5972      OnlineCalculatorError errorState;
     
    7891      ApplyLinearScalingParameter.ExecutionContext = context;
    7992
    80       double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     93      double r2 = Calculate(
     94         tree, problemData, rows,
     95         SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     96         ApplyLinearScalingParameter.ActualValue.Value,
     97         EstimationLimitsParameter.ActualValue.Lower,
     98         EstimationLimitsParameter.ActualValue.Upper);
    8199
    82100      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    87105    }
    88106
    89     public override double Evaluate(IRegressionProblemData problemData,
    90       ISymbolicExpressionTree solution,
     107    public override double Evaluate(
     108      ISymbolicExpressionTree tree,
     109      IRegressionProblemData problemData,
     110      IEnumerable<int> rows,
    91111      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    92       IEnumerable<int> rows = null,
    93112      bool applyLinearScaling = true,
    94113      double lowerEstimationLimit = double.MinValue,
    95114      double upperEstimationLimit = double.MaxValue) {
    96       return Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows ?? problemData.TrainingIndices, applyLinearScaling);
     115      return Calculate(
     116        tree, problemData, rows,
     117        interpreter, applyLinearScaling,
     118        lowerEstimationLimit, upperEstimationLimit);
    97119    }
    98120  }
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18101 r18103  
    194194      individual[SymbolicExpressionTreeName] = tree;
    195195
     196      if(TreeEvaluatorParameter.Value is SymbolicRegressionConstantOptimizationEvaluator)
     197        TreeEvaluatorParameter.Value.RandomParameter.Value = random;
     198
    196199      return TreeEvaluatorParameter.Value.Evaluate(
    197         ProblemData,
    198         tree,
     200        tree, ProblemData,
     201        ProblemData.TrainingIndices,
    199202        Interpreter,
    200         ProblemData.TrainingIndices,
    201203        StructureTemplate.ApplyLinearScaling,
    202204        EstimationLimits.Lower,
Note: See TracChangeset for help on using the changeset viewer.