[10072] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10072] | 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/>.
|
---|
[10968] | 19 | *
|
---|
| 20 | * Author: Sabine Winkler
|
---|
[10072] | 21 | */
|
---|
[10968] | 22 |
|
---|
[10072] | 23 | #endregion
|
---|
| 24 |
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[10263] | 26 | using HeuristicLab.Core;
|
---|
[10290] | 27 | using HeuristicLab.Data;
|
---|
[10263] | 28 | using HeuristicLab.Parameters;
|
---|
[10072] | 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[10073] | 30 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 31 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.GrammaticalEvolution {
|
---|
[10072] | 34 | [StorableClass]
|
---|
[10263] | 35 | public class GESymbolicRegressionSingleObjectiveEvaluator : GESymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>,
|
---|
[10276] | 36 | IGESymbolicRegressionSingleObjectiveEvaluator {
|
---|
[10263] | 37 |
|
---|
| 38 | public const string EvaluatorParameterName = "Evaluator";
|
---|
[10280] | 39 | public const string RandomParameterName = "Random";
|
---|
[10290] | 40 | public const string BoundsParameterName = "Bounds";
|
---|
| 41 | public const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
[10280] | 42 |
|
---|
[10263] | 43 | public IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
|
---|
| 44 | get { return (IValueParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
|
---|
| 45 | }
|
---|
[10290] | 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 | }
|
---|
[10263] | 52 |
|
---|
[10974] | 53 | public ISymbolicRegressionSingleObjectiveEvaluator Evaluator {
|
---|
[10263] | 54 | get { return EvaluatorParameter.Value; }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[10280] | 57 |
|
---|
[10072] | 58 | [StorableConstructor]
|
---|
[10073] | 59 | protected GESymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
|
---|
| 60 | protected GESymbolicRegressionSingleObjectiveEvaluator(GESymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
|
---|
[10263] | 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()));
|
---|
[10290] | 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."));
|
---|
[10263] | 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(
|
---|
[10280] | 81 | RandomParameter.ActualValue,
|
---|
[10290] | 82 | BoundsParameter.ActualValue,
|
---|
| 83 | MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value,
|
---|
[10263] | 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 | }
|
---|
[10072] | 95 | }
|
---|
| 96 | }
|
---|