#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.GP.StructureIdentification; using HeuristicLab.DataAnalysis; namespace HeuristicLab.GP.StructureIdentification.Classification { public abstract class GPClassificationEvaluatorBase : GPEvaluatorBase { public GPClassificationEvaluatorBase() : base() { AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList), VariableKind.In)); } public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) { ItemList classes = GetVariableValue>("TargetClassValues", scope, true); double[] classesArr = new double[classes.Count]; for(int i = 0; i < classesArr.Length; i++) classesArr[i] = classes[i].Data; Array.Sort(classesArr); double[] thresholds = new double[classes.Count - 1]; for(int i = 0; i < classesArr.Length - 1; i++) { thresholds[i] = (classesArr[i] + classesArr[i + 1]) / 2.0; } Evaluate(scope, evaluator, dataset, targetVariable, classesArr, thresholds, start, end); } public abstract void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, double[] classes, double[] thresholds, int start, int end); } }