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