- Timestamp:
- 04/27/16 16:21:07 (8 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/KnowledgeCenter.cs
r13797 r13803 654 654 var bkq = ((DoubleValue)prob.Parameters["BestKnownQuality"]).Value; 655 655 var ert = ExpectedRuntimeHelper.CalculateErt(pr.ToList(), "QualityPerEvaluations", GetTarget(bkq, target, max), max).ExpectedRuntime; 656 if (double.Is NaN(ert)) ert = int.MaxValue;656 if (double.IsInfinity(ert)) ert = int.MaxValue; 657 657 ds.AddRow(new object[] { pr.Key }.Concat(f.Cast<object>()).Concat(new object[] { ert })); 658 658 } … … 720 720 var values = pr.GroupBy(x => algorithmId2RunMapping.GetBySecond(x).Single()) 721 721 .ToDictionary(x => x.Key, x => ExpectedRuntimeHelper.CalculateErt(x.ToList(), "QualityPerEvaluations", GetTarget(bkq, target, max), max).ExpectedRuntime); 722 var ranks = ClusteringHelper<long>.Cluster(nClasses, values, x => double.Is NaN(x.Value))722 var ranks = ClusteringHelper<long>.Cluster(nClasses, values, x => double.IsInfinity(x.Value)) 723 723 .GetByCluster().ToList(); 724 724 foreach (var c in ranks) { -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/Recommenders/KNearestNeighborModel.cs
r13794 r13803 49 49 var feature = KnowledgeCenter.GetFeatures(new [] { problemInstance }, characteristics, medianValues)[0]; 50 50 var nearestK = features.Select((f, i) => new { ProblemInstanceIndex = i, Feature = f }) 51 .OrderBy(x => x.Feature.Select((f, i) => (f - feature[i]) * (f - feature[i])).Sum()) 52 .Take(K); 51 .OrderBy(x => x.Feature.Select((f, i) => (f - feature[i]) * (f - feature[i])).Sum()); 53 52 54 var performances = new Dictionary<IAlgorithm, List<double>>(); 53 var performances = new Dictionary<IAlgorithm, Performance>(); 54 55 var k = 0; 55 56 foreach (var next in nearestK) { 57 if (k >= K) break; 56 58 var perfs = performance[problemInstanceMap.GetByFirst(next.ProblemInstanceIndex)]; 57 59 if (perfs.Count == 0) continue; … … 59 61 foreach (var p in perfs) { 60 62 var ert = p.Value; 61 if (double.IsNaN(ert)) ert = int.MaxValue; 62 List<double> erts; 63 if (!performances.TryGetValue(p.Key, out erts)) { 64 performances[p.Key] = new List<double>() { ert }; ; 65 } else erts.Add(ert); 63 Performance perf; 64 if (!performances.TryGetValue(p.Key, out perf)) { 65 perf = new Performance(); 66 performances[p.Key] = perf; 67 } 68 perf.Add(ert); 66 69 } 70 71 k++; 67 72 } 68 73 69 return performances.Select(x => new { Alg = x.Key, Perf = x.Value. Average() })74 return performances.Select(x => new { Alg = x.Key, Perf = x.Value.ExpectedRuntime() }) 70 75 .OrderBy(x => x.Perf) 71 76 .Select(x => new KeyValuePair<IAlgorithm, double>(x.Alg, x.Perf)); 72 77 } 78 79 private class Performance { 80 private readonly List<double> successful; 81 private int runs; 82 public int Fails { get { return runs - successful.Count; } } 83 84 public Performance() { 85 successful = new List<double>(); 86 } 87 88 public void Add(double ert) { 89 if (!double.IsInfinity(ert)) successful.Add(ert); 90 runs++; 91 } 92 93 public double ExpectedRuntime() { 94 if (successful.Count == 0) return int.MaxValue; 95 return successful.Average() / (successful.Count / (double)runs); 96 } 97 } 73 98 } 74 99 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/Recommenders/OverallBestRecommender.cs
r13797 r13803 63 63 if (!pis.TryGetValue(problemRuns.Key, out bkq)) continue; 64 64 var ert = ExpectedRuntimeHelper.CalculateErt(problemRuns.ToList(), "QualityPerEvaluations", kc.GetTarget(bkq, kc.MinimumTarget.Value, kc.Maximization), kc.Maximization).ExpectedRuntime; 65 if (double.Is NaN(ert)) ert = int.MaxValue;65 if (double.IsInfinity(ert)) ert = int.MaxValue; 66 66 avgERT += ert; 67 67 count++;
Note: See TracChangeset
for help on using the changeset viewer.