Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2701_MemPRAlgorithm/HeuristicLab.Analysis/3.3/QualityAnalysis/ExpectedRuntimeHelper.cs @ 16724

Last change on this file since 16724 was 14102, checked in by abeham, 8 years ago

#2634: Integrated RLD analysis into trunk

  • HeuristicLab.Analysis:
    • IndexedDataTable<T>, IndexedDataRow<T>
    • QualityPerClockAnalyzer, QualityPerEvaluationsAnalyzer
    • ExpectedRuntimeHelper
  • HeuristicLab.Analysis.Views:
    • IndexedDataTableView
  • HeuristicLab.Optimization.Views:
    • RunCollectionRLDView

To test:

  1. Configure an algorithm/problem combination
  2. In the algorithm's analyzers add the QualityPerEvaluationsAnalyzer
  3. Make sure the BestAverageWorstQualityAnalyzer is executed before
  4. Run the algorithm several times
  5. In the Runs tab select the "Run-length Distribution View"
File size: 2.3 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Optimization;
3using System;
4using System.Collections.Generic;
5using System.Globalization;
6using System.Linq;
7
8namespace HeuristicLab.Analysis {
9  public static class ExpectedRuntimeHelper {
10    public static ErtCalculationResult CalculateErt(IEnumerable<IEnumerable<Tuple<double, double>>> convGraphs, double target, bool maximization) {
11      var successful = new List<double>();
12      var unsuccessful = new List<double>();
13      foreach (var graph in convGraphs) {
14        var targetAchieved = false;
15        var lastEffort = double.MaxValue;
16        foreach (var v in graph) {
17          if (maximization && v.Item2 >= target || !maximization && v.Item2 <= target) {
18            successful.Add(v.Item1);
19            targetAchieved = true;
20            break;
21          }
22          lastEffort = v.Item1;
23        }
24        if (!targetAchieved) unsuccessful.Add(lastEffort);
25      }
26
27      var ert = double.PositiveInfinity;
28
29      var nRuns = successful.Count + unsuccessful.Count;
30      if (successful.Count > 0) {
31        var succAvg = successful.Average();
32        var succDev = successful.StandardDeviation();
33        successful.RemoveAll(x => x < succAvg - 2 * succDev);
34        unsuccessful.RemoveAll(x => x < succAvg - 2 * succDev);
35        nRuns = successful.Count + unsuccessful.Count;
36
37        ert = successful.Average() / (successful.Count / (double)nRuns);
38      }
39      return new ErtCalculationResult(successful.Count, nRuns, ert);
40    }
41
42    public static ErtCalculationResult CalculateErt(List<IRun> runs, string indexedDataTableName, double target, bool maximization) {
43      return CalculateErt(runs.Select(r => ((IndexedDataTable<double>)r.Results[indexedDataTableName]).Rows.First().Values), target, maximization);
44    }
45  }
46
47  public struct ErtCalculationResult {
48    public int SuccessfulRuns;
49    public int TotalRuns;
50    public double ExpectedRuntime;
51
52    public ErtCalculationResult(int successful, int total, double ert) {
53      SuccessfulRuns = successful;
54      TotalRuns = total;
55      ExpectedRuntime = ert;
56    }
57
58    public override string ToString() {
59      return SuccessfulRuns == 0 ? "\u221e" // infinity symbol
60                                 : ExpectedRuntime.ToString("##,0.0", CultureInfo.CurrentCulture.NumberFormat);
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.