Changeset 15150
- Timestamp:
- 07/06/17 11:39:20 (7 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.Designer.cs
r14186 r15150 79 79 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 80 80 this.splitContainer = new System.Windows.Forms.SplitContainer(); 81 this.shuffleSamplesCheckBox = new System.Windows.Forms.CheckBox(); 81 82 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 82 83 ((System.ComponentModel.ISupportInitialize)(this.foldsNumericUpDown)).BeginInit(); … … 172 173 // 173 174 this.foldsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 174 175 | System.Windows.Forms.AnchorStyles.Right))); 175 176 this.foldsNumericUpDown.Location = new System.Drawing.Point(55, 26); 176 177 this.foldsNumericUpDown.Maximum = new decimal(new int[] { … … 185 186 0}); 186 187 this.foldsNumericUpDown.Name = "foldsNumericUpDown"; 187 this.foldsNumericUpDown.Size = new System.Drawing.Size( 248, 20);188 this.foldsNumericUpDown.Size = new System.Drawing.Size(154, 20); 188 189 this.foldsNumericUpDown.TabIndex = 3; 189 190 this.foldsNumericUpDown.ThousandsSeparator = true; … … 208 209 // 209 210 this.workersNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 210 211 | System.Windows.Forms.AnchorStyles.Right))); 211 212 this.workersNumericUpDown.Location = new System.Drawing.Point(55, 0); 212 213 this.workersNumericUpDown.Maximum = new decimal(new int[] { … … 262 263 // 263 264 this.samplesEndStringConvertibleValueView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 264 265 | System.Windows.Forms.AnchorStyles.Right))); 265 266 this.samplesEndStringConvertibleValueView.Caption = "StringConvertibleValue View"; 266 267 this.samplesEndStringConvertibleValueView.Content = null; … … 275 276 // 276 277 this.samplesStartStringConvertibleValueView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 277 278 | System.Windows.Forms.AnchorStyles.Right))); 278 279 this.samplesStartStringConvertibleValueView.Caption = "StringConvertibleValue View"; 279 280 this.samplesStartStringConvertibleValueView.Content = null; … … 289 290 this.tabControl.AllowDrop = true; 290 291 this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 291 292 292 | System.Windows.Forms.AnchorStyles.Left) 293 | System.Windows.Forms.AnchorStyles.Right))); 293 294 this.tabControl.Controls.Add(this.algorithmTabPage); 294 295 this.tabControl.Controls.Add(this.resultsTabPage); 295 296 this.tabControl.Controls.Add(this.runsTabPage); 296 this.tabControl.Location = new System.Drawing.Point(0, 87);297 this.tabControl.Location = new System.Drawing.Point(0, 115); 297 298 this.tabControl.Name = "tabControl"; 298 299 this.tabControl.SelectedIndex = 0; 299 this.tabControl.Size = new System.Drawing.Size(616, 421);300 this.tabControl.Size = new System.Drawing.Size(616, 393); 300 301 this.tabControl.TabIndex = 4; 301 302 // … … 310 311 this.algorithmTabPage.Name = "algorithmTabPage"; 311 312 this.algorithmTabPage.Padding = new System.Windows.Forms.Padding(3); 312 this.algorithmTabPage.Size = new System.Drawing.Size(608, 3 95);313 this.algorithmTabPage.Size = new System.Drawing.Size(608, 367); 313 314 this.algorithmTabPage.TabIndex = 0; 314 315 this.algorithmTabPage.Text = "Algorithm"; … … 321 322 // 322 323 this.algorithmNamedItemView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 323 324 | System.Windows.Forms.AnchorStyles.Right))); 324 325 this.algorithmNamedItemView.Caption = "NamedItem View"; 325 326 this.algorithmNamedItemView.Content = null; … … 334 335 this.algorithmTabControl.AllowDrop = true; 335 336 this.algorithmTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 336 337 337 | System.Windows.Forms.AnchorStyles.Left) 338 | System.Windows.Forms.AnchorStyles.Right))); 338 339 this.algorithmTabControl.Controls.Add(this.algorithmProblemTabPage); 339 340 this.algorithmTabControl.Controls.Add(this.algorithmParametersTabPage); … … 341 342 this.algorithmTabControl.Name = "algorithmTabControl"; 342 343 this.algorithmTabControl.SelectedIndex = 0; 343 this.algorithmTabControl.Size = new System.Drawing.Size(594, 324);344 this.algorithmTabControl.Size = new System.Drawing.Size(594, 296); 344 345 this.algorithmTabControl.TabIndex = 3; 345 346 // … … 353 354 this.algorithmProblemTabPage.Name = "algorithmProblemTabPage"; 354 355 this.algorithmProblemTabPage.Padding = new System.Windows.Forms.Padding(3); 355 this.algorithmProblemTabPage.Size = new System.Drawing.Size(586, 2 98);356 this.algorithmProblemTabPage.Size = new System.Drawing.Size(586, 270); 356 357 this.algorithmProblemTabPage.TabIndex = 0; 357 358 this.algorithmProblemTabPage.Text = "Problem"; … … 375 376 // 376 377 this.algorithmProblemViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 377 378 378 | System.Windows.Forms.AnchorStyles.Left) 379 | System.Windows.Forms.AnchorStyles.Right))); 379 380 this.algorithmProblemViewHost.Caption = "View"; 380 381 this.algorithmProblemViewHost.Content = null; … … 383 384 this.algorithmProblemViewHost.Name = "algorithmProblemViewHost"; 384 385 this.algorithmProblemViewHost.ReadOnly = false; 385 this.algorithmProblemViewHost.Size = new System.Drawing.Size(574, 2 56);386 this.algorithmProblemViewHost.Size = new System.Drawing.Size(574, 228); 386 387 this.algorithmProblemViewHost.TabIndex = 2; 387 388 this.algorithmProblemViewHost.ViewsLabelVisible = true; … … 405 406 this.algorithmParametersTabPage.Name = "algorithmParametersTabPage"; 406 407 this.algorithmParametersTabPage.Padding = new System.Windows.Forms.Padding(3); 407 this.algorithmParametersTabPage.Size = new System.Drawing.Size(586, 2 98);408 this.algorithmParametersTabPage.Size = new System.Drawing.Size(586, 270); 408 409 this.algorithmParametersTabPage.TabIndex = 1; 409 410 this.algorithmParametersTabPage.Text = "Parameters"; … … 412 413 // algorithmParameterCollectionView 413 414 // 415 this.algorithmParameterCollectionView.AllowEditingOfHiddenParameters = true; 414 416 this.algorithmParameterCollectionView.Caption = "ParameterCollection View"; 415 417 this.algorithmParameterCollectionView.Content = null; … … 418 420 this.algorithmParameterCollectionView.Name = "algorithmParameterCollectionView"; 419 421 this.algorithmParameterCollectionView.ReadOnly = false; 420 this.algorithmParameterCollectionView.Size = new System.Drawing.Size(580, 292); 422 this.algorithmParameterCollectionView.ShowDetails = true; 423 this.algorithmParameterCollectionView.Size = new System.Drawing.Size(580, 264); 421 424 this.algorithmParameterCollectionView.TabIndex = 0; 422 425 // … … 449 452 this.resultsTabPage.Name = "resultsTabPage"; 450 453 this.resultsTabPage.Padding = new System.Windows.Forms.Padding(3); 451 this.resultsTabPage.Size = new System.Drawing.Size(608, 3 95);454 this.resultsTabPage.Size = new System.Drawing.Size(608, 367); 452 455 this.resultsTabPage.TabIndex = 1; 453 456 this.resultsTabPage.Text = "Results"; … … 462 465 this.resultCollectionView.Name = "resultCollectionView"; 463 466 this.resultCollectionView.ReadOnly = true; 464 this.resultCollectionView.Size = new System.Drawing.Size(602, 389); 467 this.resultCollectionView.ShowDetails = true; 468 this.resultCollectionView.Size = new System.Drawing.Size(602, 361); 465 469 this.resultCollectionView.TabIndex = 0; 466 470 // … … 472 476 this.runsTabPage.Name = "runsTabPage"; 473 477 this.runsTabPage.Padding = new System.Windows.Forms.Padding(3); 474 this.runsTabPage.Size = new System.Drawing.Size(608, 3 95);478 this.runsTabPage.Size = new System.Drawing.Size(608, 367); 475 479 this.runsTabPage.TabIndex = 2; 476 480 this.runsTabPage.Text = "Runs"; … … 501 505 this.runCollectionView.Name = "runCollectionView"; 502 506 this.runCollectionView.ReadOnly = false; 503 this.runCollectionView.Size = new System.Drawing.Size(602, 3 89);507 this.runCollectionView.Size = new System.Drawing.Size(602, 361); 504 508 this.runCollectionView.TabIndex = 0; 505 509 // … … 514 518 // 515 519 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 516 520 | System.Windows.Forms.AnchorStyles.Right))); 517 521 this.splitContainer.Location = new System.Drawing.Point(0, 26); 518 522 this.splitContainer.Name = "splitContainer"; … … 520 524 // splitContainer.Panel1 521 525 // 526 this.splitContainer.Panel1.Controls.Add(this.shuffleSamplesCheckBox); 522 527 this.splitContainer.Panel1.Controls.Add(this.samplesEndStringConvertibleValueView); 523 528 this.splitContainer.Panel1.Controls.Add(this.samplesStartStringConvertibleValueView); … … 531 536 this.splitContainer.Panel2.Controls.Add(this.workersLabel); 532 537 this.splitContainer.Panel2.Controls.Add(this.workersNumericUpDown); 533 this.splitContainer.Size = new System.Drawing.Size(616, 55);538 this.splitContainer.Size = new System.Drawing.Size(616, 73); 534 539 this.splitContainer.SplitterDistance = 306; 535 540 this.splitContainer.TabIndex = 3; 536 541 // 542 // shuffleSamplesCheckBox 543 // 544 this.shuffleSamplesCheckBox.AutoSize = true; 545 this.shuffleSamplesCheckBox.Location = new System.Drawing.Point(6, 52); 546 this.shuffleSamplesCheckBox.Name = "shuffleSamplesCheckBox"; 547 this.shuffleSamplesCheckBox.Size = new System.Drawing.Size(102, 17); 548 this.shuffleSamplesCheckBox.TabIndex = 5; 549 this.shuffleSamplesCheckBox.Text = "Shuffle Samples"; 550 this.shuffleSamplesCheckBox.UseVisualStyleBackColor = true; 551 this.shuffleSamplesCheckBox.CheckedChanged += new System.EventHandler(this.shuffleSamplesCheckBox_CheckedChanged); 552 // 537 553 // CrossValidationView 538 554 // 539 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);540 555 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 541 556 this.Controls.Add(this.tabControl); … … 617 632 private System.Windows.Forms.SplitContainer splitContainer; 618 633 private Optimization.Views.ResultCollectionView resultCollectionView; 634 private System.Windows.Forms.CheckBox shuffleSamplesCheckBox; 619 635 } 620 636 } -
stable/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.cs
r14186 r15150 61 61 runCollectionView.Content = null; 62 62 storeAlgorithmInEachRunCheckBox.Checked = true; 63 shuffleSamplesCheckBox.Checked = false; 63 64 } else { 64 65 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started; … … 74 75 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 75 76 storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun; 77 shuffleSamplesCheckBox.Checked = Content.ShuffleSamples.Value; 76 78 } 77 79 } … … 137 139 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused); 138 140 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started; 141 // prevent changing the shuffle if the algorithm is not finished 142 shuffleSamplesCheckBox.Enabled = Content.ExecutionState == ExecutionState.Prepared; 139 143 } 140 144 } … … 197 201 198 202 #region GUI events 203 private void shuffleSamplesCheckBox_CheckedChanged(object sender, EventArgs e) { 204 Content.ShuffleSamples.Value = shuffleSamplesCheckBox.Checked; 205 } 199 206 private void foldsNumericUpDown_Validated(object sender, EventArgs e) { 200 207 if (foldsNumericUpDown.Text == string.Empty) … … 238 245 try { 239 246 Content.Algorithm = (IAlgorithm)algorithmTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 240 } 241 catch (Exception ex) { 247 } catch (Exception ex) { 242 248 ErrorHandling.ShowErrorDialog(this, ex); 243 249 } … … 250 256 algorithmTabControl.Enabled = false; 251 257 252 ContentManager.LoadAsync(openFileDialog.FileName, delegate (IStorableContent content, Exception error) {258 ContentManager.LoadAsync(openFileDialog.FileName, delegate (IStorableContent content, Exception error) { 253 259 try { 254 260 if (error != null) throw error; … … 258 264 else 259 265 Content.Algorithm = algorithm; 260 } 261 catch (Exception ex) { 266 } catch (Exception ex) { 262 267 ErrorHandling.ShowErrorDialog(this, ex); 263 } 264 finally { 265 Invoke(new Action(delegate() { 268 } finally { 269 Invoke(new Action(delegate () { 266 270 algorithmTabControl.Enabled = true; 267 271 })); … … 289 293 algorithmProblemViewHost.Enabled = false; 290 294 291 ContentManager.LoadAsync(openFileDialog.FileName, delegate (IStorableContent content, Exception error) {295 ContentManager.LoadAsync(openFileDialog.FileName, delegate (IStorableContent content, Exception error) { 292 296 try { 293 297 if (error != null) throw error; … … 298 302 else 299 303 Content.Problem = problem; 300 } 301 catch (Exception ex) { 304 } catch (Exception ex) { 302 305 Invoke(new Action(() => ErrorHandling.ShowErrorDialog(this, ex))); 303 } 304 finally { 305 Invoke(new Action(delegate() { 306 } finally { 307 Invoke(new Action(delegate () { 306 308 algorithmProblemViewHost.Enabled = true; 307 309 newProblemButton.Enabled = openProblemButton.Enabled = true; … … 357 359 } 358 360 #endregion 359 360 361 } 361 362 } -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r15149 r15150 33 33 using HeuristicLab.Problems.DataAnalysis; 34 34 using HeuristicLab.Problems.DataAnalysis.Symbolic; 35 using HeuristicLab.Random; 35 36 36 37 namespace HeuristicLab.Algorithms.DataAnalysis { … … 39 40 [StorableClass] 40 41 public sealed class CrossValidation : ParameterizedNamedItem, IAlgorithm, IStorableContent { 42 [Storable] 43 private int seed; 44 41 45 public CrossValidation() 42 46 : base() { … … 56 60 samplesStart = new IntValue(0); 57 61 samplesEnd = new IntValue(0); 62 shuffleSamples = new BoolValue(false); 58 63 storeAlgorithmInEachRun = false; 59 64 … … 71 76 [StorableHook(HookType.AfterDeserialization)] 72 77 private void AfterDeserialization() { 78 // BackwardsCompatibility3.3 79 #region Backwards compatible code, remove with 3.4 80 if (shuffleSamples == null) shuffleSamples = new BoolValue(false); 81 #endregion 82 73 83 RegisterEvents(); 74 84 if (Algorithm != null) RegisterAlgorithmEvents(); … … 89 99 samplesStart = cloner.Clone(original.samplesStart); 90 100 samplesEnd = cloner.Clone(original.samplesEnd); 101 shuffleSamples = cloner.Clone(original.shuffleSamples); 102 seed = original.seed; 103 91 104 RegisterEvents(); 92 105 if (Algorithm != null) RegisterAlgorithmEvents(); … … 170 183 get { return results; } 171 184 } 172 185 [Storable] 186 private BoolValue shuffleSamples; 187 public BoolValue ShuffleSamples { 188 get { return shuffleSamples; } 189 } 173 190 [Storable] 174 191 private IntValue folds; … … 270 287 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 271 288 289 seed = new FastRandom().NextInt(); 290 272 291 if (Algorithm != null) { 273 292 //create cloned algorithms 274 293 if (clonedAlgorithms.Count == 0) { 275 294 int testSamplesCount = (SamplesEnd.Value - SamplesStart.Value) / Folds.Value; 276 295 IDataset shuffledDataset = null; 277 296 for (int i = 0; i < Folds.Value; i++) { 278 IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone(); 297 var cloner = new Cloner(); 298 if (ShuffleSamples.Value) { 299 var random = new FastRandom(seed); 300 var dataAnalysisProblem = (IDataAnalysisProblem)algorithm.Problem; 301 var dataset = (Dataset)dataAnalysisProblem.ProblemData.Dataset; 302 shuffledDataset = shuffledDataset ?? dataset.Shuffle(random); 303 cloner.RegisterClonedObject(dataset, shuffledDataset); 304 } 305 IAlgorithm clonedAlgorithm = cloner.Clone(Algorithm); 279 306 clonedAlgorithm.Name = algorithm.Name + " Fold " + i; 280 307 IDataAnalysisProblem problem = clonedAlgorithm.Problem as IDataAnalysisProblem; … … 422 449 // clone manually to correctly clone references between cloned root objects 423 450 Cloner cloner = new Cloner(); 451 if (ShuffleSamples.Value) { 452 var dataset = (Dataset)Problem.ProblemData.Dataset; 453 var random = new FastRandom(seed); 454 var shuffledDataset = dataset.Shuffle(random); 455 cloner.RegisterClonedObject(dataset, shuffledDataset); 456 } 424 457 var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 425 458 // set partitions of problem data clone correctly … … 453 486 // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem. 454 487 var targetVariable = solutions.Value.First().ProblemData.TargetVariable; 455 var problemDataClone = new ClassificationProblemData(Problem.ProblemData.Dataset, 456 Problem.ProblemData.AllowedInputVariables, targetVariable); 488 var dataset = (Dataset)Problem.ProblemData.Dataset; 489 if (ShuffleSamples.Value) { 490 var random = new FastRandom(seed); 491 dataset = dataset.Shuffle(random); 492 } 493 var problemDataClone = new ClassificationProblemData(dataset, Problem.ProblemData.AllowedInputVariables, targetVariable); 457 494 // set partitions of problem data clone correctly 458 495 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; … … 537 574 algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged); 538 575 algorithm.ExecutionStateChanged += new EventHandler(Algorithm_ExecutionStateChanged); 539 if (Problem != null) Problem.Reset += new EventHandler(Problem_Reset); 576 if (Problem != null) { 577 Problem.Reset += new EventHandler(Problem_Reset); 578 } 540 579 } 541 580 private void DeregisterAlgorithmEvents() { 542 581 algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged); 543 582 algorithm.ExecutionStateChanged -= new EventHandler(Algorithm_ExecutionStateChanged); 544 if (Problem != null) Problem.Reset -= new EventHandler(Problem_Reset); 583 if (Problem != null) { 584 Problem.Reset -= new EventHandler(Problem_Reset); 585 } 545 586 } 546 587 private void Algorithm_ProblemChanged(object sender, EventArgs e) { … … 560 601 ConfigureProblem(); 561 602 } 562 563 603 private void Problem_Reset(object sender, EventArgs e) { 564 604 ConfigureProblem(); 565 605 } 566 567 606 private void ConfigureProblem() { 568 607 SamplesStart.Value = 0; … … 590 629 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { 591 630 switch (Algorithm.ExecutionState) { 592 case ExecutionState.Prepared: OnPrepared(); 631 case ExecutionState.Prepared: 632 OnPrepared(); 593 633 break; 594 634 case ExecutionState.Started: throw new InvalidOperationException("Algorithm template can not be started."); 595 635 case ExecutionState.Paused: throw new InvalidOperationException("Algorithm template can not be paused."); 596 case ExecutionState.Stopped: OnStopped(); 636 case ExecutionState.Stopped: 637 OnStopped(); 597 638 break; 598 639 } … … 724 765 AggregateResultValues(collectedResults); 725 766 results.AddRange(collectedResults.Select(x => new Result(x.Key, x.Value)).Cast<IResult>().ToArray()); 767 clonedAlgorithms.Clear(); 726 768 runsCounter++; 727 769 runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this)); -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r15131 r15150 126 126 return new ModifiableDataset(variableNames, values); 127 127 } 128 /// <summary> 129 /// Shuffle a dataset's rows 130 /// </summary> 131 /// <param name="random">Random number generator used for shuffling.</param> 132 /// <returns>A shuffled copy of the current dataset.</returns> 133 public Dataset Shuffle(IRandom random) { 134 var values = variableNames.Select(x => variableValues[x]).ToList(); 135 return new Dataset(variableNames, values.ShuffleLists(random)); 136 } 128 137 129 138 protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
Note: See TracChangeset
for help on using the changeset viewer.