Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/24/22 20:33:45 (12 months ago)
Author:
gkronber
Message:

#3136: reintegrated structure-template GP branch into trunk

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionParameterOptimizationEvaluator.cs

    r18132 r18220  
    197197          Parameters.Add(new FixedValueParameter<PercentValue>(ParameterOptimizationRowsPercentageParameterName, "Determines the percentage of the rows which should be used for parameter optimization", new PercentValue(1)));
    198198        }
    199        
     199
    200200      }
    201201    }
     
    203203    private static readonly object locker = new object();
    204204    public override IOperation InstrumentedApply() {
    205       var solution = SymbolicExpressionTreeParameter.ActualValue;
     205      var tree = SymbolicExpressionTreeParameter.ActualValue;
    206206      double quality;
    207207      if (RandomParameter.ActualValue.NextDouble() < ParameterOptimizationProbability.Value) {
    208208        IEnumerable<int> parameterOptimizationRows = GenerateRowsToEvaluate(ParameterOptimizationRowsPercentage.Value);
    209209        var counter = new EvaluationsCounter();
    210         quality = OptimizeParameters(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue,
     210        quality = OptimizeParameters(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, ProblemDataParameter.ActualValue,
    211211           parameterOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ParameterOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateParametersInTree: UpdateParametersInTree, counter: counter);
    212212
    213213        if (ParameterOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
    214214          var evaluationRows = GenerateRowsToEvaluate();
    215           quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
     215          quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     216            tree, ProblemDataParameter.ActualValue,
     217            evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     218            ApplyLinearScalingParameter.ActualValue.Value,
     219            EstimationLimitsParameter.ActualValue.Lower,
     220            EstimationLimitsParameter.ActualValue.Upper);
    216221        }
    217222
     
    225230      } else {
    226231        var evaluationRows = GenerateRowsToEvaluate();
    227         quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
     232        quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     233          tree, ProblemDataParameter.ActualValue,
     234          evaluationRows, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     235          ApplyLinearScalingParameter.ActualValue.Value,
     236          EstimationLimitsParameter.ActualValue.Lower,
     237          EstimationLimitsParameter.ActualValue.Upper);
    228238      }
    229239      QualityParameter.ActualValue = new DoubleValue(quality);
    230240
    231241      return base.InstrumentedApply();
     242    }
     243
     244    public override double Evaluate(
     245      ISymbolicExpressionTree tree,
     246      IRegressionProblemData problemData,
     247      IEnumerable<int> rows,
     248      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     249      bool applyLinearScaling = true,
     250      double lowerEstimationLimit = double.MinValue,
     251      double upperEstimationLimit = double.MaxValue) {
     252
     253      var random = RandomParameter.ActualValue;
     254      double quality = double.NaN;
     255
     256      var propability = random.NextDouble();
     257      if (propability < ParameterOptimizationProbability.Value) {
     258        quality = OptimizeParameters(
     259          interpreter, tree,
     260          problemData, rows,
     261          applyLinearScaling,
     262          ParameterOptimizationIterations.Value,
     263          updateVariableWeights: UpdateVariableWeights,
     264          lowerEstimationLimit: lowerEstimationLimit,
     265          upperEstimationLimit: upperEstimationLimit,
     266          updateParametersInTree: UpdateParametersInTree);
     267      }
     268      if (double.IsNaN(quality) || ParameterOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
     269        quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     270          tree, problemData,
     271          rows, interpreter,
     272          applyLinearScaling,
     273          lowerEstimationLimit,
     274          upperEstimationLimit);
     275      }
     276      return quality;
    232277    }
    233278
     
    242287      // because Evaluate() is used to get the quality of evolved models on
    243288      // 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);
     289      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     290        tree, problemData, rows,
     291        SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     292        ApplyLinearScalingParameter.ActualValue.Value,
     293        EstimationLimitsParameter.ActualValue.Lower,
     294        EstimationLimitsParameter.ActualValue.Upper);
    245295
    246296      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
     
    290340      }
    291341
    292       double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     342      double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     343        tree, problemData, rows,
     344        interpreter, applyLinearScaling,
     345        lowerEstimationLimit,
     346        upperEstimationLimit);
    293347
    294348      if (counter == null) counter = new EvaluationsCounter();
     
    348402        } else UpdateParameters(tree, c, updateVariableWeights);
    349403      }
    350       var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     404      var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     405        tree, problemData, rows,
     406        interpreter, applyLinearScaling,
     407        lowerEstimationLimit, upperEstimationLimit);
    351408
    352409      if (!updateParametersInTree) UpdateParameters(tree, initialParameters, updateVariableWeights);
     
    366423        FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode;
    367424        if (numberTreeNode != null) {
    368           if (numberTreeNode.Parent.Symbol is Power 
     425          if (numberTreeNode.Parent.Symbol is Power
    369426              && numberTreeNode.Parent.GetSubtree(1) == numberTreeNode) continue; // exponents in powers are not optimizated (see TreeToAutoDiffTermConverter)
    370427          numberTreeNode.Value = parameters[i++];
Note: See TracChangeset for help on using the changeset viewer.