Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18081


Ignore:
Timestamp:
11/12/21 17:10:22 (2 years ago)
Author:
dpiringe
Message:

#3136

  • changed the visibility of the following parameters: EstimationLimitsParameter, EvaluatorParameter and BestTrainingSolutionParameter
  • added first steps to set an evaluator as parameter
    • added a new parameter TreeEvaluatorParameter
    • added a temporary logic to static evaluator method Calculate
    • tried to change a lot of necessary parameters to use the method Evaluate, this caused a lot of problems -> reverted all changes
File:
1 edited

Legend:

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

    r18076 r18081  
    2121
    2222    #region Constants
     23    private const string TreeEvaluatorParameterName = "TreeEvaluator";
    2324    private const string ProblemDataParameterName = "ProblemData";
    2425    private const string StructureTemplateParameterName = "Structure Template";
     
    3738
    3839    #region Parameters
     40    public IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator> TreeEvaluatorParameter => (IConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator>)Parameters[TreeEvaluatorParameterName];
    3941    public IValueParameter<IRegressionProblemData> ProblemDataParameter => (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName];
    4042    public IFixedValueParameter<StructureTemplate> StructureTemplateParameter => (IFixedValueParameter<StructureTemplate>)Parameters[StructureTemplateParameterName];
     
    4547
    4648    #region Properties
     49
    4750    public IRegressionProblemData ProblemData {
    4851      get => ProblemDataParameter.Value;
     
    6265    public DoubleLimit EstimationLimits => EstimationLimitsParameter.Value;
    6366
    64     public override bool Maximization => true;
     67    public override bool Maximization => false;
    6568    #endregion
    6669
     
    7982      structureTemplate.Changed += OnTemplateChanged;
    8083
     84      var evaluators = new ItemSet<SymbolicRegressionSingleObjectiveEvaluator>(
     85        ApplicationManager.Manager.GetInstances<SymbolicRegressionSingleObjectiveEvaluator>()
     86        .Where(x => x.Maximization == Maximization));
     87
     88      Parameters.Add(new ConstrainedValueParameter<SymbolicRegressionSingleObjectiveEvaluator>(
     89        TreeEvaluatorParameterName,
     90        evaluators,
     91        evaluators.First()));
     92
    8193      Parameters.Add(new ValueParameter<IRegressionProblemData>(
    8294        ProblemDataParameterName,
    8395        problemData));
     96      ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged;
     97
    8498      Parameters.Add(new FixedValueParameter<StructureTemplate>(
    8599        StructureTemplateParameterName,
    86100        StructureTemplateDescriptionText,
    87101        structureTemplate));
     102     
    88103      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(
    89104        InterpreterParameterName,
    90105        new SymbolicDataAnalysisExpressionTreeInterpreter()) { Hidden = true });
     106     
    91107      Parameters.Add(new FixedValueParameter<DoubleLimit>(
    92108        EstimationLimitsParameterName,
    93109        new DoubleLimit(targetInterval.LowerBound - estimationWidth, targetInterval.UpperBound + estimationWidth)));
     110      EstimationLimitsParameter.Hidden = true;
     111
    94112      Parameters.Add(new ResultParameter<ISymbolicRegressionSolution>(BestTrainingSolutionParameterName, ""));
    95 
    96       ProblemDataParameter.ValueChanged += ProblemDataParameterValueChanged;
     113      this.BestTrainingSolutionParameter.Hidden = true;
     114
     115      this.EvaluatorParameter.Hidden = true;
     116
     117     
    97118
    98119      Operators.Add(new SymbolicDataAnalysisVariableFrequencyAnalyzer());
     
    167188      individual[SymbolicExpressionTreeName] = tree;
    168189
    169       var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(
     190      //TreeEvaluatorParameter.Value.EstimationLimitsParameter.ActualValue = EstimationLimits;
     191      //TreeEvaluatorParameter.Value.EstimationLimitsParameter.Value = EstimationLimits;
     192      //var quality = TreeEvaluatorParameter.Value.Evaluate(new ExecutionContext(null, this, new Scope("Test")), tree, ProblemData, ProblemData.TrainingIndices);
     193
     194      var quality = double.MaxValue;
     195      var evaluatorGUID = TreeEvaluatorParameter.Value.GetType().GUID;
     196
     197      // TODO: use Evaluate method instead of static Calculate -> a fake ExecutionContext is needed
     198      if (evaluatorGUID == typeof(NMSESingleObjectiveConstraintsEvaluator).GUID) {
     199        quality = NMSESingleObjectiveConstraintsEvaluator.Calculate(
     200        Interpreter, tree,
     201        EstimationLimits.Lower, EstimationLimits.Upper,
     202        ProblemData, ProblemData.TrainingIndices, new IntervalArithBoundsEstimator());
     203      } else if (evaluatorGUID == typeof(SymbolicRegressionLogResidualEvaluator).GUID) {
     204        quality = SymbolicRegressionLogResidualEvaluator.Calculate(
     205        Interpreter, tree,
     206        EstimationLimits.Lower, EstimationLimits.Upper,
     207        ProblemData, ProblemData.TrainingIndices);
     208      } else if (evaluatorGUID == typeof(SymbolicRegressionMeanRelativeErrorEvaluator).GUID) {
     209        quality = SymbolicRegressionMeanRelativeErrorEvaluator.Calculate(
     210        Interpreter, tree,
     211        EstimationLimits.Lower, EstimationLimits.Upper,
     212        ProblemData, ProblemData.TrainingIndices);
     213      } else if (evaluatorGUID == typeof(SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator).GUID) {
     214        quality = SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.Calculate(
    170215        Interpreter, tree,
    171216        EstimationLimits.Lower, EstimationLimits.Upper,
    172217        ProblemData, ProblemData.TrainingIndices, false);
    173 
     218      } else if (evaluatorGUID == typeof(SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator).GUID) {
     219        quality = SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.Calculate(
     220        Interpreter, tree,
     221        EstimationLimits.Lower, EstimationLimits.Upper,
     222        ProblemData, ProblemData.TrainingIndices, false);
     223      } else { // SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator
     224        quality = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(
     225        Interpreter, tree,
     226        EstimationLimits.Lower, EstimationLimits.Upper,
     227        ProblemData, ProblemData.TrainingIndices, false);
     228      }
     229   
    174230      return quality;
    175231    }
Note: See TracChangeset for help on using the changeset viewer.