Changeset 13736


Ignore:
Timestamp:
03/26/16 11:10:00 (6 years ago)
Author:
abeham
Message:

#2431: fixed analysis for runs that terminated earlier than others

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs

    r13583 r13736  
    325325
    326326      foreach (var group in groupedRuns) {
    327         var hits = new Dictionary<string, SortedList<double, double>>();
     327        // hits describes the number of target hits at a certain time for a certain group
     328        var hits = new Dictionary<string, SortedList<double, int>>();
     329        // misses describes the number of target misses after a certain time for a certain group
     330        // for instance when a run ends, but has not achieved all targets, misses describes
     331        // how many targets have been left open at the point when the run ended
     332        var misses = new Dictionary<string, SortedList<double, int>>();
    328333        var maxLength = 0.0;
    329334
     335        var noRuns = 0;
    330336        foreach (var problem in group.Value) {
    331337          foreach (var run in problem.Value.Item2) {
     
    334340
    335341            if (eachOrAllTargetCheckBox.Checked) {
    336               CalculateHitsForEachTarget(hits, resultsTable.Rows.First(), problem.Key, group.Key, group.Value.Count, problem.Value.Item1, problem.Value.Item2.Count);
     342              CalculateHitsForEachTarget(hits, misses, resultsTable.Rows.First(), problem.Key, group.Key, problem.Value.Item1);
     343              // achiving each target can be seen as a separate run for that target only
     344              noRuns += targets.Length;
    337345            } else {
    338               maxLength = CalculateHitsForAllTargets(hits, resultsTable.Rows.First(), problem.Key, group.Key, group.Value.Count, problem.Value.Item1, problem.Value.Item2.Count);
     346              var length = CalculateHitsForAllTargets(hits, misses, resultsTable.Rows.First(), problem.Key, group.Key, problem.Value.Item1);
     347              maxLength = Math.Max(length, maxLength);
     348              noRuns++;
    339349            }
    340350          }
     
    351361          };
    352362
    353           var total = 0.0;
     363          var ecdf = 0.0;
     364          var iter = misses[list.Key].GetEnumerator();
     365          iter.MoveNext();
     366          var sumTargets = noRuns * targets.Length;
    354367          foreach (var h in list.Value) {
    355             total += h.Value;
    356             row.Values.Add(Tuple.Create(h.Key, total));
     368            ecdf += h.Value;
     369            while (iter.Current.Key < h.Key) {
     370              sumTargets -= iter.Current.Value;
     371              if (!iter.MoveNext()) break;
     372            }
     373            row.Values.Add(Tuple.Create(h.Key, ecdf / sumTargets));
    357374          }
    358375
    359376          if (maxLength > 0 && (row.Values.Count == 0 || row.Values.Last().Item1 < maxLength))
    360             row.Values.Add(Tuple.Create(maxLength, total));
     377            row.Values.Add(Tuple.Create(maxLength, ecdf / sumTargets));
    361378
    362379          byTargetDataTable.Rows.Add(row);
     
    382399    }
    383400
    384     private void CalculateHitsForEachTarget(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, ProblemDescription problem, string group, int groupCount, double bestTarget, int problemCount) {
     401    private void CalculateHitsForEachTarget(Dictionary<string, SortedList<double, int>> hits,
     402                                            Dictionary<string, SortedList<double, int>> misses,
     403                                            IndexedDataRow<double> row, ProblemDescription problem,
     404                                            string group, double bestTarget) {
    385405      foreach (var l in targets.Select(x => (problem.IsMaximization() ? (1 - x) : (1 + x)) * bestTarget)) {
    386406        var key = group + "-" + l;
    387         if (!hits.ContainsKey(key)) hits.Add(key, new SortedList<double, double>());
     407        if (!hits.ContainsKey(key)) {
     408          hits.Add(key, new SortedList<double, int>());
     409          misses.Add(key, new SortedList<double, int>());
     410        }
     411        var hit = false;
    388412        foreach (var v in row.Values) {
    389413          if (problem.IsMaximization() && v.Item2 >= l || !problem.IsMaximization() && v.Item2 <= l) {
    390414            if (hits[key].ContainsKey(v.Item1))
    391               hits[key][v.Item1] += 1.0 / (groupCount * problemCount);
    392             else hits[key][v.Item1] = 1.0 / (groupCount * problemCount);
     415              hits[key][v.Item1]++;
     416            else hits[key][v.Item1] = 1;
     417            hit = true;
    393418            break;
    394419          }
    395420        }
    396       }
    397     }
    398 
    399     private double CalculateHitsForAllTargets(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, ProblemDescription problem, string group, int groupCount, double bestTarget, int problemCount) {
     421        if (!hit) {
     422          var max = row.Values.Last();
     423          if (misses[key].ContainsKey(max.Item1))
     424            misses[key][max.Item1]++;
     425          else misses[key][max.Item1] = 1;
     426        }
     427      }
     428    }
     429
     430    private double CalculateHitsForAllTargets(Dictionary<string, SortedList<double, int>> hits,
     431                                              Dictionary<string, SortedList<double, int>> misses,
     432                                              IndexedDataRow<double> row, ProblemDescription problem,
     433                                              string group, double bestTarget) {
    400434      var values = row.Values;
    401       if (!hits.ContainsKey(group)) hits.Add(group, new SortedList<double, double>());
     435      if (!hits.ContainsKey(group)) {
     436        hits.Add(group, new SortedList<double, int>());
     437        misses.Add(group, new SortedList<double, int>());
     438      }
    402439
    403440      var i = 0;
     
    408445        if (problem.IsMaximization() && current.Item2 >= target
    409446          || !problem.IsMaximization() && current.Item2 <= target) {
    410           if (!hits[group].ContainsKey(current.Item1)) hits[group][current.Item1] = 0;
    411           hits[group][current.Item1] += 1.0 / (groupCount * problemCount * targets.Length);
     447          if (hits[group].ContainsKey(current.Item1)) hits[group][current.Item1]++;
     448          else hits[group][current.Item1] = 1;
    412449          i++;
    413450        } else {
     
    416453      }
    417454      if (j == values.Count) j--;
     455      if (i < targets.Length) {
     456        if (misses[group].ContainsKey(values[j].Item1))
     457          misses[group][values[j].Item1] += targets.Length - i;
     458        else misses[group][values[j].Item1] = targets.Length - i;
     459      }
    418460      return values[j].Item1;
    419461    }
Note: See TracChangeset for help on using the changeset viewer.