Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.SupportVectorMachines/3.2/SupportVectorRegression.cs @ 2349

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

Created a subclass for time-series prognosis with SVM and created a simple version of TheilInequalityCoefficientEvaluator in HL.Modeling. (#705)

File size: 23.6 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 System.Xml;
28using System.Diagnostics;
29using HeuristicLab.DataAnalysis;
30using HeuristicLab.Data;
31using HeuristicLab.Operators;
32using HeuristicLab.Logging;
33using HeuristicLab.Operators.Programmable;
34using HeuristicLab.Modeling;
35using HeuristicLab.Random;
36using HeuristicLab.Selection;
37
38namespace HeuristicLab.SupportVectorMachines {
39  public class SupportVectorRegression : ItemBase, IEditable, IAlgorithm {
40
41    public virtual string Name { get { return "SupportVectorRegression"; } }
42    public virtual string Description { get { return "TODO"; } }
43
44    private SequentialEngine.SequentialEngine engine;
45    public IEngine Engine {
46      get { return engine; }
47    }
48
49    public Dataset Dataset {
50      get { return ProblemInjector.GetVariableValue<Dataset>("Dataset", null, false); }
51      set { ProblemInjector.GetVariable("Dataset").Value = value; }
52    }
53
54    public int TargetVariable {
55      get { return ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data; }
56      set { ProblemInjector.GetVariableValue<IntData>("TargetVariable", null, false).Data = value; }
57    }
58
59    public IOperator ProblemInjector {
60      get {
61        IOperator main = GetMainOperator();
62        return main.SubOperators[0].SubOperators[1];
63      }
64      set {
65        IOperator main = GetMainOperator();
66        main.RemoveSubOperator(1);
67        main.AddSubOperator(value, 1);
68      }
69    }
70
71    public IAnalyzerModel Model {
72      get {
73        if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result.");
74        IScope bestModelScope = engine.GlobalScope.SubScopes[0];
75        return CreateSVMModel(bestModelScope);
76      }
77    }
78
79    public DoubleArrayData NuList {
80      get { return GetVariableInjector().GetVariable("NuList").GetValue<DoubleArrayData>(); }
81      set { GetVariableInjector().GetVariable("NuList").Value = value; }
82    }
83
84    public int MaxNuIndex {
85      get { return GetVariableInjector().GetVariable("MaxNuIndex").GetValue<IntData>().Data; }
86      set { GetVariableInjector().GetVariable("MaxNuIndex").GetValue<IntData>().Data = value; }
87    }
88
89    public DoubleArrayData CostList {
90      get { return GetVariableInjector().GetVariable("CostList").GetValue<DoubleArrayData>(); }
91      set { GetVariableInjector().GetVariable("CostList").Value = value; }
92    }
93
94    public int MaxCostIndex {
95      get { return GetVariableInjector().GetVariable("MaxCostIndex").GetValue<IntData>().Data; }
96      set { GetVariableInjector().GetVariable("MaxCostIndex").GetValue<IntData>().Data = value; }
97    }
98
99    public DoubleArrayData GammaList {
100      get { return GetVariableInjector().GetVariable("GammaList").GetValue<DoubleArrayData>(); }
101      set { GetVariableInjector().GetVariable("GammaList").Value = value; }
102    }
103
104    public int MaxGammaIndex {
105      get { return GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data; }
106      set { GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data = value; }
107    }
108
109    public SupportVectorRegression() {
110      engine = new SequentialEngine.SequentialEngine();
111      CombinedOperator algo = CreateAlgorithm();
112      engine.OperatorGraph.AddOperator(algo);
113      engine.OperatorGraph.InitialOperator = algo;
114      MaxCostIndex = CostList.Data.Length;
115      MaxNuIndex = NuList.Data.Length;
116      MaxGammaIndex = GammaList.Data.Length;
117    }
118
119    private CombinedOperator CreateAlgorithm() {
120      CombinedOperator algo = new CombinedOperator();
121      SequentialProcessor seq = new SequentialProcessor();
122      algo.Name = "SupportVectorRegression";
123      seq.Name = "SupportVectorRegression";
124
125      IOperator initialization = CreateInitialization();
126      IOperator main = CreateMainLoop();
127      IOperator postProc = CreateModelAnalyser();
128
129      seq.AddSubOperator(initialization);
130      seq.AddSubOperator(main);
131      seq.AddSubOperator(postProc);
132
133      algo.OperatorGraph.InitialOperator = seq;
134      algo.OperatorGraph.AddOperator(seq);
135
136      return algo;
137    }
138
139    protected virtual IOperator CreateInitialization() {
140      SequentialProcessor seq = new SequentialProcessor();
141      seq.Name = "Initialization";
142      seq.AddSubOperator(CreateGlobalInjector());
143      ProblemInjector probInjector = new ProblemInjector();
144      probInjector.GetVariableInfo("MaxNumberOfTrainingSamples").Local = true;
145      probInjector.AddVariable(new Variable("MaxNumberOfTrainingSamples", new IntData(1000)));
146      seq.AddSubOperator(probInjector);
147      seq.AddSubOperator(new RandomInjector());
148
149      DatasetShuffler shuffler = new DatasetShuffler();
150      shuffler.GetVariableInfo("ShuffleStart").ActualName = "TrainingSamplesStart";
151      shuffler.GetVariableInfo("ShuffleEnd").ActualName = "TrainingSamplesEnd";
152      seq.AddSubOperator(shuffler);
153      return seq;
154    }
155
156    private IOperator CreateMainLoop() {
157      SequentialProcessor main = new SequentialProcessor();
158      main.Name = "Main";
159      #region initial solution
160      SubScopesCreater modelScopeCreator = new SubScopesCreater();
161      modelScopeCreator.GetVariableInfo("SubScopes").Local = true;
162      modelScopeCreator.AddVariable(new HeuristicLab.Core.Variable("SubScopes", new IntData(1)));
163      main.AddSubOperator(modelScopeCreator);
164
165      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
166      IOperator modelProcessor = CreateModelProcessor();
167
168      seqSubScopesProc.AddSubOperator(modelProcessor);
169      main.AddSubOperator(seqSubScopesProc);
170      #endregion
171
172      SequentialProcessor nuLoop = new SequentialProcessor();
173      nuLoop.Name = "NuLoop";
174
175      SequentialProcessor gammaLoop = new SequentialProcessor();
176      gammaLoop.Name = "GammaLoop";
177
178      nuLoop.AddSubOperator(gammaLoop);
179
180      IOperator costCounter = CreateCounter("Cost");
181      IOperator costComparator = CreateComparator("Cost");
182      gammaLoop.AddSubOperator(costCounter);
183      gammaLoop.AddSubOperator(costComparator);
184
185      ConditionalBranch costBranch = new ConditionalBranch();
186      costBranch.Name = "IfValidCostIndex";
187      costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
188
189      // build cost loop
190      SequentialProcessor costLoop = new SequentialProcessor();
191      costLoop.Name = "CostLoop";
192
193      #region selection of better solution
194      costLoop.AddSubOperator(modelScopeCreator);
195      SequentialSubScopesProcessor subScopesProcessor = new SequentialSubScopesProcessor();
196      costLoop.AddSubOperator(subScopesProcessor);
197      subScopesProcessor.AddSubOperator(new EmptyOperator());
198      subScopesProcessor.AddSubOperator(modelProcessor);
199
200      Sorter sorter = new Sorter();
201      sorter.GetVariableInfo("Value").ActualName = "ValidationQuality";
202      sorter.GetVariableInfo("Descending").Local = true;
203      sorter.AddVariable(new Variable("Descending", new BoolData(false)));
204      costLoop.AddSubOperator(sorter);
205
206      LeftSelector selector = new LeftSelector();
207      selector.GetVariableInfo("Selected").Local = true;
208      selector.AddVariable(new Variable("Selected", new IntData(1)));
209      costLoop.AddSubOperator(selector);
210
211      RightReducer reducer = new RightReducer();
212      costLoop.AddSubOperator(reducer);
213      #endregion
214
215      costLoop.AddSubOperator(costCounter);
216      costLoop.AddSubOperator(costComparator);
217
218      costBranch.AddSubOperator(costLoop);
219      costLoop.AddSubOperator(costBranch);
220
221      gammaLoop.AddSubOperator(costBranch); // inner loop
222      gammaLoop.AddSubOperator(CreateResetOperator("CostIndex", -1));
223      gammaLoop.AddSubOperator(CreateCounter("Gamma"));
224      gammaLoop.AddSubOperator(CreateComparator("Gamma"));
225
226      ConditionalBranch gammaBranch = new ConditionalBranch();
227      gammaBranch.Name = "GammaLoop";
228      gammaBranch.GetVariableInfo("Condition").ActualName = "RepeatGammaLoop";
229      gammaBranch.AddSubOperator(gammaLoop);
230      gammaLoop.AddSubOperator(gammaBranch);
231
232      nuLoop.AddSubOperator(CreateResetOperator("GammaIndex", 0));
233
234      nuLoop.AddSubOperator(CreateCounter("Nu"));
235      nuLoop.AddSubOperator(CreateComparator("Nu"));
236
237      ConditionalBranch nuBranch = new ConditionalBranch();
238      nuBranch.Name = "NuLoop";
239      nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
240
241      nuBranch.AddSubOperator(nuLoop);
242      nuLoop.AddSubOperator(nuBranch);
243
244      main.AddSubOperator(nuLoop);
245      return main;
246    }
247
248    private IOperator CreateModelProcessor() {
249      SequentialProcessor modelProcessor = new SequentialProcessor();
250      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Nu"));
251      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Cost"));
252      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Gamma"));
253
254      SupportVectorCreator modelCreator = new SupportVectorCreator();
255      modelCreator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
256      modelCreator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
257      modelCreator.GetVariableInfo("SVMCost").ActualName = "Cost";
258      modelCreator.GetVariableInfo("SVMGamma").ActualName = "Gamma";
259      modelCreator.GetVariableInfo("SVMKernelType").ActualName = "KernelType";
260      modelCreator.GetVariableInfo("SVMModel").ActualName = "Model";
261      modelCreator.GetVariableInfo("SVMNu").ActualName = "Nu";
262      modelCreator.GetVariableInfo("SVMType").ActualName = "Type";
263
264      modelProcessor.AddSubOperator(modelCreator);
265      CombinedOperator trainingEvaluator = (CombinedOperator)CreateEvaluator("ActualTraining");
266      trainingEvaluator.OperatorGraph.InitialOperator.SubOperators[1].GetVariableInfo("MSE").ActualName = "Quality";
267      modelProcessor.AddSubOperator(trainingEvaluator);
268      modelProcessor.AddSubOperator(CreateEvaluator("Validation"));
269
270      DataCollector collector = new DataCollector();
271      collector.GetVariableInfo("Values").ActualName = "Log";
272      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Nu"));
273      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Cost"));
274      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Gamma"));
275      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
276      modelProcessor.AddSubOperator(collector);
277      return modelProcessor;
278    }
279
280    private IOperator CreateComparator(string p) {
281      LessThanComparator comparator = new LessThanComparator();
282      comparator.Name = p + "IndexComparator";
283      comparator.GetVariableInfo("LeftSide").ActualName = p + "Index";
284      comparator.GetVariableInfo("RightSide").ActualName = "Max" + p + "Index";
285      comparator.GetVariableInfo("Result").ActualName = "Repeat" + p + "Loop";
286      return comparator;
287    }
288
289    private IOperator CreateCounter(string p) {
290      Counter c = new Counter();
291      c.GetVariableInfo("Value").ActualName = p + "Index";
292      c.Name = p + "Counter";
293      return c;
294    }
295
296    protected virtual IOperator CreateEvaluator(string p) {
297      CombinedOperator op = new CombinedOperator();
298      op.Name = p + "Evaluator";
299      SequentialProcessor seqProc = new SequentialProcessor();
300
301      SupportVectorEvaluator evaluator = new SupportVectorEvaluator();
302      evaluator.Name = p + "SimpleEvaluator";
303      evaluator.GetVariableInfo("SVMModel").ActualName = "Model";
304      evaluator.GetVariableInfo("SamplesStart").ActualName = p + "SamplesStart";
305      evaluator.GetVariableInfo("SamplesEnd").ActualName = p + "SamplesEnd";
306      evaluator.GetVariableInfo("Values").ActualName = p + "Values";
307      SimpleMSEEvaluator mseEvaluator = new SimpleMSEEvaluator();
308      mseEvaluator.Name = p + "MseEvaluator";
309      mseEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
310      mseEvaluator.GetVariableInfo("MSE").ActualName = p + "Quality";
311      SimpleR2Evaluator r2Evaluator = new SimpleR2Evaluator();
312      r2Evaluator.Name = p + "R2Evaluator";
313      r2Evaluator.GetVariableInfo("Values").ActualName = p + "Values";
314      r2Evaluator.GetVariableInfo("R2").ActualName = p + "R2";
315      SimpleMeanAbsolutePercentageErrorEvaluator mapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
316      mapeEvaluator.Name = p + "MAPEEvaluator";
317      mapeEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
318      mapeEvaluator.GetVariableInfo("MAPE").ActualName = p + "MAPE";
319      SimpleMeanAbsolutePercentageOfRangeErrorEvaluator mapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
320      mapreEvaluator.Name = p + "MAPREEvaluator";
321      mapreEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
322      mapreEvaluator.GetVariableInfo("MAPRE").ActualName = p + "MAPRE";
323      SimpleVarianceAccountedForEvaluator vafEvaluator = new SimpleVarianceAccountedForEvaluator();
324      vafEvaluator.Name = p + "VAFEvaluator";
325      vafEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
326      vafEvaluator.GetVariableInfo("VAF").ActualName = p + "VAF";
327
328      seqProc.AddSubOperator(evaluator);
329      seqProc.AddSubOperator(mseEvaluator);
330      seqProc.AddSubOperator(r2Evaluator);
331      seqProc.AddSubOperator(mapeEvaluator);
332      seqProc.AddSubOperator(mapreEvaluator);
333      seqProc.AddSubOperator(vafEvaluator);
334
335      op.OperatorGraph.AddOperator(seqProc);
336      op.OperatorGraph.InitialOperator = seqProc;
337      return op;
338    }
339
340    private IOperator CreateSetNextParameterValueOperator(string paramName) {
341      ProgrammableOperator progOp = new ProgrammableOperator();
342      progOp.Name = "SetNext" + paramName;
343      progOp.RemoveVariableInfo("Result");
344      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(DoubleData), VariableKind.New));
345      progOp.AddVariableInfo(new VariableInfo("ValueIndex", "ValueIndex", typeof(IntData), VariableKind.In));
346      progOp.AddVariableInfo(new VariableInfo("ValueList", "ValueList", typeof(DoubleArrayData), VariableKind.In));
347      progOp.Code =
348@"
349Value.Data = ValueList.Data[ValueIndex.Data];
350";
351
352      progOp.GetVariableInfo("Value").ActualName = paramName;
353      progOp.GetVariableInfo("ValueIndex").ActualName = paramName + "Index";
354      progOp.GetVariableInfo("ValueList").ActualName = paramName + "List";
355      return progOp;
356    }
357
358    private IOperator CreateResetOperator(string paramName, int value) {
359      ProgrammableOperator progOp = new ProgrammableOperator();
360      progOp.Name = "Reset" + paramName;
361      progOp.RemoveVariableInfo("Result");
362      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
363      progOp.Code = "Value.Data = " + value + ";";
364      progOp.GetVariableInfo("Value").ActualName = paramName;
365      return progOp;
366    }
367
368    protected virtual VariableInjector CreateGlobalInjector() {
369      VariableInjector injector = new VariableInjector();
370      injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(0)));
371      injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] {
372        Math.Pow(2,-5),
373        Math.Pow(2,-3),
374        Math.Pow(2,-1),
375        2,
376        Math.Pow(2,3),
377        Math.Pow(2,5),
378        Math.Pow(2,7),
379        Math.Pow(2,9),
380        Math.Pow(2,11),
381        Math.Pow(2,13),
382        Math.Pow(2,15)})));
383      injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
384      injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
385      injector.AddVariable(new HeuristicLab.Core.Variable("NuList", new DoubleArrayData(new double[] { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 0.8, 1 })));
386      injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
387      injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
388      injector.AddVariable(new HeuristicLab.Core.Variable("GammaIndex", new IntData(0)));
389      injector.AddVariable(new HeuristicLab.Core.Variable("GammaList", new DoubleArrayData(new double[] {
390        3.0517578125E-05, 0.0001220703125,0.00048828125,0.001953125,
391        0.0078125,0.03125,0.125,0.5,2,4,8})));
392      injector.AddVariable(new HeuristicLab.Core.Variable("MaxGammaIndex", new IntData()));
393      injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF")));
394      injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR")));
395      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
396      return injector;
397    }
398
399    protected virtual IOperator CreateModelAnalyser() {
400      CombinedOperator modelAnalyser = new CombinedOperator();
401      modelAnalyser.Name = "Model Analyzer";
402      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
403      SequentialProcessor seqProc = new SequentialProcessor();
404
405      PredictorBuilder predictorBuilder = new PredictorBuilder();
406      predictorBuilder.GetVariableInfo("SVMModel").ActualName = "Model";
407      VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
408      evalImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
409      evalImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
410      VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
411      qualImpactCalc.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
412      qualImpactCalc.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
413
414      seqProc.AddSubOperator(CreateEvaluator("Test"));
415      seqProc.AddSubOperator(predictorBuilder);
416      seqProc.AddSubOperator(evalImpactCalc);
417      seqProc.AddSubOperator(qualImpactCalc);
418      seqSubScopeProc.AddSubOperator(seqProc);
419      modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
420      modelAnalyser.OperatorGraph.AddOperator(seqSubScopeProc);
421      return modelAnalyser;
422    }
423
424
425    protected virtual IAnalyzerModel CreateSVMModel(IScope bestModelScope) {
426      AnalyzerModel model = new AnalyzerModel();
427      model.SetResult("TrainingMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data);
428      model.SetResult("ValidationMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data);
429      model.SetResult("TestMeanSquaredError", bestModelScope.GetVariableValue<DoubleData>("TestQuality", false).Data);
430      model.SetResult("TrainingCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingR2", false).Data);
431      model.SetResult("ValidationCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("ValidationR2", false).Data);
432      model.SetResult("TestCoefficientOfDetermination", bestModelScope.GetVariableValue<DoubleData>("TestR2", false).Data);
433      model.SetResult("TrainingMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPE", false).Data);
434      model.SetResult("ValidationMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data);
435      model.SetResult("TestMeanAbsolutePercentageError", bestModelScope.GetVariableValue<DoubleData>("TestMAPE", false).Data);
436      model.SetResult("TrainingMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPRE", false).Data);
437      model.SetResult("ValidationMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("ValidationMAPRE", false).Data);
438      model.SetResult("TestMeanAbsolutePercentageOfRangeError", bestModelScope.GetVariableValue<DoubleData>("TestMAPRE", false).Data);
439      model.SetResult("TrainingVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ActualTrainingVAF", false).Data);
440      model.SetResult("ValidationVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data);
441      model.SetResult("TestVarianceAccountedFor", bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data);
442
443      model.SetMetaData("Cost", bestModelScope.GetVariableValue<DoubleData>("Cost", false).Data);
444      model.SetMetaData("Nu", bestModelScope.GetVariableValue<DoubleData>("Nu", false).Data);
445
446      HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
447      model.Dataset = ds;
448      model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
449      model.TrainingSamplesStart = bestModelScope.GetVariableValue<IntData>("TrainingSamplesStart", true).Data;
450      model.TrainingSamplesEnd = bestModelScope.GetVariableValue<IntData>("TrainingSamplesEnd", true).Data;
451      model.ValidationSamplesStart = bestModelScope.GetVariableValue<IntData>("ValidationSamplesStart", true).Data;
452      model.ValidationSamplesEnd = bestModelScope.GetVariableValue<IntData>("ValidationSamplesEnd", true).Data;
453      model.TestSamplesStart = bestModelScope.GetVariableValue<IntData>("TestSamplesStart", true).Data;
454      model.TestSamplesEnd = bestModelScope.GetVariableValue<IntData>("TestSamplesEnd", true).Data;
455      model.Predictor = bestModelScope.GetVariableValue<IPredictor>("Predictor", true);
456
457      ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
458      ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
459      foreach (ItemList row in evaluationImpacts) {
460        string variableName = ((StringData)row[0]).Data;
461        double impact = ((DoubleData)row[1]).Data;
462        model.SetVariableEvaluationImpact(variableName, impact);
463        model.AddInputVariable(variableName);
464      }
465      foreach (ItemList row in qualityImpacts) {
466        string variableName = ((StringData)row[0]).Data;
467        double impact = ((DoubleData)row[1]).Data;
468        model.SetVariableQualityImpact(variableName, impact);
469        model.AddInputVariable(variableName);
470      }
471
472      return model;
473    }
474
475    protected IOperator GetVariableInjector() {
476      return GetMainOperator().SubOperators[0].SubOperators[0];
477    }
478
479    protected IOperator GetMainOperator() {
480      CombinedOperator svm = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
481      return svm.OperatorGraph.InitialOperator;
482    }
483
484    public override IView CreateView() {
485      return engine.CreateView();
486    }
487
488    #region IEditable Members
489
490    public IEditor CreateEditor() {
491      return engine.CreateEditor();
492    }
493
494    #endregion
495  }
496}
Note: See TracBrowser for help on using the repository browser.