Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleGPEvaluatorBase.cs @ 2212

Last change on this file since 2212 was 2212, checked in by gkronber, 15 years ago

GP Refactoring: #713

  • added project GP.Operators
  • moved operators from plugin GP to plugin GP.Operators
  • deleted unused constraints
  • removed dependency of GP plugins on Constraints plugin
  • moved StructID functions into directory Symbols
  • deleted unused class FunView
  • implemented add and remove functionality for the FunctionLibraryView
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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#endregion
21
22using HeuristicLab.Core;
23using HeuristicLab.Data;
24using HeuristicLab.DataAnalysis;
25
26namespace HeuristicLab.GP.StructureIdentification {
27  public abstract class SimpleGPEvaluatorBase : GPEvaluatorBase {
28    public virtual string OutputVariableName { get { return "Quality"; } }
29
30    public SimpleGPEvaluatorBase()
31      : base() {
32      AddVariableInfo(new VariableInfo(OutputVariableName, OutputVariableName, typeof(DoubleData), VariableKind.New | VariableKind.Out));
33    }
34
35    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
36      // store original and estimated values in a double array
37      double[,] values = new double[end - start, 2];
38      for (int sample = start; sample < end; sample++) {
39        double original = dataset.GetValue(sample, targetVariable);
40        double estimated = evaluator.Evaluate(sample);
41        if (updateTargetValues) {
42          dataset.SetValue(sample, targetVariable, estimated);
43        }
44        values[sample - start, 0] = estimated;
45        values[sample - start, 1] = original;
46      }
47
48      double quality = Evaluate(values);
49
50      DoubleData qualityData = GetVariableValue<DoubleData>(OutputVariableName, scope, false, false);
51      if (qualityData == null) {
52        qualityData = new DoubleData();
53        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OutputVariableName), qualityData));
54      }
55
56      qualityData.Data = quality;
57
58    }
59
60    public abstract double Evaluate(double[,] values);
61  }
62}
Note: See TracBrowser for help on using the repository browser.