- Timestamp:
- 05/02/17 17:41:44 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r14864 r14904 40 40 [StorableClass] 41 41 public sealed class CrossValidation : ParameterizedNamedItem, IAlgorithm, IStorableContent { 42 private IDataAnalysisProblemData shuffledProblemData; 43 42 44 public CrossValidation() 43 45 : base() { … … 315 317 clonedAlgorithms.Add(clonedAlgorithm); 316 318 } 319 // save the shuffled problem data because it is necessary when creating the ensemble solution 320 if (shuffledProblemData == null && shuffledDataset != null) { 321 var dataAnalysisProblem = (IDataAnalysisProblem)algorithm.Problem; 322 var dataset = (Dataset)dataAnalysisProblem.ProblemData.Dataset; 323 var cloner = new Cloner(); 324 cloner.RegisterClonedObject(dataset, shuffledDataset); 325 shuffledProblemData = cloner.Clone(dataAnalysisProblem.ProblemData); 326 } 317 327 } 318 328 … … 436 446 // clone manually to correctly clone references between cloned root objects 437 447 Cloner cloner = new Cloner(); 438 var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 448 var problemDataClone = ShuffleSamples.Value 449 ? (IRegressionProblemData)cloner.Clone(shuffledProblemData) 450 : (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 439 451 // set partitions of problem data clone correctly 440 452 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 467 479 // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem. 468 480 var targetVariable = solutions.Value.First().ProblemData.TargetVariable; 469 var problemDataClone = new ClassificationProblemData(Problem.ProblemData.Dataset, 470 Problem.ProblemData.AllowedInputVariables, targetVariable); 481 var problemDataClone = ShuffleSamples.Value 482 ? new ClassificationProblemData(shuffledProblemData.Dataset, shuffledProblemData.AllowedInputVariables, targetVariable) 483 : new ClassificationProblemData(Problem.ProblemData.Dataset, Problem.ProblemData.AllowedInputVariables, targetVariable); 471 484 // set partitions of problem data clone correctly 472 485 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 551 564 algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged); 552 565 algorithm.ExecutionStateChanged += new EventHandler(Algorithm_ExecutionStateChanged); 553 if (Problem != null) Problem.Reset += new EventHandler(Problem_Reset); 566 if (Problem != null) { 567 Problem.Reset += new EventHandler(Problem_Reset); 568 Problem.ProblemDataChanged += Problem_ProblemDataChanged; 569 } 554 570 } 555 571 private void DeregisterAlgorithmEvents() { 556 572 algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged); 557 573 algorithm.ExecutionStateChanged -= new EventHandler(Algorithm_ExecutionStateChanged); 558 if (Problem != null) Problem.Reset -= new EventHandler(Problem_Reset); 574 if (Problem != null) { 575 Problem.Reset -= new EventHandler(Problem_Reset); 576 Problem.ProblemDataChanged -= Problem_ProblemDataChanged; 577 } 559 578 } 560 579 private void Algorithm_ProblemChanged(object sender, EventArgs e) { … … 574 593 ConfigureProblem(); 575 594 } 576 595 public event EventHandler ProblemDataChanged; 596 private void OnProblemDataChanged() { 597 var handler = ProblemDataChanged; 598 if (handler != null) handler(this, EventArgs.Empty); 599 shuffledProblemData = null; 600 } 601 private void Problem_ProblemDataChanged(object sender, EventArgs e) { 602 OnProblemDataChanged(); 603 } 577 604 private void Problem_Reset(object sender, EventArgs e) { 578 605 ConfigureProblem(); 579 606 } 580 581 607 private void ConfigureProblem() { 582 608 SamplesStart.Value = 0;
Note: See TracChangeset
for help on using the changeset viewer.