- Timestamp:
- 04/26/16 00:02:05 (9 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.Designer.cs
r13791 r13794 55 55 this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView(); 56 56 this.crossvalidationTabPage = new System.Windows.Forms.TabPage(); 57 this.kendallsTauLabel = new System.Windows.Forms.Label(); 58 this.absoluteErrorLabel = new System.Windows.Forms.Label(); 59 this.kendallsTauView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 60 this.absoluteErrorView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 61 this.confusionMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView(); 57 62 this.xValidateButton = new System.Windows.Forms.Button(); 58 63 this.minTargetView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 59 64 this.minimumTargetLabel = new System.Windows.Forms.Label(); 65 this.actualLabel = new System.Windows.Forms.Label(); 66 this.predictedLabel = new System.Windows.Forms.Label(); 60 67 this.tabControl.SuspendLayout(); 61 68 this.characteristicsTabPage.SuspendLayout(); … … 75 82 // recommenderComboBox 76 83 // 77 this.recommenderComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)78 | System.Windows.Forms.AnchorStyles.Right)));79 84 this.recommenderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 80 85 this.recommenderComboBox.FormattingEnabled = true; … … 87 92 // recommendStartButton 88 93 // 89 this.recommendStartButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));90 94 this.recommendStartButton.Location = new System.Drawing.Point(442, 1); 91 95 this.recommendStartButton.Name = "recommendStartButton"; … … 107 111 this.tabControl.Name = "tabControl"; 108 112 this.tabControl.SelectedIndex = 0; 109 this.tabControl.Size = new System.Drawing.Size( 700, 350);113 this.tabControl.Size = new System.Drawing.Size(817, 509); 110 114 this.tabControl.TabIndex = 14; 111 115 // … … 174 178 // crossvalidationTabPage 175 179 // 180 this.crossvalidationTabPage.Controls.Add(this.kendallsTauLabel); 181 this.crossvalidationTabPage.Controls.Add(this.predictedLabel); 182 this.crossvalidationTabPage.Controls.Add(this.actualLabel); 183 this.crossvalidationTabPage.Controls.Add(this.absoluteErrorLabel); 184 this.crossvalidationTabPage.Controls.Add(this.kendallsTauView); 185 this.crossvalidationTabPage.Controls.Add(this.absoluteErrorView); 186 this.crossvalidationTabPage.Controls.Add(this.confusionMatrixView); 176 187 this.crossvalidationTabPage.Controls.Add(this.xValidateButton); 177 188 this.crossvalidationTabPage.Location = new System.Drawing.Point(4, 22); 178 189 this.crossvalidationTabPage.Name = "crossvalidationTabPage"; 179 190 this.crossvalidationTabPage.Padding = new System.Windows.Forms.Padding(3); 180 this.crossvalidationTabPage.Size = new System.Drawing.Size( 692, 324);191 this.crossvalidationTabPage.Size = new System.Drawing.Size(809, 483); 181 192 this.crossvalidationTabPage.TabIndex = 1; 182 193 this.crossvalidationTabPage.Text = "Crossvalidation"; 183 194 this.crossvalidationTabPage.UseVisualStyleBackColor = true; 195 // 196 // kendallsTauLabel 197 // 198 this.kendallsTauLabel.AutoSize = true; 199 this.kendallsTauLabel.Location = new System.Drawing.Point(536, 110); 200 this.kendallsTauLabel.Margin = new System.Windows.Forms.Padding(3); 201 this.kendallsTauLabel.Name = "kendallsTauLabel"; 202 this.kendallsTauLabel.Size = new System.Drawing.Size(104, 13); 203 this.kendallsTauLabel.TabIndex = 3; 204 this.kendallsTauLabel.Text = "Mean Kendall\'s Tau:"; 205 // 206 // absoluteErrorLabel 207 // 208 this.absoluteErrorLabel.AutoSize = true; 209 this.absoluteErrorLabel.Location = new System.Drawing.Point(536, 52); 210 this.absoluteErrorLabel.Margin = new System.Windows.Forms.Padding(3); 211 this.absoluteErrorLabel.Name = "absoluteErrorLabel"; 212 this.absoluteErrorLabel.Size = new System.Drawing.Size(106, 13); 213 this.absoluteErrorLabel.TabIndex = 3; 214 this.absoluteErrorLabel.Text = "Mean Absolute Error:"; 215 // 216 // kendallsTauView 217 // 218 this.kendallsTauView.Caption = "StringConvertibleValue View"; 219 this.kendallsTauView.Content = null; 220 this.kendallsTauView.LabelVisible = false; 221 this.kendallsTauView.Location = new System.Drawing.Point(520, 129); 222 this.kendallsTauView.Name = "kendallsTauView"; 223 this.kendallsTauView.ReadOnly = true; 224 this.kendallsTauView.Size = new System.Drawing.Size(194, 21); 225 this.kendallsTauView.TabIndex = 2; 226 // 227 // absoluteErrorView 228 // 229 this.absoluteErrorView.Caption = "StringConvertibleValue View"; 230 this.absoluteErrorView.Content = null; 231 this.absoluteErrorView.LabelVisible = false; 232 this.absoluteErrorView.Location = new System.Drawing.Point(520, 71); 233 this.absoluteErrorView.Name = "absoluteErrorView"; 234 this.absoluteErrorView.ReadOnly = true; 235 this.absoluteErrorView.Size = new System.Drawing.Size(194, 21); 236 this.absoluteErrorView.TabIndex = 2; 237 // 238 // confusionMatrixView 239 // 240 this.confusionMatrixView.Caption = "StringConvertibleMatrix View"; 241 this.confusionMatrixView.Content = null; 242 this.confusionMatrixView.Location = new System.Drawing.Point(37, 71); 243 this.confusionMatrixView.Name = "confusionMatrixView"; 244 this.confusionMatrixView.ReadOnly = true; 245 this.confusionMatrixView.ShowRowsAndColumnsTextBox = false; 246 this.confusionMatrixView.ShowStatisticalInformation = false; 247 this.confusionMatrixView.Size = new System.Drawing.Size(477, 363); 248 this.confusionMatrixView.TabIndex = 1; 184 249 // 185 250 // xValidateButton … … 212 277 this.minimumTargetLabel.TabIndex = 17; 213 278 this.minimumTargetLabel.Text = "Target:"; 279 // 280 // actualLabel 281 // 282 this.actualLabel.AutoSize = true; 283 this.actualLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 284 this.actualLabel.Location = new System.Drawing.Point(16, 210); 285 this.actualLabel.Margin = new System.Windows.Forms.Padding(3); 286 this.actualLabel.Name = "actualLabel"; 287 this.actualLabel.Size = new System.Drawing.Size(15, 78); 288 this.actualLabel.TabIndex = 3; 289 this.actualLabel.Text = "A\r\nC\r\nT\r\nU\r\nA\r\nL"; 290 // 291 // predictedLabel 292 // 293 this.predictedLabel.AutoSize = true; 294 this.predictedLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 295 this.predictedLabel.Location = new System.Drawing.Point(241, 52); 296 this.predictedLabel.Margin = new System.Windows.Forms.Padding(3); 297 this.predictedLabel.Name = "predictedLabel"; 298 this.predictedLabel.Size = new System.Drawing.Size(69, 13); 299 this.predictedLabel.TabIndex = 3; 300 this.predictedLabel.Text = "PREDICTED"; 214 301 // 215 302 // PerformanceModelingView … … 224 311 this.Controls.Add(this.recommendStartButton); 225 312 this.Name = "PerformanceModelingView"; 313 this.Size = new System.Drawing.Size(817, 539); 226 314 this.tabControl.ResumeLayout(false); 227 315 this.characteristicsTabPage.ResumeLayout(false); 228 316 this.parametersTabPage.ResumeLayout(false); 229 317 this.crossvalidationTabPage.ResumeLayout(false); 318 this.crossvalidationTabPage.PerformLayout(); 230 319 this.ResumeLayout(false); 231 320 this.PerformLayout(); … … 248 337 private Data.Views.StringConvertibleValueView minTargetView; 249 338 private System.Windows.Forms.Label minimumTargetLabel; 339 private System.Windows.Forms.Label kendallsTauLabel; 340 private System.Windows.Forms.Label absoluteErrorLabel; 341 private Data.Views.StringConvertibleValueView kendallsTauView; 342 private Data.Views.StringConvertibleValueView absoluteErrorView; 343 private Data.Views.StringConvertibleMatrixView confusionMatrixView; 344 private System.Windows.Forms.Label predictedLabel; 345 private System.Windows.Forms.Label actualLabel; 250 346 } 251 347 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.cs
r13791 r13794 20 20 #endregion 21 21 22 using HeuristicLab.Analysis; 22 23 using HeuristicLab.Common.Resources; 23 24 using HeuristicLab.Core; … … 134 135 var trainingSet = Content.ProblemInstances.Where(x => !Content.IsCurrentInstance(x)).ToArray(); 135 136 137 var absErr = 0.0; 138 var confMatrix = new int[6, 6]; 139 var tau = 0.0; 136 140 // leave one out crossvalidation 137 141 foreach (var pi in trainingSet) { 138 142 var model = recommender.TrainModel(trainingSet.Where(x => x != pi).ToArray(), Content, features); 139 var ranking = model.GetRanking(pi).ToList(); 140 var realPerformance = Content.GetAlgorithmPerformance(pi); 141 // absolute error predicting ert 142 // confusion matrix predicting class 143 // Kendall's tau 143 var predicted = model.GetRanking(pi).ToDictionary(x => x.Key, x => x.Value); 144 var observed = Content.GetAlgorithmPerformance(pi); 145 absErr += AbsoluteError(observed, predicted); 146 var confMat = ConfusionMatrix(observed, predicted); 147 for (var i = 0; i < confMat.GetLength(0); i++) 148 for (var j = 0; j < confMat.GetLength(1); j++) 149 confMatrix[i, j] += confMat[i, j]; 150 tau += KendallsTau(observed, predicted); 144 151 // average NCDG ... relevance determined by clustering (unsuccessful algorithms being penalized with negative relevance) 145 152 // mean reciprocal rank 146 153 // optional: expected reciprocal rank 147 154 } 148 } 149 150 private static double AbsoluteError(Dictionary<IAlgorithm, double> performance, List<Tuple<IAlgorithm, double>> ranking) { 155 absErr /= trainingSet.Length; 156 tau /= trainingSet.Length; 157 158 confusionMatrixView.Content = new IntMatrix(confMatrix); 159 absoluteErrorView.Content = new DoubleValue(absErr); 160 kendallsTauView.Content = new DoubleValue(tau); 161 } 162 163 private static double AbsoluteError(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 151 164 var error = 0.0; 152 165 foreach (var tuple in ranking) { 153 166 double actual; 154 if (!performance.TryGetValue(tuple.Item1, out actual)) continue; 155 error += Math.Abs(actual - tuple.Item2); 167 if (!performance.TryGetValue(tuple.Key, out actual)) continue; 168 if (double.IsNaN(actual)) actual = int.MaxValue; 169 error += Math.Abs(actual - tuple.Value); 156 170 } 157 171 return error; 158 172 } 159 173 160 private static int[,] ConfusionMatrix(Dictionary<IAlgorithm, double> performance, List<Tuple<IAlgorithm, double>> ranking) { 161 var confMatrix = new int[5,5]; 174 private static int[,] ConfusionMatrix(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 175 var confMatrix = new int[6,6]; 176 var clusteredPerformance = ClusteringHelper<IAlgorithm>.Cluster(5, performance, a => double.IsNaN(a.Value)).GetByInstance().ToDictionary(x => x.Key, x => x.Value.Item2); 177 var clusteredRanks = ClusteringHelper<IAlgorithm>.Cluster(5, ranking, x => double.IsNaN(x.Value) || x.Value >= int.MaxValue).GetByInstance().ToDictionary(x => x.Key, x => x.Value.Item2); 178 foreach (var cr in clusteredRanks) { 179 int realRank; 180 if (!clusteredPerformance.TryGetValue(cr.Key, out realRank)) continue; 181 confMatrix[realRank, cr.Value]++; 182 } 162 183 return confMatrix; 184 } 185 186 private static double KendallsTau(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 187 var commonKeys = performance.Keys.Intersect(ranking.Keys).ToList(); 188 var n = commonKeys.Count; 189 if (n == 0) return 0.0; 190 191 var actualRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = performance[x] }) 192 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = i }) 193 .OrderBy(x => x.Index).Select(x => x.Rank).ToList(); 194 var predictedRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = ranking[x] }) 195 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = i }) 196 .OrderBy(x => x.Index).Select(x => x.Rank).ToList(); 197 198 var paired = actualRanks.Zip(predictedRanks, (a, p) => new { Actual = a, Predicted = p }).ToList(); 199 var concordant = 0; 200 var discordant = 0; 201 for (var i = 0; i < paired.Count - 1; i++) 202 for (var j = 0; j < paired.Count; j++) { 203 if (paired[i].Actual > paired[j].Actual && paired[i].Predicted > paired[j].Predicted 204 || paired[i].Actual < paired[j].Actual && paired[i].Predicted < paired[j].Predicted) 205 concordant++; 206 else discordant++; 207 } 208 return (2.0 * (concordant - discordant)) / (n * (n - 1)); 163 209 } 164 210 #endregion -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/SolverView.cs
r13791 r13794 28 28 using HeuristicLab.OptimizationExpertSystem.Common; 29 29 using System; 30 using System.Collections.Generic; 30 31 using System.Linq; 31 32 using System.Windows.Forms; … … 96 97 for (var i = 0; i < ranking.Count; i++) { 97 98 suggestedInstancesComboBox.Items.Add(new AlgorithmInstanceItem(ranking[i])); 98 if (prevSelection == null || ranking[i]. Item1.Name == prevSelection.Item.Item1.Name)99 if (prevSelection == null || ranking[i].Key.Name == prevSelection.Item.Key.Name) 99 100 prevNewIndex = prevSelection == null ? 0 : i; 100 101 } … … 119 120 private void AlgorithmStartButtonOnClick(object sender, EventArgs e) { 120 121 if (suggestedInstancesComboBox.SelectedIndex >= 0) 121 Content.StartAlgorithmAsync(Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i}).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item. Item1.Name).Index);122 Content.StartAlgorithmAsync(Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i}).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item.Key.Name).Index); 122 123 } 123 124 124 125 private void AlgorithmCloneButtonOnClick(object sender, EventArgs e) { 125 126 if (suggestedInstancesComboBox.SelectedIndex >= 0) 126 MainForm.ShowContent((IAlgorithm)Content.AlgorithmInstances[Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i }).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item. Item1.Name).Index].Clone());127 MainForm.ShowContent((IAlgorithm)Content.AlgorithmInstances[Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i }).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item.Key.Name).Index].Clone()); 127 128 } 128 129 … … 130 131 if (InvokeRequired) { Invoke((Action<object, EventArgs>)SuggestedInstancesComboBoxOnSelectedIndexChanged, sender, e); return; } 131 132 if (suggestedInstancesComboBox.SelectedIndex >= 0) { 132 var alg = Content.AlgorithmInstances[Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i }).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item. Item1.Name).Index];133 var alg = Content.AlgorithmInstances[Content.AlgorithmInstances.Select((a, i) => new { Alg = a, Index = i }).Single(x => x.Alg.Name == ((AlgorithmInstanceItem)suggestedInstancesComboBox.SelectedItem).Item.Key.Name).Index]; 133 134 solverParametersView.Content = alg.Parameters; 134 135 var engineAlg = alg as EngineAlgorithm; … … 145 146 #region Helper Classes and Methods 146 147 private class AlgorithmInstanceItem { 147 private readonly Tuple<IAlgorithm, double> item;148 public Tuple<IAlgorithm, double> Item { get { return item; } }148 private readonly KeyValuePair<IAlgorithm, double> item; 149 public KeyValuePair<IAlgorithm, double> Item { get { return item; } } 149 150 150 public AlgorithmInstanceItem( Tuple<IAlgorithm, double> item) {151 public AlgorithmInstanceItem(KeyValuePair<IAlgorithm, double> item) { 151 152 this.item = item; 152 153 } 153 154 154 155 public override string ToString() { 155 return item. Item2.ToString("N0") + ": " + item.Item1.Name;156 return item.Value.ToString("N0") + ": " + item.Key.Name; 156 157 } 157 158 }
Note: See TracChangeset
for help on using the changeset viewer.