Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling/3.2/TargetClassesCalculator.cs @ 3215

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

Fixed #784 (ProblemInjector should be changed to read variable names instead of indexes for input and target variables)

File size: 2.1 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 HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.DataAnalysis;
26using System.Linq;
27
28namespace HeuristicLab.Modeling {
29  public class TargetClassesCalculator : OperatorBase {
30
31    public TargetClassesCalculator()
32      : base() {
33      AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In));
34      AddVariableInfo(new VariableInfo("TargetVariable", "Name the target variable", typeof(StringData), VariableKind.In));
35      AddVariableInfo(new VariableInfo("TargetClassValues", "The original class values of target variable (for instance negative=0 and positive=1).", typeof(ItemList<DoubleData>), VariableKind.New));
36    }
37
38    public override IOperation Apply(IScope scope) {
39      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
40      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
41
42      ItemList<DoubleData> classes = new ItemList<DoubleData>();
43      foreach (double x in dataset.GetVariableValues(targetVariable).Distinct().OrderBy(v => v)) {
44        classes.Add(new DoubleData(x));
45      }
46
47      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TargetClassValues"), classes));
48      return null;
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.