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 System.Xml;
|
---|
28 | using System.Diagnostics;
|
---|
29 | using HeuristicLab.DataAnalysis;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Operators;
|
---|
32 | using HeuristicLab.Logging;
|
---|
33 | using HeuristicLab.Operators.Programmable;
|
---|
34 | using HeuristicLab.Modeling;
|
---|
35 | using HeuristicLab.Random;
|
---|
36 | using HeuristicLab.Selection;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.SupportVectorMachines {
|
---|
39 | public class SupportVectorRegression : ItemBase, IEditable, IAlgorithm {
|
---|
40 |
|
---|
41 | public string Name { get { return "SupportVectorRegression"; } }
|
---|
42 | public 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 IModel 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 | private 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(5000)));
|
---|
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 | modelProcessor.AddSubOperator(CreateEvaluator("Test"));
|
---|
270 |
|
---|
271 | DataCollector collector = new DataCollector();
|
---|
272 | collector.GetVariableInfo("Values").ActualName = "Log";
|
---|
273 | ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Nu"));
|
---|
274 | ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Cost"));
|
---|
275 | ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("Gamma"));
|
---|
276 | ((ItemList<StringData>)collector.GetVariable("VariableNames").Value).Add(new StringData("ValidationQuality"));
|
---|
277 | modelProcessor.AddSubOperator(collector);
|
---|
278 | return modelProcessor;
|
---|
279 | }
|
---|
280 |
|
---|
281 | private IOperator CreateComparator(string p) {
|
---|
282 | LessThanComparator comparator = new LessThanComparator();
|
---|
283 | comparator.Name = p + "IndexComparator";
|
---|
284 | comparator.GetVariableInfo("LeftSide").ActualName = p + "Index";
|
---|
285 | comparator.GetVariableInfo("RightSide").ActualName = "Max" + p + "Index";
|
---|
286 | comparator.GetVariableInfo("Result").ActualName = "Repeat" + p + "Loop";
|
---|
287 | return comparator;
|
---|
288 | }
|
---|
289 |
|
---|
290 | private IOperator CreateCounter(string p) {
|
---|
291 | Counter c = new Counter();
|
---|
292 | c.GetVariableInfo("Value").ActualName = p + "Index";
|
---|
293 | c.Name = p + "Counter";
|
---|
294 | return c;
|
---|
295 | }
|
---|
296 |
|
---|
297 | private IOperator CreateEvaluator(string p) {
|
---|
298 | CombinedOperator op = new CombinedOperator();
|
---|
299 | op.Name = p + "Evaluator";
|
---|
300 | SequentialProcessor seqProc = new SequentialProcessor();
|
---|
301 |
|
---|
302 | SupportVectorEvaluator evaluator = new SupportVectorEvaluator();
|
---|
303 | evaluator.Name = p + "SimpleEvaluator";
|
---|
304 | evaluator.GetVariableInfo("SVMModel").ActualName = "Model";
|
---|
305 | evaluator.GetVariableInfo("SamplesStart").ActualName = p + "SamplesStart";
|
---|
306 | evaluator.GetVariableInfo("SamplesEnd").ActualName = p + "SamplesEnd";
|
---|
307 | evaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
308 | SimpleMSEEvaluator mseEvaluator = new SimpleMSEEvaluator();
|
---|
309 | mseEvaluator.Name = p + "MseEvaluator";
|
---|
310 | mseEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
311 | mseEvaluator.GetVariableInfo("MSE").ActualName = p + "Quality";
|
---|
312 | SimpleR2Evaluator r2Evaluator = new SimpleR2Evaluator();
|
---|
313 | r2Evaluator.Name = p + "R2Evaluator";
|
---|
314 | r2Evaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
315 | r2Evaluator.GetVariableInfo("R2").ActualName = p + "R2";
|
---|
316 | SimpleMeanAbsolutePercentageErrorEvaluator mapeEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
|
---|
317 | mapeEvaluator.Name = p + "MAPEEvaluator";
|
---|
318 | mapeEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
319 | mapeEvaluator.GetVariableInfo("MAPE").ActualName = p + "MAPE";
|
---|
320 | SimpleMeanAbsolutePercentageOfRangeErrorEvaluator mapreEvaluator = new SimpleMeanAbsolutePercentageOfRangeErrorEvaluator();
|
---|
321 | mapreEvaluator.Name = p + "MAPREEvaluator";
|
---|
322 | mapreEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
323 | mapreEvaluator.GetVariableInfo("MAPRE").ActualName = p + "MAPRE";
|
---|
324 | SimpleVarianceAccountedForEvaluator vafEvaluator = new SimpleVarianceAccountedForEvaluator();
|
---|
325 | vafEvaluator.Name = p + "VAFEvaluator";
|
---|
326 | vafEvaluator.GetVariableInfo("Values").ActualName = p + "Values";
|
---|
327 | vafEvaluator.GetVariableInfo("VAF").ActualName = p + "VAF";
|
---|
328 |
|
---|
329 | seqProc.AddSubOperator(evaluator);
|
---|
330 | seqProc.AddSubOperator(mseEvaluator);
|
---|
331 | seqProc.AddSubOperator(r2Evaluator);
|
---|
332 | seqProc.AddSubOperator(mapeEvaluator);
|
---|
333 | seqProc.AddSubOperator(mapreEvaluator);
|
---|
334 | seqProc.AddSubOperator(vafEvaluator);
|
---|
335 |
|
---|
336 | op.OperatorGraph.AddOperator(seqProc);
|
---|
337 | op.OperatorGraph.InitialOperator = seqProc;
|
---|
338 | return op;
|
---|
339 | }
|
---|
340 |
|
---|
341 | private IOperator CreateSetNextParameterValueOperator(string paramName) {
|
---|
342 | ProgrammableOperator progOp = new ProgrammableOperator();
|
---|
343 | progOp.Name = "SetNext" + paramName;
|
---|
344 | progOp.RemoveVariableInfo("Result");
|
---|
345 | progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(DoubleData), VariableKind.New));
|
---|
346 | progOp.AddVariableInfo(new VariableInfo("ValueIndex", "ValueIndex", typeof(IntData), VariableKind.In));
|
---|
347 | progOp.AddVariableInfo(new VariableInfo("ValueList", "ValueList", typeof(DoubleArrayData), VariableKind.In));
|
---|
348 | progOp.Code =
|
---|
349 | @"
|
---|
350 | Value.Data = ValueList.Data[ValueIndex.Data];
|
---|
351 | ";
|
---|
352 |
|
---|
353 | progOp.GetVariableInfo("Value").ActualName = paramName;
|
---|
354 | progOp.GetVariableInfo("ValueIndex").ActualName = paramName + "Index";
|
---|
355 | progOp.GetVariableInfo("ValueList").ActualName = paramName + "List";
|
---|
356 | return progOp;
|
---|
357 | }
|
---|
358 |
|
---|
359 | private IOperator CreateResetOperator(string paramName, int value) {
|
---|
360 | ProgrammableOperator progOp = new ProgrammableOperator();
|
---|
361 | progOp.Name = "Reset" + paramName;
|
---|
362 | progOp.RemoveVariableInfo("Result");
|
---|
363 | progOp.AddVariableInfo(new VariableInfo("Value", "Value", typeof(IntData), VariableKind.In | VariableKind.Out));
|
---|
364 | progOp.Code = "Value.Data = "+value+";";
|
---|
365 | progOp.GetVariableInfo("Value").ActualName = paramName;
|
---|
366 | return progOp;
|
---|
367 | }
|
---|
368 |
|
---|
369 | private IOperator CreateGlobalInjector() {
|
---|
370 | VariableInjector injector = new VariableInjector();
|
---|
371 | injector.AddVariable(new HeuristicLab.Core.Variable("CostIndex", new IntData(0)));
|
---|
372 | injector.AddVariable(new HeuristicLab.Core.Variable("CostList", new DoubleArrayData(new double[] {
|
---|
373 | Math.Pow(2,-5),
|
---|
374 | Math.Pow(2,-3),
|
---|
375 | Math.Pow(2,-1),
|
---|
376 | 2,
|
---|
377 | Math.Pow(2,3),
|
---|
378 | Math.Pow(2,5),
|
---|
379 | Math.Pow(2,7),
|
---|
380 | Math.Pow(2,9),
|
---|
381 | Math.Pow(2,11),
|
---|
382 | Math.Pow(2,13),
|
---|
383 | Math.Pow(2,15)})));
|
---|
384 | injector.AddVariable(new HeuristicLab.Core.Variable("MaxCostIndex", new IntData()));
|
---|
385 | injector.AddVariable(new HeuristicLab.Core.Variable("NuIndex", new IntData(0)));
|
---|
386 | 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 })));
|
---|
387 | injector.AddVariable(new HeuristicLab.Core.Variable("MaxNuIndex", new IntData()));
|
---|
388 | injector.AddVariable(new HeuristicLab.Core.Variable("Log", new ItemList()));
|
---|
389 | injector.AddVariable(new HeuristicLab.Core.Variable("GammaIndex", new IntData(0)));
|
---|
390 | injector.AddVariable(new HeuristicLab.Core.Variable("GammaList", new DoubleArrayData(new double[] {
|
---|
391 | 3.0517578125E-05, 0.0001220703125,0.00048828125,0.001953125,
|
---|
392 | 0.0078125,0.03125,0.125,0.5,2,4,8})));
|
---|
393 | injector.AddVariable(new HeuristicLab.Core.Variable("MaxGammaIndex", new IntData()));
|
---|
394 | injector.AddVariable(new HeuristicLab.Core.Variable("KernelType", new StringData("RBF")));
|
---|
395 | injector.AddVariable(new HeuristicLab.Core.Variable("Type", new StringData("NU_SVR")));
|
---|
396 |
|
---|
397 | return injector;
|
---|
398 | }
|
---|
399 |
|
---|
400 | private IOperator CreateModelAnalyser() {
|
---|
401 | CombinedOperator modelAnalyser = new CombinedOperator();
|
---|
402 | modelAnalyser.Name = "Model Analyzer";
|
---|
403 | SequentialSubScopesProcessor seqSubScopeProc = new SequentialSubScopesProcessor();
|
---|
404 | SequentialProcessor seqProc = new SequentialProcessor();
|
---|
405 | VariableEvaluationImpactCalculator evalImpactCalc = new VariableEvaluationImpactCalculator();
|
---|
406 | evalImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
|
---|
407 | VariableQualityImpactCalculator qualImpactCalc = new VariableQualityImpactCalculator();
|
---|
408 | qualImpactCalc.GetVariableInfo("SVMModel").ActualName = "Model";
|
---|
409 |
|
---|
410 | seqProc.AddSubOperator(evalImpactCalc);
|
---|
411 | seqProc.AddSubOperator(qualImpactCalc);
|
---|
412 | seqSubScopeProc.AddSubOperator(seqProc);
|
---|
413 | modelAnalyser.OperatorGraph.InitialOperator = seqSubScopeProc;
|
---|
414 | modelAnalyser.OperatorGraph.AddOperator(seqSubScopeProc);
|
---|
415 | return modelAnalyser;
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 | protected internal virtual Model CreateSVMModel(IScope bestModelScope) {
|
---|
420 | Model model = new Model();
|
---|
421 | model.TrainingMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("Quality", false).Data;
|
---|
422 | model.ValidationMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("ValidationQuality", false).Data;
|
---|
423 | model.TestMeanSquaredError = bestModelScope.GetVariableValue<DoubleData>("TestQuality", false).Data;
|
---|
424 | model.TrainingCoefficientOfDetermination = bestModelScope.GetVariableValue<DoubleData>("ActualTrainingR2", false).Data;
|
---|
425 | model.ValidationCoefficientOfDetermination = bestModelScope.GetVariableValue<DoubleData>("ValidationR2", false).Data;
|
---|
426 | model.TestCoefficientOfDetermination = bestModelScope.GetVariableValue<DoubleData>("TestR2", false).Data;
|
---|
427 | model.TrainingMeanAbsolutePercentageError = bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPE", false).Data;
|
---|
428 | model.ValidationMeanAbsolutePercentageError = bestModelScope.GetVariableValue<DoubleData>("ValidationMAPE", false).Data;
|
---|
429 | model.TestMeanAbsolutePercentageError = bestModelScope.GetVariableValue<DoubleData>("TestMAPE", false).Data;
|
---|
430 | model.TrainingMeanAbsolutePercentageOfRangeError = bestModelScope.GetVariableValue<DoubleData>("ActualTrainingMAPRE", false).Data;
|
---|
431 | model.ValidationMeanAbsolutePercentageOfRangeError = bestModelScope.GetVariableValue<DoubleData>("ValidationMAPRE", false).Data;
|
---|
432 | model.TestMeanAbsolutePercentageOfRangeError = bestModelScope.GetVariableValue<DoubleData>("TestMAPRE", false).Data;
|
---|
433 | model.TrainingVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("ActualTrainingVAF", false).Data;
|
---|
434 | model.ValidationVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("ValidationVAF", false).Data;
|
---|
435 | model.TestVarianceAccountedFor = bestModelScope.GetVariableValue<DoubleData>("TestVAF", false).Data;
|
---|
436 |
|
---|
437 | model.Data = bestModelScope.GetVariableValue<SVMModel>("Model", false);
|
---|
438 | HeuristicLab.DataAnalysis.Dataset ds = bestModelScope.GetVariableValue<Dataset>("Dataset", true);
|
---|
439 | model.Dataset = ds;
|
---|
440 | model.TargetVariable = ds.GetVariableName(bestModelScope.GetVariableValue<IntData>("TargetVariable", true).Data);
|
---|
441 |
|
---|
442 | ItemList evaluationImpacts = bestModelScope.GetVariableValue<ItemList>("VariableEvaluationImpacts", false);
|
---|
443 | ItemList qualityImpacts = bestModelScope.GetVariableValue<ItemList>("VariableQualityImpacts", false);
|
---|
444 | foreach (ItemList row in evaluationImpacts) {
|
---|
445 | string variableName = ((StringData)row[0]).Data;
|
---|
446 | double impact = ((DoubleData)row[1]).Data;
|
---|
447 | model.SetVariableEvaluationImpact(variableName, impact);
|
---|
448 | model.AddInputVariables(variableName);
|
---|
449 | }
|
---|
450 | foreach (ItemList row in qualityImpacts) {
|
---|
451 | string variableName = ((StringData)row[0]).Data;
|
---|
452 | double impact = ((DoubleData)row[1]).Data;
|
---|
453 | model.SetVariableQualityImpact(variableName, impact);
|
---|
454 | model.AddInputVariables(variableName);
|
---|
455 | }
|
---|
456 |
|
---|
457 | return model;
|
---|
458 | }
|
---|
459 |
|
---|
460 | private IOperator GetVariableInjector() {
|
---|
461 | return GetMainOperator().SubOperators[0].SubOperators[0];
|
---|
462 | }
|
---|
463 |
|
---|
464 | private IOperator GetMainOperator() {
|
---|
465 | CombinedOperator svm = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
|
---|
466 | return svm.OperatorGraph.InitialOperator;
|
---|
467 | }
|
---|
468 |
|
---|
469 | public override IView CreateView() {
|
---|
470 | return engine.CreateView();
|
---|
471 | }
|
---|
472 |
|
---|
473 | #region IEditable Members
|
---|
474 |
|
---|
475 | public IEditor CreateEditor() {
|
---|
476 | return engine.CreateEditor();
|
---|
477 | }
|
---|
478 |
|
---|
479 | #endregion
|
---|
480 | }
|
---|
481 | }
|
---|