1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | *
|
---|
20 | * Author: Sabine Winkler
|
---|
21 | */
|
---|
22 |
|
---|
23 | #endregion
|
---|
24 |
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HEAL.Attic;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis;
|
---|
31 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.GrammaticalEvolution {
|
---|
34 | [StorableType("85880E49-DE2F-4FB4-8C1E-F1C51D862FDF")]
|
---|
35 | public class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>,
|
---|
36 | IGESymbolicRegressionSingleObjectiveEvaluator {
|
---|
37 |
|
---|
38 | public const string EvaluatorParameterName = "Evaluator";
|
---|
39 | public const string RandomParameterName = "Random";
|
---|
40 | public const string BoundsParameterName = "Bounds";
|
---|
41 | public const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
42 |
|
---|
43 | public IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
|
---|
44 | get { return (IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
|
---|
45 | }
|
---|
46 | public ILookupParameter<IntMatrix> BoundsParameter {
|
---|
47 | get { return (ILookupParameter<IntMatrix>)Parameters[BoundsParameterName]; }
|
---|
48 | }
|
---|
49 | public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
|
---|
50 | get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ISymbolicRegressionSingleObjectiveEvaluator Evaluator {
|
---|
54 | get { return EvaluatorParameter.Value; }
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | [StorableConstructor]
|
---|
59 | protected GESymbolicRegressionSingleObjectiveEvaluator(StorableConstructorFlag _) : base(_) { }
|
---|
60 | protected GESymbolicRegressionSingleObjectiveEvaluator(GESymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
61 | public GESymbolicRegressionSingleObjectiveEvaluator()
|
---|
62 | : base() {
|
---|
63 | Parameters.Add(new ValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName, "The symbolic regression evaluator that should be used to assess the quality of trees.", new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator()));
|
---|
64 | Parameters.Add(new LookupParameter<IntMatrix>(BoundsParameterName, "The integer number range in which the single genomes of a genotype are created."));
|
---|
65 | Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Genotype length."));
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
69 | return new GESymbolicRegressionSingleObjectiveEvaluator(this, cloner);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override bool Maximization {
|
---|
73 | get { return Evaluator.Maximization; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override IOperation Apply() {
|
---|
77 | var genotype = IntegerVectorParameter.ActualValue;
|
---|
78 |
|
---|
79 | // translate to phenotype
|
---|
80 | var tree = GenotypeToPhenotypeMapperParameter.ActualValue.Map(
|
---|
81 | RandomParameter.ActualValue,
|
---|
82 | BoundsParameter.ActualValue,
|
---|
83 | MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value,
|
---|
84 | SymbolicExpressionTreeGrammarParameter.ActualValue,
|
---|
85 | genotype
|
---|
86 | );
|
---|
87 | SymbolicExpressionTreeParameter.ActualValue = tree; // write to scope for analyzers
|
---|
88 |
|
---|
89 | // create operation for evaluation
|
---|
90 | var evalOp = ExecutionContext.CreateChildOperation(Evaluator);
|
---|
91 | var successorOp = base.Apply();
|
---|
92 |
|
---|
93 | return new OperationCollection(evalOp, successorOp);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|