Changeset 15002
- Timestamp:
- 05/30/17 15:03:51 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.cs
r14864 r15002 137 137 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused); 138 138 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started; 139 shuffleSamplesCheckBox.Checked = Content.ShuffleSamples.Value; 140 // prevent changing the shuffle if the algorithm is not finished 141 shuffleSamplesCheckBox.Enabled = Content.ExecutionState == ExecutionState.Prepared || 142 Content.ExecutionState == ExecutionState.Stopped; 139 143 } 140 144 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r14904 r15002 40 40 [StorableClass] 41 41 public sealed class CrossValidation : ParameterizedNamedItem, IAlgorithm, IStorableContent { 42 private IDataAnalysisProblemData shuffledProblemData; 42 [Storable] 43 private int seed; 43 44 44 45 public CrossValidation() … … 94 95 samplesEnd = cloner.Clone(original.samplesEnd); 95 96 shuffleSamples = cloner.Clone(original.shuffleSamples); 97 seed = original.seed; 98 96 99 RegisterEvents(); 97 100 if (Algorithm != null) RegisterAlgorithmEvents(); … … 279 282 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 280 283 284 seed = new FastRandom().NextInt(); 285 281 286 if (Algorithm != null) { 282 287 //create cloned algorithms … … 287 292 var cloner = new Cloner(); 288 293 if (ShuffleSamples.Value) { 294 var random = new FastRandom(seed); 289 295 var dataAnalysisProblem = (IDataAnalysisProblem)algorithm.Problem; 290 296 var dataset = (Dataset)dataAnalysisProblem.ProblemData.Dataset; 291 shuffledDataset = shuffledDataset ?? dataset.Shuffle( new FastRandom());297 shuffledDataset = shuffledDataset ?? dataset.Shuffle(random); 292 298 cloner.RegisterClonedObject(dataset, shuffledDataset); 293 299 } … … 316 322 clonedAlgorithm.Prepare(); 317 323 clonedAlgorithms.Add(clonedAlgorithm); 318 }319 // save the shuffled problem data because it is necessary when creating the ensemble solution320 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 324 } 327 325 } … … 446 444 // clone manually to correctly clone references between cloned root objects 447 445 Cloner cloner = new Cloner(); 448 var problemDataClone = ShuffleSamples.Value 449 ? (IRegressionProblemData)cloner.Clone(shuffledProblemData) 450 : (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 446 if (ShuffleSamples.Value) { 447 var dataset = (Dataset)Problem.ProblemData.Dataset; 448 var random = new FastRandom(seed); 449 var shuffledDataset = dataset.Shuffle(random); 450 cloner.RegisterClonedObject(dataset, shuffledDataset); 451 } 452 var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 451 453 // set partitions of problem data clone correctly 452 454 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 479 481 // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem. 480 482 var targetVariable = solutions.Value.First().ProblemData.TargetVariable; 481 var problemDataClone = ShuffleSamples.Value 482 ? new ClassificationProblemData(shuffledProblemData.Dataset, shuffledProblemData.AllowedInputVariables, targetVariable) 483 : new ClassificationProblemData(Problem.ProblemData.Dataset, Problem.ProblemData.AllowedInputVariables, targetVariable); 483 var dataset = (Dataset)Problem.ProblemData.Dataset; 484 if (ShuffleSamples.Value) { 485 var random = new FastRandom(seed); 486 dataset = dataset.Shuffle(random); 487 } 488 var problemDataClone = new ClassificationProblemData(dataset, Problem.ProblemData.AllowedInputVariables, targetVariable); 484 489 // set partitions of problem data clone correctly 485 490 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 566 571 if (Problem != null) { 567 572 Problem.Reset += new EventHandler(Problem_Reset); 568 Problem.ProblemDataChanged += Problem_ProblemDataChanged;569 573 } 570 574 } … … 574 578 if (Problem != null) { 575 579 Problem.Reset -= new EventHandler(Problem_Reset); 576 Problem.ProblemDataChanged -= Problem_ProblemDataChanged;577 580 } 578 581 } … … 592 595 if (handler != null) handler(this, EventArgs.Empty); 593 596 ConfigureProblem(); 594 }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 597 } 604 598 private void Problem_Reset(object sender, EventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.