Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SupportVectorMachines/3.2/PredictorBuilder.cs @ 2319

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

Applied patch from mkommend for variable impact calculators and adapted data-modeling algorithms to use the new operators for variable impact calculation. #728

File size: 2.7 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.Modeling;
29using HeuristicLab.DataAnalysis;
30
31namespace HeuristicLab.SupportVectorMachines {
32  public class PredictorBuilder : OperatorBase {
33    public PredictorBuilder()
34      : base() {
35      AddVariableInfo(new VariableInfo("Dataset", "The input dataset", typeof(Dataset), VariableKind.In));
36      AddVariableInfo(new VariableInfo("SVMModel", "The SVM model", typeof(SVMModel), VariableKind.In));
37      AddVariableInfo(new VariableInfo("TargetVariable", "The target variable", typeof(StringData), VariableKind.In));
38      AddVariableInfo(new VariableInfo("InputVariables", "The input variable names", typeof(StringData), VariableKind.In));
39      AddVariableInfo(new VariableInfo("Predictor", "The predictor can be used to generate estimated values", typeof(IPredictor), VariableKind.New));
40    }
41
42    public override string Description {
43      get { return "Extracts the SVM Model and generates a predictor for the model analyzer."; }
44    }
45
46    public override IOperation Apply(IScope scope) {
47      Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true);
48      SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
49      int targetVariable = GetVariableValue<IntData>("TargetVariable", scope, true).Data;
50      string targetVariableName = ds.GetVariableName(targetVariable);
51      ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true);
52      Dictionary<string, int> variableNames = new Dictionary<string, int>();
53      for (int i = 0; i < ds.Columns; i++) variableNames[ds.GetVariableName(i)] = i;
54
55      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), new Predictor(model, targetVariableName, variableNames)));
56      return null;
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.