Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.Boolean/Evaluator.cs @ 978

Last change on this file since 978 was 730, checked in by gkronber, 16 years ago

fixed bugs in plugin HL.GP.Boolean #340 (Plugin for genetic programming for boolean logic)

File size: 2.8 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.DataAnalysis;
29
30namespace HeuristicLab.GP.Boolean {
31  public class Evaluator : OperatorBase {
32    public Evaluator()
33      : base() {
34      AddVariableInfo(new VariableInfo("FunctionTree", "The function tree representing the ant", typeof(BakedFunctionTree), VariableKind.In));
35      AddVariableInfo(new VariableInfo("Dataset", "The boolean dataset (values 0.0 = false, 1.0=true)", typeof(Dataset), VariableKind.In));
36      AddVariableInfo(new VariableInfo("TargetVariable", "Index of the column of the dataset that holds the target variable", typeof(IntData), VariableKind.In));
37      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
38      AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
39      AddVariableInfo(new VariableInfo("Errors", "", typeof(DoubleData), VariableKind.New | VariableKind.Out));
40    }
41
42    public override IOperation Apply(IScope scope) {
43      BakedFunctionTree tree = GetVariableValue<BakedFunctionTree>("FunctionTree", scope, true);
44      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
45      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
46      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
47      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
48
49      BooleanTreeInterpreter interpreter = new BooleanTreeInterpreter();
50      interpreter.Reset(dataset, tree, targetVariable);
51      int errors = interpreter.GetNumberOfErrors(start, end);
52
53      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Errors"), new DoubleData(errors)));
54      return null;
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.