Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3514 was 2552, checked in by mkommend, 15 years ago

added gamma as metadata for SVR-Models (ticket #775)

File size: 23.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 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 IEngine 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 string TargetVariable {
55      get { return ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data; }
56      set { ProblemInjector.GetVariableValue<StringData>("TargetVariable", null, false).Data = value; }
57    }
58
59    public IOperator ProblemInjector {
60      get {
61        IOperator main = GetMainOperator();
62        CombinedOperator probInject = (CombinedOperator)main.SubOperators[0].SubOperators[2];
63        return probInject.OperatorGraph.InitialOperator.SubOperators[0];
64      }
65      set {
66        IOperator main = GetMainOperator();
67        CombinedOperator probInject = (CombinedOperator)main.SubOperators[0].SubOperators[2];
68        probInject.OperatorGraph.InitialOperator.RemoveSubOperator(0);
69        probInject.OperatorGraph.InitialOperator.AddSubOperator(value, 0);
70      }
71    }
72
73    public IAnalyzerModel Model {
74      get {
75        if (!engine.Terminated) throw new InvalidOperationException("The algorithm is still running. Wait until the algorithm is terminated to retrieve the result.");
76        IScope bestModelScope = engine.GlobalScope.SubScopes[0];
77        return CreateSVMModel(bestModelScope);
78      }
79    }
80    public IEnumerable<string> AllowedVariables {
81      get {
82        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
83        return allowedVariables.Select(x => x.Data);
84      }
85      set {
86        ItemList<StringData> allowedVariables = ProblemInjector.GetVariableValue<ItemList<StringData>>("AllowedFeatures", null, false);
87        foreach (string x in value) allowedVariables.Add(new StringData(x));
88      }
89    }
90
91    public int TrainingSamplesStart {
92      get { return ProblemInjector.GetVariableValue<IntData>("TrainingSamplesStart", null, false).Data; }
93      set { ProblemInjector.GetVariableValue<IntData>("TrainingSamplesStart", null, false).Data = value; }
94    }
95
96    public int TrainingSamplesEnd {
97      get { return ProblemInjector.GetVariableValue<IntData>("TrainingSamplesEnd", null, false).Data; }
98      set { ProblemInjector.GetVariableValue<IntData>("TrainingSamplesEnd", null, false).Data = value; }
99    }
100
101    public int ValidationSamplesStart {
102      get { return ProblemInjector.GetVariableValue<IntData>("ValidationSamplesStart", null, false).Data; }
103      set { ProblemInjector.GetVariableValue<IntData>("ValidationSamplesStart", null, false).Data = value; }
104    }
105
106    public int ValidationSamplesEnd {
107      get { return ProblemInjector.GetVariableValue<IntData>("ValidationSamplesEnd", null, false).Data; }
108      set { ProblemInjector.GetVariableValue<IntData>("ValidationSamplesEnd", null, false).Data = value; }
109    }
110
111    public int TestSamplesStart {
112      get { return ProblemInjector.GetVariableValue<IntData>("TestSamplesStart", null, false).Data; }
113      set { ProblemInjector.GetVariableValue<IntData>("TestSamplesStart", null, false).Data = value; }
114    }
115
116    public int TestSamplesEnd {
117      get { return ProblemInjector.GetVariableValue<IntData>("TestSamplesEnd", null, false).Data; }
118      set { ProblemInjector.GetVariableValue<IntData>("TestSamplesEnd", null, false).Data = value; }
119    }
120
121    public DoubleArrayData NuList {
122      get { return GetVariableInjector().GetVariable("NuList").GetValue<DoubleArrayData>(); }
123      set { GetVariableInjector().GetVariable("NuList").Value = value; }
124    }
125
126    public int MaxNuIndex {
127      get { return GetVariableInjector().GetVariable("MaxNuIndex").GetValue<IntData>().Data; }
128      set { GetVariableInjector().GetVariable("MaxNuIndex").GetValue<IntData>().Data = value; }
129    }
130
131    public DoubleArrayData CostList {
132      get { return GetVariableInjector().GetVariable("CostList").GetValue<DoubleArrayData>(); }
133      set { GetVariableInjector().GetVariable("CostList").Value = value; }
134    }
135
136    public int MaxCostIndex {
137      get { return GetVariableInjector().GetVariable("MaxCostIndex").GetValue<IntData>().Data; }
138      set { GetVariableInjector().GetVariable("MaxCostIndex").GetValue<IntData>().Data = value; }
139    }
140
141    public DoubleArrayData GammaList {
142      get { return GetVariableInjector().GetVariable("GammaList").GetValue<DoubleArrayData>(); }
143      set { GetVariableInjector().GetVariable("GammaList").Value = value; }
144    }
145
146    public int MaxGammaIndex {
147      get { return GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data; }
148      set { GetVariableInjector().GetVariable("MaxGammaIndex").GetValue<IntData>().Data = value; }
149    }
150
151    public string SvmType {
152      get { return GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data; }
153      set { GetVariableInjector().GetVariable("Type").GetValue<StringData>().Data = value; }
154    }
155
156    public SupportVectorRegression() {
157      engine = new SequentialEngine.SequentialEngine();
158      CombinedOperator algo = CreateAlgorithm();
159      engine.OperatorGraph.AddOperator(algo);
160      engine.OperatorGraph.InitialOperator = algo;
161      MaxCostIndex = CostList.Data.Length;
162      MaxNuIndex = NuList.Data.Length;
163      MaxGammaIndex = GammaList.Data.Length;
164    }
165
166    private CombinedOperator CreateAlgorithm() {
167      CombinedOperator algo = new CombinedOperator();
168      SequentialProcessor seq = new SequentialProcessor();
169      algo.Name = Name;
170      seq.Name = Name;
171
172      IOperator initialization = CreateInitialization();
173      IOperator main = CreateMainLoop();
174      IOperator postProc = CreatePostProcessingOperator();
175
176      seq.AddSubOperator(initialization);
177      seq.AddSubOperator(main);
178      seq.AddSubOperator(postProc);
179
180      algo.OperatorGraph.InitialOperator = seq;
181      algo.OperatorGraph.AddOperator(seq);
182
183      return algo;
184    }
185
186    protected virtual IOperator CreateInitialization() {
187      SequentialProcessor seq = new SequentialProcessor();
188      seq.Name = "Initialization";
189      seq.AddSubOperator(new RandomInjector());
190      seq.AddSubOperator(CreateGlobalInjector());
191      seq.AddSubOperator(CreateProblemInjector());
192      return seq;
193    }
194
195    protected virtual IOperator CreateProblemInjector() {
196      return DefaultRegressionOperators.CreateProblemInjector();
197    }
198
199    private IOperator CreateMainLoop() {
200      SequentialProcessor main = new SequentialProcessor();
201      main.Name = "Main";
202      #region initial solution
203      SubScopesCreater modelScopeCreator = new SubScopesCreater();
204      modelScopeCreator.GetVariableInfo("SubScopes").Local = true;
205      modelScopeCreator.AddVariable(new HeuristicLab.Core.Variable("SubScopes", new IntData(1)));
206      main.AddSubOperator(modelScopeCreator);
207
208      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
209      IOperator modelProcessor = CreateModelProcessor();
210
211      seqSubScopesProc.AddSubOperator(modelProcessor);
212      main.AddSubOperator(seqSubScopesProc);
213      #endregion
214
215      SequentialProcessor nuLoop = new SequentialProcessor();
216      nuLoop.Name = "NuLoop";
217
218      SequentialProcessor gammaLoop = new SequentialProcessor();
219      gammaLoop.Name = "GammaLoop";
220
221      nuLoop.AddSubOperator(gammaLoop);
222
223      IOperator costCounter = CreateCounter("Cost");
224      IOperator costComparator = CreateComparator("Cost");
225      gammaLoop.AddSubOperator(costCounter);
226      gammaLoop.AddSubOperator(costComparator);
227
228      ConditionalBranch costBranch = new ConditionalBranch();
229      costBranch.Name = "IfValidCostIndex";
230      costBranch.GetVariableInfo("Condition").ActualName = "RepeatCostLoop";
231
232      // build cost loop
233      SequentialProcessor costLoop = new SequentialProcessor();
234      costLoop.Name = "CostLoop";
235
236      #region selection of better solution
237      costLoop.AddSubOperator(modelScopeCreator);
238      SequentialSubScopesProcessor subScopesProcessor = new SequentialSubScopesProcessor();
239      costLoop.AddSubOperator(subScopesProcessor);
240      subScopesProcessor.AddSubOperator(new EmptyOperator());
241      subScopesProcessor.AddSubOperator(modelProcessor);
242
243      Sorter sorter = new Sorter();
244      sorter.GetVariableInfo("Value").ActualName = "ValidationQuality";
245      sorter.GetVariableInfo("Descending").Local = true;
246      sorter.AddVariable(new Variable("Descending", new BoolData(false)));
247      costLoop.AddSubOperator(sorter);
248
249      LeftSelector selector = new LeftSelector();
250      selector.GetVariableInfo("Selected").Local = true;
251      selector.AddVariable(new Variable("Selected", new IntData(1)));
252      costLoop.AddSubOperator(selector);
253
254      RightReducer reducer = new RightReducer();
255      costLoop.AddSubOperator(reducer);
256      #endregion
257
258      costLoop.AddSubOperator(costCounter);
259      costLoop.AddSubOperator(costComparator);
260
261      costBranch.AddSubOperator(costLoop);
262      costLoop.AddSubOperator(costBranch);
263
264      gammaLoop.AddSubOperator(costBranch); // inner loop
265      gammaLoop.AddSubOperator(CreateResetOperator("CostIndex", -1));
266      gammaLoop.AddSubOperator(CreateCounter("Gamma"));
267      gammaLoop.AddSubOperator(CreateComparator("Gamma"));
268
269      ConditionalBranch gammaBranch = new ConditionalBranch();
270      gammaBranch.Name = "GammaLoop";
271      gammaBranch.GetVariableInfo("Condition").ActualName = "RepeatGammaLoop";
272      gammaBranch.AddSubOperator(gammaLoop);
273      gammaLoop.AddSubOperator(gammaBranch);
274
275      nuLoop.AddSubOperator(CreateResetOperator("GammaIndex", 0));
276
277      nuLoop.AddSubOperator(CreateCounter("Nu"));
278      nuLoop.AddSubOperator(CreateComparator("Nu"));
279
280      ConditionalBranch nuBranch = new ConditionalBranch();
281      nuBranch.Name = "NuLoop";
282      nuBranch.GetVariableInfo("Condition").ActualName = "RepeatNuLoop";
283
284      nuBranch.AddSubOperator(nuLoop);
285      nuLoop.AddSubOperator(nuBranch);
286
287      main.AddSubOperator(nuLoop);
288      return main;
289    }
290
291    private IOperator CreateModelProcessor() {
292      SequentialProcessor modelProcessor = new SequentialProcessor();
293      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Nu"));
294      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Cost"));
295      modelProcessor.AddSubOperator(CreateSetNextParameterValueOperator("Gamma"));
296
297      SupportVectorCreator modelCreator = new SupportVectorCreator();
298      modelCreator.GetVariableInfo("SamplesStart").ActualName = "ActualTrainingSamplesStart";
299      modelCreator.GetVariableInfo("SamplesEnd").ActualName = "ActualTrainingSamplesEnd";
300      modelCreator.GetVariableInfo("SVMCost").ActualName = "Cost";
301      modelCreator.GetVariableInfo("SVMGamma").ActualName = "Gamma";
302      modelCreator.GetVariableInfo("SVMKernelType").ActualName = "KernelType";
303      modelCreator.GetVariableInfo("SVMModel").ActualName = "Model";
304      modelCreator.GetVariableInfo("SVMNu").ActualName = "Nu";
305      modelCreator.GetVariableInfo("SVMType").ActualName = "Type";
306
307      modelProcessor.AddSubOperator(modelCreator);
308      CombinedOperator trainingEvaluator = (CombinedOperator)CreateEvaluator("ActualTraining");
309      trainingEvaluator.OperatorGraph.InitialOperator.SubOperators[1].GetVariableInfo("MSE").ActualName = "Quality";
310      modelProcessor.AddSubOperator(trainingEvaluator);
311      modelProcessor.AddSubOperator(CreateEvaluator("Validation"));
312
313      DataCollector collector = new DataCollector();
314      collector.GetVariableInfo("Values").ActualName = "Log";
315      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Nu"));
316      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Cost"));
317      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Gamma"));
318      ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
319      modelProcessor.AddSubOperator(collector);
320      return modelProcessor;
321    }
322
323    private IOperator CreateComparator(string p) {
324      LessThanComparator comparator = new LessThanComparator();
325      comparator.Name = p + "IndexComparator";
326      comparator.GetVariableInfo("LeftSide").ActualName = p + "Index";
327      comparator.GetVariableInfo("RightSide").ActualName = "Max" + p + "Index";
328      comparator.GetVariableInfo("Result").ActualName = "Repeat" + p + "Loop";
329      return comparator;
330    }
331
332    private IOperator CreateCounter(string p) {
333      Counter c = new Counter();
334      c.GetVariableInfo("Value").ActualName = p + "Index";
335      c.Name = p + "Counter";
336      return c;
337    }
338
339    protected virtual IOperator CreateEvaluator(string p) {
340      CombinedOperator op = new CombinedOperator();
341      op.Name = p + "Evaluator";
342      SequentialProcessor seqProc = new SequentialProcessor();
343
344      SupportVectorEvaluator evaluator = new SupportVectorEvaluator();
345      evaluator.Name = p + "SimpleEvaluator";
346      evaluator.GetVariableInfo("SVMModel").ActualName = "Model";
347      evaluator.GetVariableInfo("SamplesStart").ActualName = p + "SamplesStart";
348      evaluator.GetVariableInfo("SamplesEnd").ActualName = p + "SamplesEnd";
349      evaluator.GetVariableInfo("Values").ActualName = p + "Values";
350      SimpleMSEEvaluator mseEvaluator = new SimpleMSEEvaluator();
351      mseEvaluator.Name = p + "MseEvaluator";
352      mseEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
353      mseEvaluator.GetVariableInfo("MSE").ActualName = p + "Quality";
354      SimpleR2Evaluator r2Evaluator = new SimpleR2Evaluator();
355      r2Evaluator.Name = p + "R2Evaluator";
356      r2Evaluator.GetVariableInfo("Values").ActualName = p + "Values";
357      r2Evaluator.GetVariableInfo("R2").ActualName = p + "R2";
358      SimpleMeanAbsolutePercentageErrorEvaluator mapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
359      mapeEvaluator.Name = p + "MAPEEvaluator";
360      mapeEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
361      mapeEvaluator.GetVariableInfo("MAPE").ActualName = p + "MAPE";
362      SimpleMeanAbsolutePercentageOfRangeErrorEvaluator mapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
363      mapreEvaluator.Name = p + "MAPREEvaluator";
364      mapreEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
365      mapreEvaluator.GetVariableInfo("MAPRE").ActualName = p + "MAPRE";
366      SimpleVarianceAccountedForEvaluator vafEvaluator = new SimpleVarianceAccountedForEvaluator();
367      vafEvaluator.Name = p + "VAFEvaluator";
368      vafEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
369      vafEvaluator.GetVariableInfo("VAF").ActualName = p + "VAF";
370
371      seqProc.AddSubOperator(evaluator);
372      seqProc.AddSubOperator(mseEvaluator);
373      seqProc.AddSubOperator(r2Evaluator);
374      seqProc.AddSubOperator(mapeEvaluator);
375      seqProc.AddSubOperator(mapreEvaluator);
376      seqProc.AddSubOperator(vafEvaluator);
377
378      op.OperatorGraph.AddOperator(seqProc);
379      op.OperatorGraph.InitialOperator = seqProc;
380      return op;
381    }
382
383    private IOperator CreateSetNextParameterValueOperator(string paramName) {
384      ProgrammableOperator progOp = new ProgrammableOperator();
385      progOp.Name = "SetNext" + paramName;
386      progOp.RemoveVariableInfo("Result");
387      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(DoubleData), VariableKind.New));
388      progOp.AddVariableInfo(new VariableInfo("ValueIndex", "ValueIndex", typeof(IntData), VariableKind.In));
389      progOp.AddVariableInfo(new VariableInfo("ValueList", "ValueList", typeof(DoubleArrayData), VariableKind.In));
390      progOp.Code =
391@"
392Value.Data = ValueList.Data[ValueIndex.Data];
393";
394
395      progOp.GetVariableInfo("Value").ActualName = paramName;
396      progOp.GetVariableInfo("ValueIndex").ActualName = paramName + "Index";
397      progOp.GetVariableInfo("ValueList").ActualName = paramName + "List";
398      return progOp;
399    }
400
401    private IOperator CreateResetOperator(string paramName, int value) {
402      ProgrammableOperator progOp = new ProgrammableOperator();
403      progOp.Name = "Reset" + paramName;
404      progOp.RemoveVariableInfo("Result");
405      progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
406      progOp.Code = "Value.Data = " + value + ";";
407      progOp.GetVariableInfo("Value").ActualName = paramName;
408      return progOp;
409    }
410
411    protected virtual VariableInjector CreateGlobalInjector() {
412      VariableInjector injector = new VariableInjector();
413      injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(0)));
414      injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] {
415        Math.Pow(2,-5),
416        Math.Pow(2,-3),
417        Math.Pow(2,-1),
418        2,
419        Math.Pow(2,3),
420        Math.Pow(2,5),
421        Math.Pow(2,7),
422        Math.Pow(2,9),
423        Math.Pow(2,11),
424        Math.Pow(2,13),
425        Math.Pow(2,15)})));
426      injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
427      injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
428      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.8, 0.9, 1 })));
429      injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
430      injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
431      injector.AddVariable(new HeuristicLab.Core.Variable("GammaIndex", new IntData(0)));
432      injector.AddVariable(new HeuristicLab.Core.Variable("GammaList", new DoubleArrayData(new double[] {
433        3.0517578125E-05, 0.0001220703125,0.00048828125,0.001953125,
434        0.0078125,0.03125,0.125,0.5,2,4,8})));
435      injector.AddVariable(new HeuristicLab.Core.Variable("MaxGammaIndex", new IntData()));
436      injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF")));
437      injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR")));
438      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(1000.0)));
439      injector.AddVariable(new Variable("MaxNumberOfTrainingSamples", new IntData(1000)));
440      return injector;
441    }
442
443    protected virtual IOperator CreatePostProcessingOperator() {
444      CombinedOperator modelAnalyser = new CombinedOperator();
445      modelAnalyser.Name = "Model Analyzer";
446      SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
447      SequentialProcessor seqProc = new SequentialProcessor();
448
449      PredictorBuilder predictorBuilder = new PredictorBuilder();
450      predictorBuilder.GetVariableInfo("SVMModel").ActualName = "Model";
451
452      seqProc.AddSubOperator(CreateEvaluator("Test"));
453      seqProc.AddSubOperator(CreateEvaluator("Training"));
454      seqProc.AddSubOperator(predictorBuilder);
455
456      #region variable impacts
457      VariableQualityImpactCalculator qualityImpactCalculator = new VariableQualityImpactCalculator();
458      qualityImpactCalculator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
459      qualityImpactCalculator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
460
461      seqProc.AddSubOperator(qualityImpactCalculator);
462      #endregion
463
464
465      seqProc.AddSubOperator(CreateModelAnalyzerOperator());
466
467      seqSubScopeProc.AddSubOperator(seqProc);
468      modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
469      modelAnalyser.OperatorGraph.AddOperator(seqSubScopeProc);
470      return modelAnalyser;
471    }
472
473    protected virtual IOperator CreateModelAnalyzerOperator() {
474      return DefaultRegressionOperators.CreatePostProcessingOperator();
475    }
476
477
478    protected virtual IAnalyzerModel CreateSVMModel(IScope bestModelScope) {
479      AnalyzerModel model = new AnalyzerModel();
480      model.SetMetaData("Cost", bestModelScope.GetVariableValue<DoubleData>("Cost", false).Data);
481      model.SetMetaData("Nu", bestModelScope.GetVariableValue<DoubleData>("Nu", false).Data);
482      model.SetMetaData("Gamma", bestModelScope.GetVariableValue<DoubleData>("Gamma", false).Data);
483      #region variable impacts
484      ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>(ModelingResult.VariableQualityImpact.ToString(), false);
485      foreach (ItemList row in qualityImpacts) {
486        string variableName = ((StringData)row[0]).Data;
487        double impact = ((DoubleData)row[1]).Data;
488        model.SetVariableResult(ModelingResult.VariableQualityImpact, variableName, impact);
489        model.AddInputVariable(variableName);
490      }
491      #endregion
492
493      CreateSpecificSVMModel(bestModelScope, model);
494
495      return model;
496    }
497
498    protected virtual void CreateSpecificSVMModel(IScope bestModelScope, IAnalyzerModel model) {
499      DefaultRegressionOperators.PopulateAnalyzerModel(bestModelScope, model);
500    }
501
502    protected IOperator GetVariableInjector() {
503      return GetMainOperator().SubOperators[0].SubOperators[1];
504    }
505
506    protected IOperator GetMainOperator() {
507      CombinedOperator svm = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
508      return svm.OperatorGraph.InitialOperator;
509    }
510
511    public override IView CreateView() {
512      return engine.CreateView();
513    }
514
515    #region IEditable Members
516
517    public IEditor CreateEditor() {
518      return ((SequentialEngine.SequentialEngine)engine).CreateEditor();
519    }
520
521    #endregion
522
523    #region persistence
524    public override object Clone(IDictionary<Guid, object> clonedObjects) {
525      SupportVectorRegression clone = (SupportVectorRegression)base.Clone(clonedObjects);
526      clone.engine = (IEngine)Auxiliary.Clone(Engine, clonedObjects);
527      return clone;
528    }
529
530    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
531      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
532      node.AppendChild(PersistenceManager.Persist("Engine", engine, document, persistedObjects));
533      return node;
534    }
535
536    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
537      base.Populate(node, restoredObjects);
538      engine = (IEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
539    }
540    #endregion
541  }
542}
Note: See TracBrowser for help on using the repository browser.