Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2993_UserDefinedEvaluators/HeuristicLab.Problems.DataAnalysis.Symbolic.UserDefinedEval/SymbolicRegressionSingleObjectiveUserDefinedEvaluator.cs @ 17514

Last change on this file since 17514 was 16687, checked in by bburlacu, 6 years ago

#2993: Initial implementation of user-defined evaluators as separate plugin.

File size: 3.1 KB
Line 
1using HEAL.Attic;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Parameters;
6using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
7
8namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
9  [Item("Symbolic regression single-objective user-defined evaluator", "Encapsulates a collection of single-objective evaluators and aggregates their output.")]
10  [StorableType("BCA2D407-576B-4529-8586-A4DFCE117F4C")]
11  public class SymbolicRegressionSingleObjectiveUserDefinedEvaluator : SymbolicDataAnalysisSingleObjectiveUserDefinedEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator {
12    private const string OptimizeConstantsParameterName = "OptimizeConstants";
13    private const string ConstantOptimizationIterationsParameterName = "ConstantOptimizationIterations";
14
15    public IFixedValueParameter<BoolValue> OptimizeConstantsParameter {
16      get { return (IFixedValueParameter<BoolValue>)Parameters[OptimizeConstantsParameterName]; }
17    }
18
19    public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter {
20      get { return (IFixedValueParameter<IntValue>)Parameters[ConstantOptimizationIterationsParameterName]; }
21    }
22
23    public bool OptimizeConstants => OptimizeConstantsParameter.Value.Value;
24
25    public int ConstantOptimizationIterations => ConstantOptimizationIterationsParameter.Value.Value;
26
27    public ILookupParameter<DoubleArray> QualitiesParameter => throw new System.NotImplementedException();
28
29    public SymbolicRegressionSingleObjectiveUserDefinedEvaluator() {
30      Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeConstantsParameterName, new BoolValue(false)));
31      Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, new IntValue(10)));
32    }
33
34    protected SymbolicRegressionSingleObjectiveUserDefinedEvaluator(SymbolicRegressionSingleObjectiveUserDefinedEvaluator original, Cloner cloner) : base(original, cloner) { }
35
36    public override IDeepCloneable Clone(Cloner cloner) {
37      return new SymbolicRegressionSingleObjectiveUserDefinedEvaluator(this, cloner);
38    }
39
40    [StorableConstructor]
41    protected SymbolicRegressionSingleObjectiveUserDefinedEvaluator(StorableConstructorFlag _) : base(_) { }
42
43    public override IOperation InstrumentedApply() {
44      var tree = SymbolicExpressionTreeParameter.ActualValue;
45      var problemData = ProblemDataParameter.ActualValue;
46
47      if (OptimizeConstants) {
48        var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
49        var estimationLimits = EstimationLimitsParameter.ActualValue;
50        var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
51        var iterations = ConstantOptimizationIterations;
52        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, applyLinearScaling, iterations, true, estimationLimits.Lower, estimationLimits.Upper, true);
53      }
54
55      return base.InstrumentedApply();
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.