1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Threading;
|
---|
27 | using System.Threading.Tasks;
|
---|
28 | using HeuristicLab.Collections;
|
---|
29 | using HeuristicLab.Common;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 | using HeuristicLab.Data;
|
---|
32 | using HeuristicLab.Optimization;
|
---|
33 | using HEAL.Attic;
|
---|
34 | using HeuristicLab.Problems.DataAnalysis;
|
---|
35 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
36 | using HeuristicLab.Random;
|
---|
37 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
|
---|
38 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Classification;
|
---|
39 |
|
---|
40 | namespace HeuristicLab.Algorithms.DataAnalysis {
|
---|
41 | [Item("Cross Validation (CV)", "Cross-validation wrapper for data analysis algorithms.")]
|
---|
42 | [Creatable(CreatableAttribute.Categories.DataAnalysis, Priority = 100)]
|
---|
43 | [StorableType("1C622121-AE5B-42FD-831C-FCA8F8E0AF8D")]
|
---|
44 | public sealed class CrossValidation : ParameterizedNamedItem, IAlgorithm, IStorableContent {
|
---|
45 | [Storable]
|
---|
46 | private int seed;
|
---|
47 |
|
---|
48 | private SemaphoreSlim availableWorkers; // limits the number of concurrent algorithm executions
|
---|
49 | private ManualResetEventSlim allAlgorithmsFinished; // this indicates that all started algorithms have been paused or stopped
|
---|
50 |
|
---|
51 | public CrossValidation()
|
---|
52 | : base() {
|
---|
53 | name = ItemName;
|
---|
54 | description = ItemDescription;
|
---|
55 |
|
---|
56 | executionState = ExecutionState.Stopped;
|
---|
57 | runs = new RunCollection { OptimizerName = name };
|
---|
58 | runsCounter = 0;
|
---|
59 |
|
---|
60 | algorithm = null;
|
---|
61 | clonedAlgorithms = new ItemCollection<IAlgorithm>();
|
---|
62 | results = new ResultCollection();
|
---|
63 |
|
---|
64 | folds = new IntValue(2);
|
---|
65 | numberOfWorkers = new IntValue(1);
|
---|
66 | samplesStart = new IntValue(0);
|
---|
67 | samplesEnd = new IntValue(0);
|
---|
68 | shuffleSamples = new BoolValue(false);
|
---|
69 | storeAlgorithmInEachRun = false;
|
---|
70 |
|
---|
71 | RegisterEvents();
|
---|
72 | if (Algorithm != null) RegisterAlgorithmEvents();
|
---|
73 | }
|
---|
74 |
|
---|
75 | public string Filename { get; set; }
|
---|
76 |
|
---|
77 | #region persistence and cloning
|
---|
78 | [StorableConstructor]
|
---|
79 | private CrossValidation(StorableConstructorFlag _) : base(_) {
|
---|
80 | }
|
---|
81 | [StorableHook(HookType.AfterDeserialization)]
|
---|
82 | private void AfterDeserialization() {
|
---|
83 | // BackwardsCompatibility3.3
|
---|
84 | #region Backwards compatible code, remove with 3.4
|
---|
85 | if (shuffleSamples == null) shuffleSamples = new BoolValue(false);
|
---|
86 | #endregion
|
---|
87 |
|
---|
88 | RegisterEvents();
|
---|
89 | if (Algorithm != null) RegisterAlgorithmEvents();
|
---|
90 | }
|
---|
91 |
|
---|
92 | private CrossValidation(CrossValidation original, Cloner cloner)
|
---|
93 | : base(original, cloner) {
|
---|
94 | executionState = original.executionState;
|
---|
95 | storeAlgorithmInEachRun = original.storeAlgorithmInEachRun;
|
---|
96 | runs = cloner.Clone(original.runs);
|
---|
97 | runsCounter = original.runsCounter;
|
---|
98 | algorithm = cloner.Clone(original.algorithm);
|
---|
99 | clonedAlgorithms = cloner.Clone(original.clonedAlgorithms);
|
---|
100 | results = cloner.Clone(original.results);
|
---|
101 |
|
---|
102 | folds = cloner.Clone(original.folds);
|
---|
103 | numberOfWorkers = cloner.Clone(original.numberOfWorkers);
|
---|
104 | samplesStart = cloner.Clone(original.samplesStart);
|
---|
105 | samplesEnd = cloner.Clone(original.samplesEnd);
|
---|
106 | shuffleSamples = cloner.Clone(original.shuffleSamples);
|
---|
107 | seed = original.seed;
|
---|
108 |
|
---|
109 | RegisterEvents();
|
---|
110 | if (Algorithm != null) RegisterAlgorithmEvents();
|
---|
111 | }
|
---|
112 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
113 | return new CrossValidation(this, cloner);
|
---|
114 | }
|
---|
115 |
|
---|
116 | #endregion
|
---|
117 |
|
---|
118 | #region properties
|
---|
119 | [Storable]
|
---|
120 | private IAlgorithm algorithm;
|
---|
121 | public IAlgorithm Algorithm {
|
---|
122 | get { return algorithm; }
|
---|
123 | set {
|
---|
124 | if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped)
|
---|
125 | throw new InvalidOperationException("Changing the algorithm is only allowed if the CrossValidation is stopped or prepared.");
|
---|
126 | if (algorithm != value) {
|
---|
127 | if (value != null && value.Problem != null && !(value.Problem is IDataAnalysisProblem))
|
---|
128 | throw new ArgumentException("Only algorithms with a DataAnalysisProblem could be used for the cross validation.");
|
---|
129 | if (algorithm != null) DeregisterAlgorithmEvents();
|
---|
130 | algorithm = value;
|
---|
131 | Parameters.Clear();
|
---|
132 |
|
---|
133 | if (algorithm != null) {
|
---|
134 | algorithm.StoreAlgorithmInEachRun = false;
|
---|
135 | RegisterAlgorithmEvents();
|
---|
136 | algorithm.Prepare(true);
|
---|
137 | Parameters.AddRange(algorithm.Parameters);
|
---|
138 | }
|
---|
139 | OnAlgorithmChanged();
|
---|
140 | Prepare();
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | [Storable]
|
---|
147 | private IDataAnalysisProblem problem;
|
---|
148 | public IDataAnalysisProblem Problem {
|
---|
149 | get {
|
---|
150 | if (algorithm == null)
|
---|
151 | return null;
|
---|
152 | return (IDataAnalysisProblem)algorithm.Problem;
|
---|
153 | }
|
---|
154 | set {
|
---|
155 | if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped)
|
---|
156 | throw new InvalidOperationException("Changing the problem is only allowed if the CrossValidation is stopped or prepared.");
|
---|
157 | if (algorithm == null) throw new ArgumentNullException("Could not set a problem before an algorithm was set.");
|
---|
158 | algorithm.Problem = value;
|
---|
159 | problem = value;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | IProblem IAlgorithm.Problem {
|
---|
164 | get { return Problem; }
|
---|
165 | set {
|
---|
166 | if (value != null && !ProblemType.IsInstanceOfType(value))
|
---|
167 | throw new ArgumentException("Only DataAnalysisProblems could be used for the cross validation.");
|
---|
168 | Problem = (IDataAnalysisProblem)value;
|
---|
169 | }
|
---|
170 | }
|
---|
171 | public Type ProblemType {
|
---|
172 | get { return typeof(IDataAnalysisProblem); }
|
---|
173 | }
|
---|
174 |
|
---|
175 | [Storable]
|
---|
176 | private ItemCollection<IAlgorithm> clonedAlgorithms;
|
---|
177 |
|
---|
178 | public IEnumerable<IOptimizer> NestedOptimizers {
|
---|
179 | get {
|
---|
180 | if (Algorithm == null) yield break;
|
---|
181 | yield return Algorithm;
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | [Storable]
|
---|
186 | private ResultCollection results;
|
---|
187 | public ResultCollection Results {
|
---|
188 | get { return results; }
|
---|
189 | }
|
---|
190 | [Storable]
|
---|
191 | private BoolValue shuffleSamples;
|
---|
192 | public BoolValue ShuffleSamples {
|
---|
193 | get { return shuffleSamples; }
|
---|
194 | }
|
---|
195 | [Storable]
|
---|
196 | private IntValue folds;
|
---|
197 | public IntValue Folds {
|
---|
198 | get { return folds; }
|
---|
199 | }
|
---|
200 | [Storable]
|
---|
201 | private IntValue samplesStart;
|
---|
202 | public IntValue SamplesStart {
|
---|
203 | get { return samplesStart; }
|
---|
204 | }
|
---|
205 | [Storable]
|
---|
206 | private IntValue samplesEnd;
|
---|
207 | public IntValue SamplesEnd {
|
---|
208 | get { return samplesEnd; }
|
---|
209 | }
|
---|
210 | [Storable]
|
---|
211 | private IntValue numberOfWorkers;
|
---|
212 | public IntValue NumberOfWorkers {
|
---|
213 | get { return numberOfWorkers; }
|
---|
214 | }
|
---|
215 |
|
---|
216 | [Storable]
|
---|
217 | private bool storeAlgorithmInEachRun;
|
---|
218 | public bool StoreAlgorithmInEachRun {
|
---|
219 | get { return storeAlgorithmInEachRun; }
|
---|
220 | set {
|
---|
221 | if (storeAlgorithmInEachRun != value) {
|
---|
222 | storeAlgorithmInEachRun = value;
|
---|
223 | OnStoreAlgorithmInEachRunChanged();
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | [Storable]
|
---|
229 | private int runsCounter;
|
---|
230 | [Storable]
|
---|
231 | private RunCollection runs;
|
---|
232 | public RunCollection Runs {
|
---|
233 | get { return runs; }
|
---|
234 | }
|
---|
235 |
|
---|
236 | [Storable]
|
---|
237 | private ExecutionState executionState;
|
---|
238 | public ExecutionState ExecutionState {
|
---|
239 | get { return executionState; }
|
---|
240 | private set {
|
---|
241 | if (executionState != value) {
|
---|
242 | executionState = value;
|
---|
243 | OnExecutionStateChanged();
|
---|
244 | OnItemImageChanged();
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 | public static new Image StaticItemImage {
|
---|
249 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
|
---|
250 | }
|
---|
251 | public override Image ItemImage {
|
---|
252 | get {
|
---|
253 | if (ExecutionState == ExecutionState.Prepared) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutablePrepared;
|
---|
254 | else if (ExecutionState == ExecutionState.Started) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStarted;
|
---|
255 | else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutablePaused;
|
---|
256 | else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStopped;
|
---|
257 | else return base.ItemImage;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | public TimeSpan ExecutionTime {
|
---|
262 | get {
|
---|
263 | if (ExecutionState != ExecutionState.Prepared)
|
---|
264 | return TimeSpan.FromMilliseconds(clonedAlgorithms.Select(x => x.ExecutionTime.TotalMilliseconds).Sum());
|
---|
265 | return TimeSpan.Zero;
|
---|
266 | }
|
---|
267 | }
|
---|
268 | #endregion
|
---|
269 |
|
---|
270 | protected override void OnNameChanged() {
|
---|
271 | base.OnNameChanged();
|
---|
272 | Runs.OptimizerName = Name;
|
---|
273 | }
|
---|
274 |
|
---|
275 | public void Prepare() {
|
---|
276 | if (startPending) return;
|
---|
277 | if (ExecutionState == ExecutionState.Started)
|
---|
278 | throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
|
---|
279 | results.Clear();
|
---|
280 | clonedAlgorithms.Clear();
|
---|
281 | if (Algorithm != null) {
|
---|
282 | Algorithm.Prepare();
|
---|
283 | if (Algorithm.ExecutionState == ExecutionState.Prepared) OnPrepared();
|
---|
284 | }
|
---|
285 | }
|
---|
286 | public void Prepare(bool clearRuns) {
|
---|
287 | if (clearRuns) runs.Clear();
|
---|
288 | Prepare();
|
---|
289 | }
|
---|
290 |
|
---|
291 | private bool startPending;
|
---|
292 | public void Start() {
|
---|
293 | Start(CancellationToken.None);
|
---|
294 | }
|
---|
295 | public void Start(CancellationToken cancellationToken) {
|
---|
296 | lock (locker) {
|
---|
297 | if (startPending) return;
|
---|
298 | startPending = true;
|
---|
299 | }
|
---|
300 |
|
---|
301 | try {
|
---|
302 | if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
|
---|
303 | throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
|
---|
304 | seed = RandomSeedGenerator.GetSeed();
|
---|
305 |
|
---|
306 | if (Algorithm == null) return;
|
---|
307 | //create cloned algorithms
|
---|
308 | if (clonedAlgorithms.Count == 0) {
|
---|
309 | int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value;
|
---|
310 | IDataset shuffledDataset = null;
|
---|
311 | for (int i = 0; i < Folds.Value; i++) {
|
---|
312 | var cloner = new Cloner();
|
---|
313 | if (ShuffleSamples.Value) {
|
---|
314 | var random = new FastRandom(seed);
|
---|
315 | var dataAnalysisProblem = (IDataAnalysisProblem)algorithm.Problem;
|
---|
316 | var dataset = (Dataset)dataAnalysisProblem.ProblemData.Dataset;
|
---|
317 | shuffledDataset = shuffledDataset ?? dataset.Shuffle(random);
|
---|
318 | cloner.RegisterClonedObject(dataset, shuffledDataset);
|
---|
319 | }
|
---|
320 | IAlgorithm clonedAlgorithm = cloner.Clone(Algorithm);
|
---|
321 | clonedAlgorithm.Name = algorithm.Name + " Fold " + i;
|
---|
322 | IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem;
|
---|
323 | ISymbolicDataAnalysisProblem symbolicProblem = problem as ISymbolicDataAnalysisProblem;
|
---|
324 |
|
---|
325 | int testStart = (i * testSamplesCount) + SamplesStart.Value;
|
---|
326 | int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value;
|
---|
327 |
|
---|
328 | problem.ProblemData.TrainingPartition.Start = SamplesStart.Value;
|
---|
329 | problem.ProblemData.TrainingPartition.End = SamplesEnd.Value;
|
---|
330 | problem.ProblemData.TestPartition.Start = testStart;
|
---|
331 | problem.ProblemData.TestPartition.End = testEnd;
|
---|
332 | DataAnalysisProblemData problemData = problem.ProblemData as DataAnalysisProblemData;
|
---|
333 | if (problemData != null) {
|
---|
334 | problemData.TrainingPartitionParameter.Hidden = false;
|
---|
335 | problemData.TestPartitionParameter.Hidden = false;
|
---|
336 | }
|
---|
337 |
|
---|
338 | if (symbolicProblem != null) {
|
---|
339 | symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value;
|
---|
340 | symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value;
|
---|
341 | }
|
---|
342 |
|
---|
343 | // We need to set the estimation limits because they are recalculated by the problem
|
---|
344 | // whenever the data partitions change.
|
---|
345 | // Instead of explicitly handling all types we could also check the parameters-collection
|
---|
346 | // for a parameter with name "EstimationLimits".
|
---|
347 | SetEstimationLimits(problem, new[] { typeof(SymbolicRegressionSingleObjectiveProblem),
|
---|
348 | typeof(SymbolicRegressionMultiObjectiveProblem),
|
---|
349 | typeof(SymbolicClassificationSingleObjectiveProblem),
|
---|
350 | typeof(SymbolicClassificationMultiObjectiveProblem) });
|
---|
351 |
|
---|
352 | clonedAlgorithm.Prepare();
|
---|
353 | clonedAlgorithms.Add(clonedAlgorithm);
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | OnStarted();
|
---|
358 | } finally {
|
---|
359 | if (startPending) startPending = false;
|
---|
360 | }
|
---|
361 |
|
---|
362 | availableWorkers = new SemaphoreSlim(NumberOfWorkers.Value, NumberOfWorkers.Value);
|
---|
363 | allAlgorithmsFinished = new ManualResetEventSlim(false);
|
---|
364 |
|
---|
365 | var startedTasks = new List<Task>(clonedAlgorithms.Count);
|
---|
366 |
|
---|
367 | //start prepared or paused cloned algorithms
|
---|
368 | foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) {
|
---|
369 | if (pausePending || stopPending || ExecutionState != ExecutionState.Started) break;
|
---|
370 | if (clonedAlgorithm.ExecutionState == ExecutionState.Prepared ||
|
---|
371 | clonedAlgorithm.ExecutionState == ExecutionState.Paused) {
|
---|
372 | availableWorkers.Wait();
|
---|
373 | lock (locker) {
|
---|
374 | if (pausePending || stopPending || ExecutionState != ExecutionState.Started) break;
|
---|
375 | var task = clonedAlgorithm.StartAsync(cancellationToken);
|
---|
376 | startedTasks.Add(task);
|
---|
377 | }
|
---|
378 | }
|
---|
379 | }
|
---|
380 |
|
---|
381 | allAlgorithmsFinished.Wait();
|
---|
382 |
|
---|
383 | Task.WaitAll(startedTasks.ToArray()); // to get exceptions not handled within the tasks
|
---|
384 | }
|
---|
385 |
|
---|
386 | public async Task StartAsync() { await StartAsync(CancellationToken.None); }
|
---|
387 | public async Task StartAsync(CancellationToken cancellationToken) {
|
---|
388 | await AsyncHelper.DoAsync(Start, cancellationToken);
|
---|
389 | }
|
---|
390 |
|
---|
391 | private bool pausePending;
|
---|
392 | public void Pause() {
|
---|
393 | if (startPending) return;
|
---|
394 | if (ExecutionState != ExecutionState.Started)
|
---|
395 | throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
|
---|
396 | if (!pausePending) {
|
---|
397 | pausePending = true;
|
---|
398 | lock (locker) {
|
---|
399 | var toPause = clonedAlgorithms.Where(x => x.ExecutionState == ExecutionState.Started).ToList();
|
---|
400 | foreach (var optimizer in toPause) {
|
---|
401 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
402 | try { optimizer.Pause(); } catch (InvalidOperationException) { }
|
---|
403 | }
|
---|
404 | }
|
---|
405 | }
|
---|
406 | }
|
---|
407 |
|
---|
408 | private bool stopPending;
|
---|
409 | public void Stop() {
|
---|
410 | if (startPending) return;
|
---|
411 | if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
|
---|
412 | throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".",
|
---|
413 | ExecutionState));
|
---|
414 | if (!stopPending) {
|
---|
415 | stopPending = true;
|
---|
416 | lock (locker) {
|
---|
417 | var toStop = clonedAlgorithms.Where(x => x.ExecutionState == ExecutionState.Started || x.ExecutionState == ExecutionState.Paused).ToList();
|
---|
418 | foreach (var optimizer in toStop) {
|
---|
419 | // a race-condition may occur when the optimizer has changed the state by itself in the meantime
|
---|
420 | try { optimizer.Stop(); } catch (InvalidOperationException) { }
|
---|
421 | }
|
---|
422 | }
|
---|
423 | }
|
---|
424 | }
|
---|
425 |
|
---|
426 | #region collect parameters and results
|
---|
427 | public override void CollectParameterValues(IDictionary<string, IItem> values) {
|
---|
428 | values.Add("Algorithm Name", new StringValue(Name));
|
---|
429 | values.Add("Algorithm Type", new StringValue(GetType().GetPrettyName()));
|
---|
430 | values.Add("Folds", new IntValue(Folds.Value));
|
---|
431 |
|
---|
432 | if (algorithm != null) {
|
---|
433 | values.Add("CrossValidation Algorithm Name", new StringValue(Algorithm.Name));
|
---|
434 | values.Add("CrossValidation Algorithm Type", new StringValue(Algorithm.GetType().GetPrettyName()));
|
---|
435 | base.CollectParameterValues(values);
|
---|
436 | }
|
---|
437 | if (Problem != null) {
|
---|
438 | values.Add("Problem Name", new StringValue(Problem.Name));
|
---|
439 | values.Add("Problem Type", new StringValue(Problem.GetType().GetPrettyName()));
|
---|
440 | Problem.CollectParameterValues(values);
|
---|
441 | }
|
---|
442 | }
|
---|
443 |
|
---|
444 | public void CollectResultValues(IDictionary<string, IItem> results) {
|
---|
445 | var clonedResults = (ResultCollection)this.results.Clone();
|
---|
446 | foreach (var result in clonedResults) {
|
---|
447 | results.Add(result.Name, result.Value);
|
---|
448 | }
|
---|
449 | }
|
---|
450 |
|
---|
451 | private void AggregateResultValues(IDictionary<string, IItem> results) {
|
---|
452 | IEnumerable<IRun> runs = clonedAlgorithms.Select(alg => alg.Runs.FirstOrDefault()).Where(run => run != null);
|
---|
453 | IEnumerable<KeyValuePair<string, IItem>> resultCollections = runs.Where(x => x != null).SelectMany(x => x.Results).ToList();
|
---|
454 |
|
---|
455 | foreach (IResult result in ExtractAndAggregateResults<IntValue>(resultCollections))
|
---|
456 | results.Add(result.Name, result.Value);
|
---|
457 | foreach (IResult result in ExtractAndAggregateResults<DoubleValue>(resultCollections))
|
---|
458 | results.Add(result.Name, result.Value);
|
---|
459 | foreach (IResult result in ExtractAndAggregateResults<PercentValue>(resultCollections))
|
---|
460 | results.Add(result.Name, result.Value);
|
---|
461 | foreach (IResult result in ExtractAndAggregateRegressionSolutions(resultCollections)) {
|
---|
462 | results.Add(result.Name, result.Value);
|
---|
463 | }
|
---|
464 | foreach (IResult result in ExtractAndAggregateClassificationSolutions(resultCollections)) {
|
---|
465 | results.Add(result.Name, result.Value);
|
---|
466 | }
|
---|
467 | results.Add("Execution Time", new TimeSpanValue(this.ExecutionTime));
|
---|
468 | results.Add("CrossValidation Folds", new RunCollection(runs));
|
---|
469 | }
|
---|
470 |
|
---|
471 | private IEnumerable<IResult> ExtractAndAggregateRegressionSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
|
---|
472 | Dictionary<string, List<IRegressionSolution>> resultSolutions = new Dictionary<string, List<IRegressionSolution>>();
|
---|
473 | foreach (var result in resultCollections) {
|
---|
474 | var regressionSolution = result.Value as IRegressionSolution;
|
---|
475 | if (regressionSolution != null) {
|
---|
476 | if (resultSolutions.ContainsKey(result.Key)) {
|
---|
477 | resultSolutions[result.Key].Add(regressionSolution);
|
---|
478 | } else {
|
---|
479 | resultSolutions.Add(result.Key, new List<IRegressionSolution>() { regressionSolution });
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 | List<IResult> aggregatedResults = new List<IResult>();
|
---|
484 | foreach (KeyValuePair<string, List<IRegressionSolution>> solutions in resultSolutions) {
|
---|
485 | // clone manually to correctly clone references between cloned root objects
|
---|
486 | Cloner cloner = new Cloner();
|
---|
487 | if (ShuffleSamples.Value) {
|
---|
488 | var dataset = (Dataset)Problem.ProblemData.Dataset;
|
---|
489 | var random = new FastRandom(seed);
|
---|
490 | var shuffledDataset = dataset.Shuffle(random);
|
---|
491 | cloner.RegisterClonedObject(dataset, shuffledDataset);
|
---|
492 | }
|
---|
493 | var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData);
|
---|
494 | // set partitions of problem data clone correctly
|
---|
495 | problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
|
---|
496 | problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
|
---|
497 | // clone models
|
---|
498 | var ensembleSolution = new RegressionEnsembleSolution(problemDataClone);
|
---|
499 | ensembleSolution.AddRegressionSolutions(solutions.Value);
|
---|
500 |
|
---|
501 | aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
|
---|
502 | }
|
---|
503 | List<IResult> flattenedResults = new List<IResult>();
|
---|
504 | CollectResultsRecursively("", aggregatedResults, flattenedResults);
|
---|
505 | return flattenedResults;
|
---|
506 | }
|
---|
507 |
|
---|
508 | private IEnumerable<IResult> ExtractAndAggregateClassificationSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
|
---|
509 | Dictionary<string, List<IClassificationSolution>> resultSolutions = new Dictionary<string, List<IClassificationSolution>>();
|
---|
510 | foreach (var result in resultCollections) {
|
---|
511 | var classificationSolution = result.Value as IClassificationSolution;
|
---|
512 | if (classificationSolution != null) {
|
---|
513 | if (resultSolutions.ContainsKey(result.Key)) {
|
---|
514 | resultSolutions[result.Key].Add(classificationSolution);
|
---|
515 | } else {
|
---|
516 | resultSolutions.Add(result.Key, new List<IClassificationSolution>() { classificationSolution });
|
---|
517 | }
|
---|
518 | }
|
---|
519 | }
|
---|
520 | var aggregatedResults = new List<IResult>();
|
---|
521 | foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
|
---|
522 | // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem.
|
---|
523 | var dataset = (Dataset)Problem.ProblemData.Dataset;
|
---|
524 | if (ShuffleSamples.Value) {
|
---|
525 | var random = new FastRandom(seed);
|
---|
526 | dataset = dataset.Shuffle(random);
|
---|
527 | }
|
---|
528 | var problemData = (IClassificationProblemData)Problem.ProblemData;
|
---|
529 | var problemDataClone = new ClassificationProblemData(dataset, problemData.AllowedInputVariables, problemData.TargetVariable, problemData.ClassNames, problemData.PositiveClass);
|
---|
530 | // set partitions of problem data clone correctly
|
---|
531 | problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
|
---|
532 | problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
|
---|
533 | problemDataClone.PositiveClass = problemData.PositiveClass;
|
---|
534 | // clone models
|
---|
535 | var ensembleSolution = new ClassificationEnsembleSolution(problemDataClone);
|
---|
536 | ensembleSolution.AddClassificationSolutions(solutions.Value);
|
---|
537 |
|
---|
538 | aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
|
---|
539 | }
|
---|
540 | List<IResult> flattenedResults = new List<IResult>();
|
---|
541 | CollectResultsRecursively("", aggregatedResults, flattenedResults);
|
---|
542 | return flattenedResults;
|
---|
543 | }
|
---|
544 |
|
---|
545 | private void CollectResultsRecursively(string path, IEnumerable<IResult> results, IList<IResult> flattenedResults) {
|
---|
546 | foreach (IResult result in results) {
|
---|
547 | flattenedResults.Add(new Result(path + result.Name, result.Value));
|
---|
548 | ResultCollection childCollection = result.Value as ResultCollection;
|
---|
549 | if (childCollection != null) {
|
---|
550 | CollectResultsRecursively(path + result.Name + ".", childCollection, flattenedResults);
|
---|
551 | }
|
---|
552 | }
|
---|
553 | }
|
---|
554 |
|
---|
555 | private static IEnumerable<IResult> ExtractAndAggregateResults<T>(IEnumerable<KeyValuePair<string, IItem>> results)
|
---|
556 | where T : class, IItem, new() {
|
---|
557 | Dictionary<string, List<double>> resultValues = new Dictionary<string, List<double>>();
|
---|
558 | foreach (var resultValue in results.Where(r => r.Value.GetType() == typeof(T))) {
|
---|
559 | if (!resultValues.ContainsKey(resultValue.Key))
|
---|
560 | resultValues[resultValue.Key] = new List<double>();
|
---|
561 | resultValues[resultValue.Key].Add(ConvertToDouble(resultValue.Value));
|
---|
562 | }
|
---|
563 |
|
---|
564 | DoubleValue doubleValue;
|
---|
565 | if (typeof(T) == typeof(PercentValue))
|
---|
566 | doubleValue = new PercentValue();
|
---|
567 | else if (typeof(T) == typeof(DoubleValue))
|
---|
568 | doubleValue = new DoubleValue();
|
---|
569 | else if (typeof(T) == typeof(IntValue))
|
---|
570 | doubleValue = new DoubleValue();
|
---|
571 | else
|
---|
572 | throw new NotSupportedException();
|
---|
573 |
|
---|
574 | List<IResult> aggregatedResults = new List<IResult>();
|
---|
575 | foreach (KeyValuePair<string, List<double>> resultValue in resultValues) {
|
---|
576 | doubleValue.Value = resultValue.Value.Average();
|
---|
577 | aggregatedResults.Add(new Result(resultValue.Key + " (average)", (IItem)doubleValue.Clone()));
|
---|
578 | doubleValue.Value = resultValue.Value.StandardDeviation();
|
---|
579 | aggregatedResults.Add(new Result(resultValue.Key + " (std.dev.)", (IItem)doubleValue.Clone()));
|
---|
580 | }
|
---|
581 | return aggregatedResults;
|
---|
582 | }
|
---|
583 |
|
---|
584 | private static double ConvertToDouble(IItem item) {
|
---|
585 | if (item is DoubleValue) return ((DoubleValue)item).Value;
|
---|
586 | else if (item is IntValue) return ((IntValue)item).Value;
|
---|
587 | else throw new NotSupportedException("Could not convert any item type to double");
|
---|
588 | }
|
---|
589 | #endregion
|
---|
590 |
|
---|
591 | #region events
|
---|
592 | private void RegisterEvents() {
|
---|
593 | Folds.ValueChanged += new EventHandler(Folds_ValueChanged);
|
---|
594 | RegisterClonedAlgorithmsEvents();
|
---|
595 | }
|
---|
596 | private void Folds_ValueChanged(object sender, EventArgs e) {
|
---|
597 | if (ExecutionState != ExecutionState.Prepared)
|
---|
598 | throw new InvalidOperationException("Can not change number of folds if the execution state is not prepared.");
|
---|
599 | }
|
---|
600 |
|
---|
601 |
|
---|
602 | #region template algorithms events
|
---|
603 | public event EventHandler AlgorithmChanged;
|
---|
604 | private void OnAlgorithmChanged() {
|
---|
605 | EventHandler handler = AlgorithmChanged;
|
---|
606 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
607 | OnProblemChanged();
|
---|
608 | if (Problem == null) ExecutionState = ExecutionState.Stopped;
|
---|
609 | }
|
---|
610 | private void RegisterAlgorithmEvents() {
|
---|
611 | algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged);
|
---|
612 | algorithm.ExecutionStateChanged += new EventHandler(Algorithm_ExecutionStateChanged);
|
---|
613 | if (Problem != null) {
|
---|
614 | Problem.Reset += new EventHandler(Problem_Reset);
|
---|
615 | }
|
---|
616 | }
|
---|
617 | private void DeregisterAlgorithmEvents() {
|
---|
618 | algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged);
|
---|
619 | algorithm.ExecutionStateChanged -= new EventHandler(Algorithm_ExecutionStateChanged);
|
---|
620 | if (Problem != null) {
|
---|
621 | Problem.Reset -= new EventHandler(Problem_Reset);
|
---|
622 | }
|
---|
623 | }
|
---|
624 | private void Algorithm_ProblemChanged(object sender, EventArgs e) {
|
---|
625 | if (algorithm.Problem != null && !(algorithm.Problem is IDataAnalysisProblem)) {
|
---|
626 | algorithm.Problem = problem;
|
---|
627 | throw new ArgumentException("A cross validation algorithm can only contain DataAnalysisProblems.");
|
---|
628 | }
|
---|
629 | if (problem != null) problem.Reset -= new EventHandler(Problem_Reset);
|
---|
630 | problem = (IDataAnalysisProblem)algorithm.Problem;
|
---|
631 | if (problem != null) problem.Reset += new EventHandler(Problem_Reset);
|
---|
632 | OnProblemChanged();
|
---|
633 | }
|
---|
634 | public event EventHandler ProblemChanged;
|
---|
635 | private void OnProblemChanged() {
|
---|
636 | EventHandler handler = ProblemChanged;
|
---|
637 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
638 | ConfigureProblem();
|
---|
639 | }
|
---|
640 | private void Problem_Reset(object sender, EventArgs e) {
|
---|
641 | ConfigureProblem();
|
---|
642 | }
|
---|
643 | private void ConfigureProblem() {
|
---|
644 | SamplesStart.Value = 0;
|
---|
645 | if (Problem != null) {
|
---|
646 | SamplesEnd.Value = Problem.ProblemData.Dataset.Rows;
|
---|
647 |
|
---|
648 | DataAnalysisProblemData problemData = Problem.ProblemData as DataAnalysisProblemData;
|
---|
649 | if (problemData != null) {
|
---|
650 | problemData.TrainingPartitionParameter.Hidden = true;
|
---|
651 | problemData.TestPartitionParameter.Hidden = true;
|
---|
652 | }
|
---|
653 | ISymbolicDataAnalysisProblem symbolicProblem = Problem as ISymbolicDataAnalysisProblem;
|
---|
654 | if (symbolicProblem != null) {
|
---|
655 | symbolicProblem.FitnessCalculationPartitionParameter.Hidden = true;
|
---|
656 | symbolicProblem.FitnessCalculationPartition.Start = SamplesStart.Value;
|
---|
657 | symbolicProblem.FitnessCalculationPartition.End = SamplesEnd.Value;
|
---|
658 | symbolicProblem.ValidationPartitionParameter.Hidden = true;
|
---|
659 | symbolicProblem.ValidationPartition.Start = 0;
|
---|
660 | symbolicProblem.ValidationPartition.End = 0;
|
---|
661 | }
|
---|
662 | } else
|
---|
663 | SamplesEnd.Value = 0;
|
---|
664 | }
|
---|
665 |
|
---|
666 | private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
667 | switch (Algorithm.ExecutionState) {
|
---|
668 | case ExecutionState.Prepared:
|
---|
669 | OnPrepared();
|
---|
670 | break;
|
---|
671 | case ExecutionState.Started: throw new InvalidOperationException("Algorithm template can not be started.");
|
---|
672 | case ExecutionState.Paused: throw new InvalidOperationException("Algorithm template can not be paused.");
|
---|
673 | case ExecutionState.Stopped:
|
---|
674 | OnStopped();
|
---|
675 | break;
|
---|
676 | }
|
---|
677 | }
|
---|
678 | #endregion
|
---|
679 |
|
---|
680 | #region clonedAlgorithms events
|
---|
681 | private void RegisterClonedAlgorithmsEvents() {
|
---|
682 | clonedAlgorithms.ItemsAdded += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsAdded);
|
---|
683 | clonedAlgorithms.ItemsRemoved += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsRemoved);
|
---|
684 | clonedAlgorithms.CollectionReset += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_CollectionReset);
|
---|
685 | foreach (IAlgorithm algorithm in clonedAlgorithms)
|
---|
686 | RegisterClonedAlgorithmEvents(algorithm);
|
---|
687 | }
|
---|
688 | private void DeregisterClonedAlgorithmsEvents() {
|
---|
689 | clonedAlgorithms.ItemsAdded -= new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsAdded);
|
---|
690 | clonedAlgorithms.ItemsRemoved -= new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsRemoved);
|
---|
691 | clonedAlgorithms.CollectionReset -= new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_CollectionReset);
|
---|
692 | foreach (IAlgorithm algorithm in clonedAlgorithms)
|
---|
693 | DeregisterClonedAlgorithmEvents(algorithm);
|
---|
694 | }
|
---|
695 | private void ClonedAlgorithms_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) {
|
---|
696 | foreach (IAlgorithm algorithm in e.Items)
|
---|
697 | RegisterClonedAlgorithmEvents(algorithm);
|
---|
698 | }
|
---|
699 | private void ClonedAlgorithms_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) {
|
---|
700 | foreach (IAlgorithm algorithm in e.Items)
|
---|
701 | DeregisterClonedAlgorithmEvents(algorithm);
|
---|
702 | }
|
---|
703 | private void ClonedAlgorithms_CollectionReset(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) {
|
---|
704 | foreach (IAlgorithm algorithm in e.OldItems)
|
---|
705 | DeregisterClonedAlgorithmEvents(algorithm);
|
---|
706 | foreach (IAlgorithm algorithm in e.Items)
|
---|
707 | RegisterClonedAlgorithmEvents(algorithm);
|
---|
708 | }
|
---|
709 | private void RegisterClonedAlgorithmEvents(IAlgorithm algorithm) {
|
---|
710 | algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred);
|
---|
711 | algorithm.ExecutionTimeChanged += new EventHandler(ClonedAlgorithm_ExecutionTimeChanged);
|
---|
712 | algorithm.Started += new EventHandler(ClonedAlgorithm_Started);
|
---|
713 | algorithm.Paused += new EventHandler(ClonedAlgorithm_Paused);
|
---|
714 | algorithm.Stopped += new EventHandler(ClonedAlgorithm_Stopped);
|
---|
715 | }
|
---|
716 | private void DeregisterClonedAlgorithmEvents(IAlgorithm algorithm) {
|
---|
717 | algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred);
|
---|
718 | algorithm.ExecutionTimeChanged -= new EventHandler(ClonedAlgorithm_ExecutionTimeChanged);
|
---|
719 | algorithm.Started -= new EventHandler(ClonedAlgorithm_Started);
|
---|
720 | algorithm.Paused -= new EventHandler(ClonedAlgorithm_Paused);
|
---|
721 | algorithm.Stopped -= new EventHandler(ClonedAlgorithm_Stopped);
|
---|
722 | }
|
---|
723 | private void ClonedAlgorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
724 | Pause();
|
---|
725 | OnExceptionOccurred(e.Value);
|
---|
726 | }
|
---|
727 | private void ClonedAlgorithm_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
728 | OnExecutionTimeChanged();
|
---|
729 | }
|
---|
730 |
|
---|
731 | private readonly object locker = new object();
|
---|
732 | private readonly object resultLocker = new object();
|
---|
733 | private void ClonedAlgorithm_Started(object sender, EventArgs e) {
|
---|
734 | IAlgorithm algorithm = sender as IAlgorithm;
|
---|
735 | lock (resultLocker) {
|
---|
736 | if (algorithm != null && !results.ContainsKey(algorithm.Name))
|
---|
737 | results.Add(new Result(algorithm.Name, "Contains results for the specific fold.", algorithm.Results));
|
---|
738 | }
|
---|
739 | }
|
---|
740 |
|
---|
741 | private void ClonedAlgorithm_Paused(object sender, EventArgs e) {
|
---|
742 | lock (locker) {
|
---|
743 | availableWorkers.Release();
|
---|
744 | if (clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Started)) {
|
---|
745 | OnPaused();
|
---|
746 | allAlgorithmsFinished.Set();
|
---|
747 | }
|
---|
748 | }
|
---|
749 | }
|
---|
750 |
|
---|
751 | private void ClonedAlgorithm_Stopped(object sender, EventArgs e) {
|
---|
752 | lock (locker) {
|
---|
753 | // if the algorithm was in paused state, its worker has already been released
|
---|
754 | if (availableWorkers.CurrentCount < NumberOfWorkers.Value)
|
---|
755 | availableWorkers.Release();
|
---|
756 | if (clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Stopped)) {
|
---|
757 | OnStopped();
|
---|
758 | allAlgorithmsFinished.Set();
|
---|
759 | } else if (stopPending && clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Prepared || alg.ExecutionState == ExecutionState.Stopped)) {
|
---|
760 | OnStopped();
|
---|
761 | allAlgorithmsFinished.Set();
|
---|
762 | }
|
---|
763 | }
|
---|
764 | }
|
---|
765 | #endregion
|
---|
766 | #endregion
|
---|
767 |
|
---|
768 | #region event firing
|
---|
769 | public event EventHandler ExecutionStateChanged;
|
---|
770 | private void OnExecutionStateChanged() {
|
---|
771 | EventHandler handler = ExecutionStateChanged;
|
---|
772 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
773 | }
|
---|
774 | public event EventHandler ExecutionTimeChanged;
|
---|
775 | private void OnExecutionTimeChanged() {
|
---|
776 | EventHandler handler = ExecutionTimeChanged;
|
---|
777 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
778 | }
|
---|
779 | public event EventHandler Prepared;
|
---|
780 | private void OnPrepared() {
|
---|
781 | ExecutionState = ExecutionState.Prepared;
|
---|
782 | EventHandler handler = Prepared;
|
---|
783 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
784 | OnExecutionTimeChanged();
|
---|
785 | }
|
---|
786 | public event EventHandler Started;
|
---|
787 | private void OnStarted() {
|
---|
788 | startPending = false;
|
---|
789 | ExecutionState = ExecutionState.Started;
|
---|
790 | EventHandler handler = Started;
|
---|
791 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
792 | }
|
---|
793 | public event EventHandler Paused;
|
---|
794 | private void OnPaused() {
|
---|
795 | pausePending = false;
|
---|
796 | ExecutionState = ExecutionState.Paused;
|
---|
797 | EventHandler handler = Paused;
|
---|
798 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
799 | }
|
---|
800 | public event EventHandler Stopped;
|
---|
801 | private void OnStopped() {
|
---|
802 | stopPending = false;
|
---|
803 | Dictionary<string, IItem> collectedResults = new Dictionary<string, IItem>();
|
---|
804 | AggregateResultValues(collectedResults);
|
---|
805 | results.AddRange(collectedResults.Select(x => new Result(x.Key, x.Value)).Cast<IResult>().ToArray());
|
---|
806 | clonedAlgorithms.Clear();
|
---|
807 | runsCounter++;
|
---|
808 | runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
|
---|
809 | ExecutionState = ExecutionState.Stopped;
|
---|
810 | EventHandler handler = Stopped;
|
---|
811 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
812 | }
|
---|
813 | public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
|
---|
814 | private void OnExceptionOccurred(Exception exception) {
|
---|
815 | EventHandler<EventArgs<Exception>> handler = ExceptionOccurred;
|
---|
816 | if (handler != null) handler(this, new EventArgs<Exception>(exception));
|
---|
817 | }
|
---|
818 | public event EventHandler StoreAlgorithmInEachRunChanged;
|
---|
819 | private void OnStoreAlgorithmInEachRunChanged() {
|
---|
820 | EventHandler handler = StoreAlgorithmInEachRunChanged;
|
---|
821 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
822 | }
|
---|
823 | #endregion
|
---|
824 |
|
---|
825 | #region helper
|
---|
826 |
|
---|
827 | private void SetEstimationLimits(IDataAnalysisProblem problem, Type[] types) {
|
---|
828 | foreach (var type in types) {
|
---|
829 | if (type.IsAssignableFrom(problem.GetType())) {
|
---|
830 | var originalLimits = (DoubleLimit)Problem.Parameters["EstimationLimits"].ActualValue; // problem is a clone of Problem
|
---|
831 | var limits = (DoubleLimit)problem.Parameters["EstimationLimits"].ActualValue;
|
---|
832 | limits.Lower = originalLimits.Lower;
|
---|
833 | limits.Upper = originalLimits.Upper;
|
---|
834 | }
|
---|
835 | }
|
---|
836 | }
|
---|
837 |
|
---|
838 | #endregion
|
---|
839 | }
|
---|
840 | }
|
---|