[2319] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Modeling;
|
---|
| 29 | using HeuristicLab.DataAnalysis;
|
---|
| 30 |
|
---|
| 31 | namespace 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));
|
---|
[2421] | 38 | AddVariableInfo(new VariableInfo("InputVariables", "The input variable names", typeof(ItemList), VariableKind.In));
|
---|
[2328] | 39 | AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of the training set", typeof(IntData), VariableKind.In));
|
---|
| 40 | AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of the training set", typeof(IntData), VariableKind.In));
|
---|
[2373] | 41 | AddVariableInfo(new VariableInfo("MaxTimeOffset", "(optional) highest allowed time offset value", typeof(IntData), VariableKind.In));
|
---|
| 42 | AddVariableInfo(new VariableInfo("MinTimeOffset", "(optional) lowest allowed time offset value", typeof(IntData), VariableKind.In));
|
---|
[2328] | 43 | AddVariableInfo(new VariableInfo("PunishmentFactor", "The punishment factor limits the range of predicted values", typeof(DoubleData), VariableKind.In));
|
---|
[2319] | 44 | AddVariableInfo(new VariableInfo("Predictor", "The predictor can be used to generate estimated values", typeof(IPredictor), VariableKind.New));
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public override string Description {
|
---|
| 48 | get { return "Extracts the SVM Model and generates a predictor for the model analyzer."; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public override IOperation Apply(IScope scope) {
|
---|
| 52 | Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true);
|
---|
| 53 | SVMModel model = GetVariableValue<SVMModel>("SVMModel", scope, true);
|
---|
[2440] | 54 | string targetVariable = GetVariableValue<StringData>("TargetVariable", scope, true).Data;
|
---|
[2328] | 55 | int start = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
|
---|
| 56 | int end = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
|
---|
[2373] | 57 | IntData maxTimeOffsetData = GetVariableValue<IntData>("MaxTimeOffset", scope, true, false);
|
---|
| 58 | int maxTimeOffset = maxTimeOffsetData == null ? 0 : maxTimeOffsetData.Data;
|
---|
| 59 | IntData minTimeOffsetData = GetVariableValue<IntData>("MinTimeOffset", scope, true, false);
|
---|
| 60 | int minTimeOffset = minTimeOffsetData == null ? 0 : minTimeOffsetData.Data;
|
---|
[2328] | 61 | double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
|
---|
| 62 |
|
---|
[2440] | 63 |
|
---|
[2319] | 64 | ItemList inputVariables = GetVariableValue<ItemList>("InputVariables", scope, true);
|
---|
[2421] | 65 | var inputVariableNames = from x in inputVariables
|
---|
| 66 | select ((StringData)x).Data;
|
---|
[2319] | 67 |
|
---|
[2328] | 68 | double mean = ds.GetMean(targetVariable, start, end);
|
---|
| 69 | double range = ds.GetRange(targetVariable, start, end);
|
---|
| 70 |
|
---|
[2440] | 71 | Predictor predictor = new Predictor(model, targetVariable, inputVariableNames, minTimeOffset, maxTimeOffset);
|
---|
[2328] | 72 | predictor.LowerPredictionLimit = mean - punishmentFactor * range;
|
---|
| 73 | predictor.UpperPredictionLimit = mean + punishmentFactor * range;
|
---|
| 74 | scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("Predictor"), predictor));
|
---|
[2319] | 75 | return null;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|