Changeset 7179
- Timestamp:
- 12/12/11 22:03:15 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.Designer.cs
r6709 r7179 47 47 this.matrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView(); 48 48 this.comboBox = new System.Windows.Forms.ComboBox(); 49 this. label1= new System.Windows.Forms.Label();49 this.foldsLabel = new System.Windows.Forms.Label(); 50 50 this.variableImpactsGroupBox = new System.Windows.Forms.GroupBox(); 51 51 this.variableImpactsGroupBox.SuspendLayout(); … … 54 54 // matrixView 55 55 // 56 this.matrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 57 | System.Windows.Forms.AnchorStyles.Left)58 56 this.matrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 57 | System.Windows.Forms.AnchorStyles.Left) 58 | System.Windows.Forms.AnchorStyles.Right))); 59 59 this.matrixView.Caption = "StringConvertibleMatrix View"; 60 60 this.matrixView.Content = null; … … 78 78 // label1 79 79 // 80 this. label1.AutoSize = true;81 this. label1.Location = new System.Drawing.Point(3, 9);82 this. label1.Name = "label1";83 this. label1.Size = new System.Drawing.Size(30, 13);84 this. label1.TabIndex = 2;85 this. label1.Text = "Fold:";80 this.foldsLabel.AutoSize = true; 81 this.foldsLabel.Location = new System.Drawing.Point(3, 9); 82 this.foldsLabel.Name = "foldsLabel"; 83 this.foldsLabel.Size = new System.Drawing.Size(30, 13); 84 this.foldsLabel.TabIndex = 2; 85 this.foldsLabel.Text = "Fold:"; 86 86 // 87 87 // variableImpactsGroupBox 88 88 // 89 this.variableImpactsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 90 | System.Windows.Forms.AnchorStyles.Left)91 89 this.variableImpactsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 90 | System.Windows.Forms.AnchorStyles.Left) 91 | System.Windows.Forms.AnchorStyles.Right))); 92 92 this.variableImpactsGroupBox.Controls.Add(this.matrixView); 93 93 this.variableImpactsGroupBox.Location = new System.Drawing.Point(0, 33); … … 103 103 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 104 104 this.Controls.Add(this.variableImpactsGroupBox); 105 this.Controls.Add(this. label1);105 this.Controls.Add(this.foldsLabel); 106 106 this.Controls.Add(this.comboBox); 107 107 this.Name = "RunCollectionVariableImpactView"; … … 117 117 private HeuristicLab.Data.Views.StringConvertibleMatrixView matrixView; 118 118 private System.Windows.Forms.ComboBox comboBox; 119 private System.Windows.Forms.Label label1;119 private System.Windows.Forms.Label foldsLabel; 120 120 private System.Windows.Forms.GroupBox variableImpactsGroupBox; 121 121 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs
r6783 r7179 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 49 50 protected override void RegisterContentEvents() { 50 51 base.RegisterContentEvents(); 51 Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);52 Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);53 Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);54 Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);52 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; 53 Content.ItemsAdded += Content_ItemsAdded; 54 Content.ItemsRemoved += Content_ItemsRemoved; 55 Content.CollectionReset += Content_CollectionReset; 55 56 RegisterRunEvents(Content); 56 57 } 57 58 protected override void DeregisterContentEvents() { 58 59 base.RegisterContentEvents(); 59 Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);60 Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);61 Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);62 Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);60 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 61 Content.ItemsAdded -= Content_ItemsAdded; 62 Content.ItemsRemoved -= Content_ItemsRemoved; 63 Content.CollectionReset -= Content_CollectionReset; 63 64 DeregisterRunEvents(Content); 64 65 } 65 66 private void RegisterRunEvents(IEnumerable<IRun> runs) { 66 67 foreach (IRun run in runs) 67 run.Changed += new EventHandler(Run_Changed);68 run.Changed += Run_Changed; 68 69 } 69 70 private void DeregisterRunEvents(IEnumerable<IRun> runs) { 70 71 foreach (IRun run in runs) 71 run.Changed -= new EventHandler(Run_Changed);72 run.Changed -= Run_Changed; 72 73 } 73 74 private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) { … … 99 100 private void comboBox_SelectedValueChanged(object sender, EventArgs e) { 100 101 if (comboBox.SelectedItem != null) { 101 var cvRuns = from r in Content 102 where r.Visible 103 where r.Parameters.ContainsKey(numberOfFoldsParameterName) 104 select r; 102 var visibleRuns = from run in Content where run.Visible select run; 105 103 if (comboBox.SelectedIndex == 0) { 106 var selectedFolds = cvRuns 107 .SelectMany(r => (RunCollection)r.Results[crossValidationFoldsResultName]) 108 .Where(r => r.Results.ContainsKey(variableImpactResultName)); 109 matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.ToArray()); 104 var selectedFolds = from r in visibleRuns 105 let foldCollection = (RunCollection)r.Results[crossValidationFoldsResultName] 106 from run in foldCollection 107 let name = (r.Name + " " + run.Name) 108 select new { run, name }; 109 matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.Select(x => x.run).ToArray(), selectedFolds.Select(x => x.name).ToArray()); 110 110 } else { 111 var selectedFolds = from r in cvRuns111 var selectedFolds = from r in visibleRuns 112 112 let foldCollection = (RunCollection)r.Results[crossValidationFoldsResultName] 113 113 let run = foldCollection.ElementAt(comboBox.SelectedIndex - 1) 114 where run.Results.ContainsKey(variableImpactResultName)115 select new { run, r.Name };116 matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.Select(x => x.run).ToArray(), selectedFolds.Select(x => x. Name).ToArray());114 let name = (r.Name + " " + run.Name) 115 select new { run, name }; 116 matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.Select(x => x.run).ToArray(), selectedFolds.Select(x => x.name).ToArray()); 117 117 } 118 118 } … … 121 121 122 122 private void UpdateData() { 123 if (Content != null) { 124 comboBox.Items.Clear(); 125 comboBox.Enabled = false; 126 var visibleRuns = Content.Where(r => r.Visible).ToArray(); 127 var representativeCvRun = 128 visibleRuns.Where(r => r.Parameters.ContainsKey(numberOfFoldsParameterName)).FirstOrDefault(); 129 if (representativeCvRun != null) { 130 // make sure all runs have the same number of folds 131 int nFolds = ((IntValue)representativeCvRun.Parameters[numberOfFoldsParameterName]).Value; 132 var cvRuns = visibleRuns.Where(r => r.Parameters.ContainsKey(numberOfFoldsParameterName)); 133 if (cvRuns.All(r => ((IntValue)r.Parameters[numberOfFoldsParameterName]).Value == nFolds)) { 123 if (InvokeRequired) { 124 Invoke((Action)UpdateData); 125 } else { 126 if (Content != null) { 127 comboBox.Items.Clear(); 128 comboBox.Enabled = false; 129 comboBox.Visible = false; 130 foldsLabel.Visible = false; 131 variableImpactsGroupBox.Dock = DockStyle.Fill; 132 var visibleRuns = Content.Where(r => r.Visible).ToArray(); 133 if (visibleRuns.Length == 0) { 134 DisplayMessage("Run collection is empty."); 135 } else if (visibleRuns.All(r => r.Parameters.ContainsKey(numberOfFoldsParameterName))) { 136 // check if all runs are comparable (CV or normal runs) 137 CheckAndUpdateCvRuns(); 138 } else if (visibleRuns.All(r => !r.Parameters.ContainsKey(numberOfFoldsParameterName))) { 139 CheckAndUpdateNormalRuns(); 140 } else { 141 // there is a mix of CV and normal runs => show an error message 142 DisplayMessage("The run collection contains a mixture of normal runs and cross-validation runs. Variable impact calculation does not work in this case."); 143 } 144 } 145 } 146 } 147 148 private void CheckAndUpdateCvRuns() { 149 var visibleRuns = from run in Content where run.Visible select run; 150 var representativeRun = visibleRuns.First(); 151 // make sure all runs have the same number of folds 152 int nFolds = ((IntValue)representativeRun.Parameters[numberOfFoldsParameterName]).Value; 153 if (visibleRuns.All(r => ((IntValue)r.Parameters[numberOfFoldsParameterName]).Value == nFolds)) { 154 var allFoldResults = visibleRuns.SelectMany(run => (RunCollection)run.Results[crossValidationFoldsResultName]); 155 156 // make sure each fold contains variable impacts 157 if (!allFoldResults.All(r => r.Results.ContainsKey(variableImpactResultName))) { 158 DisplayMessage("At least one of the runs does not contain a variable impact result."); 159 } else { 160 // make sure each of the runs has the same input variables 161 var allVariableNames = from run in allFoldResults 162 let varImpacts = (DoubleMatrix)run.Results[variableImpactResultName] 163 select varImpacts.RowNames; 164 var groupedVariableNames = allVariableNames 165 .SelectMany(x => x) 166 .GroupBy(x => x); 167 168 if (groupedVariableNames.Any(g => g.Count() != allFoldResults.Count())) { 169 DisplayMessage("At least one of the runs has a different input variable set than the rest."); 170 } else { 134 171 // populate combobox 135 172 comboBox.Items.Add("Overall"); … … 139 176 comboBox.SelectedIndex = 0; 140 177 comboBox.Enabled = true; 141 } else { 142 matrixView.Content = null; 143 } 178 comboBox.Visible = true; 179 foldsLabel.Visible = true; 180 variableImpactsGroupBox.Controls.Clear(); 181 variableImpactsGroupBox.Dock = DockStyle.None; 182 variableImpactsGroupBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | 183 AnchorStyles.Bottom; 184 variableImpactsGroupBox.Height = this.Height - comboBox.Height - 12; 185 variableImpactsGroupBox.Width = this.Width; 186 matrixView.Dock = DockStyle.Fill; 187 variableImpactsGroupBox.Controls.Add(matrixView); 188 } 189 } 190 } else { 191 DisplayMessage("At least on of the cross-validation runs has a different number of folds than the rest."); 192 } 193 } 194 195 private void CheckAndUpdateNormalRuns() { 196 // make sure all runs contain variable impact results 197 var visibleRuns = from run in Content where run.Visible select run; 198 199 if (!visibleRuns.All(r => r.Results.ContainsKey(variableImpactResultName))) { 200 DisplayMessage("At least one of the runs does not contain a variable impact result."); 201 } else { 202 // make sure each of the runs has the same input variables 203 var allVariableNames = from run in visibleRuns 204 let varImpacts = (DoubleMatrix)run.Results[variableImpactResultName] 205 select varImpacts.RowNames; 206 var groupedVariableNames = allVariableNames 207 .SelectMany(x => x) 208 .GroupBy(x => x); 209 210 if (groupedVariableNames.Any(g => g.Count() != visibleRuns.Count())) { 211 DisplayMessage("At least one of the runs has a different input variable set than the rest."); 144 212 } else { 145 var runsWithVariables = visibleRuns.Where(r => r.Results.ContainsKey(variableImpactResultName)).ToArray();146 matrixView.Content = CalculateVariableImpactMatrix(runsWithVariables);147 }148 }149 }150 151 private IStringConvertibleMatrix CalculateVariableImpactMatrix(IRun[] runs) {152 return CalculateVariableImpactMatrix(runs, runs.Select(r => r.Name).ToArray());213 if (!variableImpactsGroupBox.Controls.Contains(matrixView)) { 214 variableImpactsGroupBox.Controls.Clear(); 215 matrixView.Dock = DockStyle.Fill; 216 variableImpactsGroupBox.Controls.Add(matrixView); 217 } 218 matrixView.Content = CalculateVariableImpactMatrix(visibleRuns.ToArray(), visibleRuns.Select(r => r.Name).ToArray()); 219 } 220 } 153 221 } 154 222 … … 280 348 } 281 349 350 private void DisplayMessage(string message) { 351 variableImpactsGroupBox.Controls.Remove(matrixView); 352 var label = new Label { TextAlign = ContentAlignment.MiddleCenter, Text = message, Dock = DockStyle.Fill }; 353 variableImpactsGroupBox.Controls.Add(label); 354 } 282 355 } 283 356 }
Note: See TracChangeset
for help on using the changeset viewer.