Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.GrammaticalEvolution/3.3/Symbolic/GESymbolicRegressionSingleObjectiveEvaluator.cs @ 12204

Last change on this file since 12204 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

File size: 4.3 KB
RevLine 
[10072]1#region License Information
2/* HeuristicLab
[12009]3 * Copyright (C) 2002-2015 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
25using HeuristicLab.Common;
[10263]26using HeuristicLab.Core;
[10290]27using HeuristicLab.Data;
[10263]28using HeuristicLab.Parameters;
[10072]29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[10073]30using HeuristicLab.Problems.DataAnalysis;
31using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
32
33namespace 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}
Note: See TracBrowser for help on using the repository browser.