Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.StructureIdentification/Evaluation/AccuracyEvaluator.cs @ 453

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

fixed a small problem in classification evaluators (#225)

File size: 3.0 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.Operators;
29using HeuristicLab.Functions;
30using HeuristicLab.DataAnalysis;
31
32namespace HeuristicLab.StructureIdentification {
33  public class AccuracyEvaluator : GPEvaluatorBase {
34    public override string Description {
35      get {
36        return @"TASK";
37      }
38    }
39
40    public AccuracyEvaluator()
41      : base() {
42      AddVariableInfo(new VariableInfo("ClassSeparation", "The value of separation between negative and positive target classification values (for instance 0.5 if negative=0 and positive=1).", typeof(DoubleData), VariableKind.In));
43    }
44
45    private double[] original = new double[1];
46    private double[] estimated = new double[1];
47    public override double Evaluate(IScope scope, IFunctionTree functionTree, int targetVariable, Dataset dataset) {
48      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
49      int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
50      int nSamples = trainingEnd-trainingStart;
51      double limit = GetVariableValue<DoubleData>("ClassSeparation", scope, true).Data;
52      double TP = 0;
53      double TN = 0;
54      double targetMean = dataset.GetMean(targetVariable, trainingStart, trainingEnd);
55      for(int sample = trainingStart; sample < trainingEnd; sample++) {
56        double est = evaluator.Evaluate(sample);
57        double orig = dataset.GetValue(sample, targetVariable);
58        if(double.IsNaN(est) || double.IsInfinity(est)) {
59          est = targetMean + maximumPunishment;
60        } else if(est > targetMean + maximumPunishment) {
61          est = targetMean + maximumPunishment;
62        } else if(est < targetMean - maximumPunishment) {
63          est = targetMean - maximumPunishment;
64        }
65        if(orig >= limit && est>=limit) TP++;
66        if(orig < limit && est < limit) TN++;
67      }
68      scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data = totalEvaluatedNodes + treeSize * nSamples;
69      return (TP+TN) / nSamples;
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.