- Timestamp:
- 02/07/18 20:55:57 (7 years ago)
- Location:
- branches/1614_GeneralizedQAP/HeuristicLab.OptimizationExpertSystem/3.3/Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.Designer.cs
r13803 r15736 57 57 this.topNComboBox = new System.Windows.Forms.ComboBox(); 58 58 this.topNlabel = new System.Windows.Forms.Label(); 59 this.ndcgLabel = new System.Windows.Forms.Label(); 59 60 this.kendallsTauLabel = new System.Windows.Forms.Label(); 60 61 this.predictedLabel = new System.Windows.Forms.Label(); 61 62 this.absoluteLogErrorLabel = new System.Windows.Forms.Label(); 62 63 this.absoluteErrorLabel = new System.Windows.Forms.Label(); 64 this.ncdgView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 63 65 this.kendallsTauView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 64 66 this.absoluteLogErrorView = new HeuristicLab.Data.Views.StringConvertibleValueView(); … … 68 70 this.minTargetView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 69 71 this.minimumTargetLabel = new System.Windows.Forms.Label(); 70 this. ncdgView = new HeuristicLab.Data.Views.StringConvertibleValueView();71 this. ndcgLabel = new System.Windows.Forms.Label();72 this.spearmansRhoView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 73 this.spearmansRhoLabel = new System.Windows.Forms.Label(); 72 74 this.tabControl.SuspendLayout(); 73 75 this.characteristicsTabPage.SuspendLayout(); … … 186 188 this.crossvalidationTabPage.Controls.Add(this.topNlabel); 187 189 this.crossvalidationTabPage.Controls.Add(this.ndcgLabel); 190 this.crossvalidationTabPage.Controls.Add(this.spearmansRhoLabel); 188 191 this.crossvalidationTabPage.Controls.Add(this.kendallsTauLabel); 189 192 this.crossvalidationTabPage.Controls.Add(this.predictedLabel); … … 191 194 this.crossvalidationTabPage.Controls.Add(this.absoluteErrorLabel); 192 195 this.crossvalidationTabPage.Controls.Add(this.ncdgView); 196 this.crossvalidationTabPage.Controls.Add(this.spearmansRhoView); 193 197 this.crossvalidationTabPage.Controls.Add(this.kendallsTauView); 194 198 this.crossvalidationTabPage.Controls.Add(this.absoluteLogErrorView); … … 223 227 this.topNlabel.Text = "Evaluate only best ranked:"; 224 228 // 229 // ndcgLabel 230 // 231 this.ndcgLabel.AutoSize = true; 232 this.ndcgLabel.Location = new System.Drawing.Point(519, 165); 233 this.ndcgLabel.Margin = new System.Windows.Forms.Padding(3); 234 this.ndcgLabel.Name = "ndcgLabel"; 235 this.ndcgLabel.Size = new System.Drawing.Size(106, 13); 236 this.ndcgLabel.TabIndex = 3; 237 this.ndcgLabel.Text = "Mean NDCG (top N):"; 238 // 225 239 // kendallsTauLabel 226 240 // … … 263 277 this.absoluteErrorLabel.TabIndex = 3; 264 278 this.absoluteErrorLabel.Text = "Mean Absolute Error (top N):"; 279 // 280 // ncdgView 281 // 282 this.ncdgView.Caption = "StringConvertibleValue View"; 283 this.ncdgView.Content = null; 284 this.ncdgView.LabelVisible = false; 285 this.ncdgView.Location = new System.Drawing.Point(503, 184); 286 this.ncdgView.Name = "ncdgView"; 287 this.ncdgView.ReadOnly = true; 288 this.ncdgView.Size = new System.Drawing.Size(194, 21); 289 this.ncdgView.TabIndex = 2; 265 290 // 266 291 // kendallsTauView … … 339 364 this.minimumTargetLabel.Text = "Target:"; 340 365 // 341 // ncdgView342 // 343 this. ncdgView.Caption = "StringConvertibleValue View";344 this. ncdgView.Content = null;345 this. ncdgView.LabelVisible = false;346 this. ncdgView.Location = new System.Drawing.Point(503, 184);347 this. ncdgView.Name = "ncdgView";348 this. ncdgView.ReadOnly = true;349 this. ncdgView.Size = new System.Drawing.Size(194, 21);350 this. ncdgView.TabIndex = 2;351 // 352 // ndcgLabel353 // 354 this. ndcgLabel.AutoSize = true;355 this. ndcgLabel.Location = new System.Drawing.Point(519, 165);356 this. ndcgLabel.Margin = new System.Windows.Forms.Padding(3);357 this. ndcgLabel.Name = "ndcgLabel";358 this. ndcgLabel.Size = new System.Drawing.Size(106, 13);359 this. ndcgLabel.TabIndex = 3;360 this. ndcgLabel.Text = "Mean NDCG (top N):";366 // spearmansRhoView 367 // 368 this.spearmansRhoView.Caption = "StringConvertibleValue View"; 369 this.spearmansRhoView.Content = null; 370 this.spearmansRhoView.LabelVisible = false; 371 this.spearmansRhoView.Location = new System.Drawing.Point(503, 303); 372 this.spearmansRhoView.Name = "spearmansRhoView"; 373 this.spearmansRhoView.ReadOnly = true; 374 this.spearmansRhoView.Size = new System.Drawing.Size(194, 21); 375 this.spearmansRhoView.TabIndex = 2; 376 // 377 // spearmansRhoLabel 378 // 379 this.spearmansRhoLabel.AutoSize = true; 380 this.spearmansRhoLabel.Location = new System.Drawing.Point(519, 284); 381 this.spearmansRhoLabel.Margin = new System.Windows.Forms.Padding(3); 382 this.spearmansRhoLabel.Name = "spearmansRhoLabel"; 383 this.spearmansRhoLabel.Size = new System.Drawing.Size(118, 13); 384 this.spearmansRhoLabel.TabIndex = 3; 385 this.spearmansRhoLabel.Text = "Mean Spearman\'s Rho:"; 361 386 // 362 387 // PerformanceModelingView … … 409 434 private System.Windows.Forms.Label ndcgLabel; 410 435 private Data.Views.StringConvertibleValueView ncdgView; 436 private System.Windows.Forms.Label spearmansRhoLabel; 437 private Data.Views.StringConvertibleValueView spearmansRhoView; 411 438 } 412 439 } -
branches/1614_GeneralizedQAP/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.cs
r13878 r15736 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Threading.Tasks; 22 26 using HeuristicLab.Analysis; 23 27 using HeuristicLab.Common.Resources; … … 28 32 using HeuristicLab.OptimizationExpertSystem.Common; 29 33 using HeuristicLab.PluginInfrastructure; 30 using System;31 using System.Collections.Generic;32 using System.Linq;33 using System.Threading.Tasks;34 34 35 35 namespace HeuristicLab.OptimizationExpertSystem { … … 181 181 var tau = 0.0; 182 182 var tauCnt = 0; 183 var rho = 0.0; 184 var rhoCnt = 0; 183 185 var ndcg = 0.0; 184 186 var ndcgCnt = 0; … … 207 209 } 208 210 var kt = KendallsTau(observed, predicted); 209 if (!double.IsNaN(kt) ) {211 if (!double.IsNaN(kt) && !double.IsInfinity(kt)) { 210 212 tau += kt; 211 213 tauCnt++; 214 } 215 var sr = SpearmansRho(observed, predicted); 216 if (!double.IsNaN(sr)) { 217 rho += sr; 218 rhoCnt++; 212 219 } 213 220 var gain = NDCG(observed, model.GetRanking(pi).Take(topN).Select(x => x.Key).ToList()); … … 216 223 ndcgCnt++; 217 224 } 218 // mean reciprocal rank219 // optional: expected reciprocal rank220 225 progress.ProgressValue = ++count / (double)trainingSet.Length; 221 226 } … … 223 228 absLogErr /= absLogErrCnt; 224 229 tau /= tauCnt; 230 rho /= rhoCnt; 225 231 ndcg /= ndcgCnt; 226 232 … … 230 236 confusionMatrixView.Content = new IntMatrix(confMatrix) {ColumnNames = description}; 231 237 kendallsTauView.Content = new DoubleValue(tau); 238 spearmansRhoView.Content = new DoubleValue(rho); 232 239 ncdgView.Content = new DoubleValue(ndcg); 233 240 } finally { progress.Finish(); } … … 272 279 } 273 280 281 private static double SpearmansRho(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 282 var commonKeys = performance.Keys.Intersect(ranking.Keys).ToList(); 283 var n = commonKeys.Count; 284 if (n == 0) return double.NaN; 285 286 var actualRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = performance[x] }) 287 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = double.IsPositiveInfinity(x.Perf) ? int.MaxValue : i }) 288 .OrderBy(x => x.Index).Select(x => (double)x.Rank).ToArray(); 289 var predictedRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = ranking[x] }) 290 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = double.IsPositiveInfinity(x.Perf) ? int.MaxValue : i }) 291 .OrderBy(x => x.Index).Select(x => (double)x.Rank).ToArray(); 292 293 return alglib.spearmancorr2(actualRanks, predictedRanks); 294 } 295 274 296 private static double KendallsTau(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 275 297 var commonKeys = performance.Keys.Intersect(ranking.Keys).ToList(); … … 278 300 279 301 var actualRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = performance[x] }) 280 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = i })302 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = double.IsPositiveInfinity(x.Perf) ? int.MaxValue : i }) 281 303 .OrderBy(x => x.Index).Select(x => x.Rank).ToList(); 282 304 var predictedRanks = commonKeys.Select((x, i) => new { Alg = x, Index = i, Perf = ranking[x] }) 283 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = i })305 .OrderBy(x => x.Perf).Select((x, i) => new { Index = x.Index, Rank = double.IsPositiveInfinity(x.Perf) ? int.MaxValue : i }) 284 306 .OrderBy(x => x.Index).Select(x => x.Rank).ToList(); 285 307 … … 292 314 || paired[i].Actual < paired[j].Actual && paired[i].Predicted < paired[j].Predicted) 293 315 concordant++; 294 else discordant++; 316 else if (paired[i].Actual > paired[j].Actual && paired[i].Predicted < paired[j].Predicted 317 || paired[i].Actual < paired[j].Actual && paired[i].Predicted > paired[j].Predicted) 318 discordant++; 295 319 } 296 return (2.0 * (concordant - discordant)) / (n * (n - 1)); 320 321 var ti = performance.GroupBy(x => x.Value).Sum(x => x.Count() * (x.Count() - 1)); 322 var uj = ranking.GroupBy(x => x.Value).Sum(x => x.Count() * (x.Count() - 1)); 323 return (2.0 * (concordant - discordant)) / Math.Sqrt( (n * (n - 1) - ti * (ti - 1)) * (n * (n - 1) - uj * (uj - 1)) ); 297 324 } 298 325
Note: See TracChangeset
for help on using the changeset viewer.