[17621] | 1 | using System.Collections.Generic;
|
---|
| 2 | using HEAL.Attic;
|
---|
| 3 | using HeuristicLab.Common;
|
---|
| 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Data;
|
---|
| 6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 7 |
|
---|
| 8 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
|
---|
| 9 | [Item("Constraint ConstOpt Evaluator", "")]
|
---|
| 10 | [StorableType("4170FD8B-DDD9-43B7-8BF8-F9C7290D4D1C")]
|
---|
| 11 | public class SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
|
---|
| 12 | [StorableConstructor]
|
---|
| 13 | protected SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator(StorableConstructorFlag _) : base(_) { }
|
---|
| 14 |
|
---|
| 15 | protected SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator(
|
---|
| 16 | SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator original, Cloner cloner)
|
---|
| 17 | : base(original, cloner) { }
|
---|
| 18 |
|
---|
| 19 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 20 | return new SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator(this, cloner);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public SymbolicRegressionSingleObjectiveConstraintConstOptEvaluator() { }
|
---|
| 24 |
|
---|
| 25 | public override bool Maximization => true;
|
---|
| 26 |
|
---|
| 27 | public override IOperation InstrumentedApply() {
|
---|
| 28 | var solution = SymbolicExpressionTreeParameter.ActualValue;
|
---|
| 29 | var rows = GenerateRowsToEvaluate();
|
---|
| 30 |
|
---|
| 31 | var quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution,
|
---|
| 32 | EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
|
---|
| 33 | ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
|
---|
| 34 | QualityParameter.ActualValue = new DoubleValue(quality);
|
---|
| 35 | return base.InstrumentedApply();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
|
---|
| 39 | ISymbolicExpressionTree tree, double lowerEstimationLimit,
|
---|
| 40 | double upperEstimationLimit, IRegressionProblemData problemData,
|
---|
| 41 | IEnumerable<int> rows, bool applyLinearScaling) {
|
---|
| 42 | var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
|
---|
| 43 | var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
|
---|
| 44 |
|
---|
| 45 | var constraints = problemData.IntervalConstraints.EnabledConstraints;
|
---|
[17636] | 46 | var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
|
---|
[17621] | 47 |
|
---|
| 48 | if (!SymbolicRegressionConstraintAnalyzer.ConstraintsSatisfied(constraints, variableRanges, tree)) return 0;
|
---|
| 49 |
|
---|
| 50 | var r2 = SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData,
|
---|
| 51 | problemData.TrainingIndices,
|
---|
| 52 | applyLinearScaling, 10);
|
---|
| 53 | return r2;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree,
|
---|
| 57 | IRegressionProblemData problemData, IEnumerable<int> rows) {
|
---|
| 58 | SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
|
---|
| 59 | EstimationLimitsParameter.ExecutionContext = context;
|
---|
| 60 | ApplyLinearScalingParameter.ExecutionContext = context;
|
---|
| 61 |
|
---|
| 62 | var r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree,
|
---|
| 63 | EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
|
---|
| 64 | problemData, rows,
|
---|
| 65 | ApplyLinearScalingParameter.ActualValue.Value);
|
---|
| 66 |
|
---|
| 67 | SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
|
---|
| 68 | EstimationLimitsParameter.ExecutionContext = null;
|
---|
| 69 | ApplyLinearScalingParameter.ExecutionContext = null;
|
---|
| 70 |
|
---|
| 71 | return r2;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | } |
---|