Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ArtificialNeuralNetworks/3.2/PredictorBuilder.cs @ 3051

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

Added project for ANN. #751 (Plugin for for data-modeling with ANN (integrated into CEDMA))

File size: 3.9 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.ArtificialNeuralNetworks {
32  public class PredictorBuilder : OperatorBase {
33    public PredictorBuilder()
34      : base() {
35      AddVariableInfo(new VariableInfo("MultiLayerPerceptron", "MultiLayerPerceptron", typeof(MultiLayerPerceptron), VariableKind.In));
36      AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the estimated values to a certain range", typeof(DoubleData), VariableKind.In));
37      AddVariableInfo(new VariableInfo("Dataset", "The dataset", typeof(Dataset), VariableKind.In));
38      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training set", typeof(DoubleData), VariableKind.In));
39      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training set", typeof(DoubleData), VariableKind.In));
40      AddVariableInfo(new VariableInfo("TargetVariable", "Name of the target variable", typeof(StringData), VariableKind.In));
41      AddVariableInfo(new VariableInfo("Predictor", "The predictor combines the function tree and the evaluator and can be used to generate estimated values", typeof(IPredictor), VariableKind.New));
42    }
43
44    public override string Description {
45      get { return "TODO"; }
46    }
47
48    public override IOperation Apply(IScope scope) {
49      MultiLayerPerceptron model = GetVariableValue<MultiLayerPerceptron>("MultiLayerPerceptron", scope, true);
50      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
51      Dataset dataset = GetVariableValue<Dataset>("Dataset", scope, true);
52      int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
53      int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
54      string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
55      IPredictor predictor = CreatePredictor(model, punishmentFactor, dataset, targetVariable, start, end);
56      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor));
57      return null;
58    }
59
60    public static IPredictor CreatePredictor(MultiLayerPerceptron perceptron, double punishmentFactor,
61      Dataset dataset, int targetVariable, int start, int end) {
62      double mean = dataset.GetMean(targetVariable, start, end);
63      double range = dataset.GetRange(targetVariable, start, end);
64      double minEstimatedValue = mean - punishmentFactor * range;
65      double maxEstimatedValue = mean + punishmentFactor * range;
66      return new Predictor(perceptron, minEstimatedValue, maxEstimatedValue);
67    }
68
69    public static IPredictor CreatePredictor(MultiLayerPerceptron perceptron, double punishmentFactor,
70      Dataset dataset, string targetVariable, int start, int end) {
71      return CreatePredictor(perceptron, punishmentFactor, dataset, dataset.GetVariableIndex(targetVariable), start, end);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.