Ignore:
Timestamp:
06/07/16 16:29:59 (4 years ago)
Author:
abeham
Message:

#2457: added standardization of features for recommendation and using log10 of the expected runtime for clustering

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/KnowledgeCenter.cs

    r13809 r13878  
    657657    }
    658658
     659    public static double[][] GetFeaturesStandardized(IRun[] problemInstances, string[] characteristics, out double[] means, out double[] sdevs, double[] medianValues = null) {
     660      var instances = new double[problemInstances.Length][];
     661      var columns = new List<double>[characteristics.Length];
     662      for (var p = 0; p < problemInstances.Length; p++) {
     663        instances[p] = new double[characteristics.Length];
     664        for (var f = 0; f < characteristics.Length; f++) {
     665          if (columns[f] == null) {
     666            columns[f] = new List<double>(problemInstances.Length);
     667          }
     668          IItem item;
     669          if (problemInstances[p].Results.TryGetValue(characteristics[f], out item)) {
     670            double val = 0;
     671            var dItem = item as DoubleValue;
     672            if (dItem != null) {
     673              val = dItem.Value;
     674            } else {
     675              var iItem = item as IntValue;
     676              if (iItem != null) val = iItem.Value;
     677              else val = double.NaN;
     678            }
     679            if (double.IsNaN(val) && medianValues != null)
     680              instances[p][f] = medianValues[f];
     681            else instances[p][f] = val;
     682            columns[f].Add(instances[p][f]);
     683          } else instances[p][f] = medianValues != null ? medianValues[f] : double.NaN;
     684        }
     685      }
     686
     687      means = new double[characteristics.Length];
     688      sdevs = new double[characteristics.Length];
     689      for (var f = 0; f < characteristics.Length; f++) {
     690        var mean = columns[f].Average();
     691        var dev = columns[f].StandardDeviation();
     692        means[f] = mean;
     693        sdevs[f] = dev;
     694        for (var p = 0; p < problemInstances.Length; p++) {
     695          if (dev.IsAlmost(0)) instances[p][f] = 0;
     696          else instances[p][f] = (instances[p][f] - mean) / dev;
     697        }
     698      }
     699
     700      return instances;
     701    }
     702
    659703    public static double[] GetMedianValues(IRun[] problemInstances, string[] characteristics) {
    660704      var values = new List<double>[characteristics.Length];
     
    704748                          .GroupBy(x => algorithmId2AlgorithmInstanceMapping.GetByFirst(algorithmId2RunMapping.GetBySecond(x).Single()))
    705749                          .ToDictionary(x => x.Key, x => ExpectedRuntimeHelper.CalculateErt(x.ToList(), "QualityPerEvaluations", target, Maximization).ExpectedRuntime);
     750    }
     751
     752    public Dictionary<IAlgorithm, double> GetAlgorithmPerformanceLog10(IRun problemInstance) {
     753      if (!problemInstance.Parameters.ContainsKey("BestKnownQuality")) return new Dictionary<IAlgorithm, double>();
     754      var target = GetTarget(((DoubleValue)problemInstance.Parameters["BestKnownQuality"]).Value, MinimumTarget.Value, Maximization);
     755      return knowledgeBase.Where(x => ((StringValue)x.Parameters["Problem Name"]).Value == ((StringValue)problemInstance.Parameters["Problem Name"]).Value)
     756                          .GroupBy(x => algorithmId2AlgorithmInstanceMapping.GetByFirst(algorithmId2RunMapping.GetBySecond(x).Single()))
     757                          .ToDictionary(x => x.Key, x => Math.Log10(ExpectedRuntimeHelper.CalculateErt(x.ToList(), "QualityPerEvaluations", target, Maximization).ExpectedRuntime));
    706758    }
    707759
     
    802854
    803855        var values = pr.GroupBy(x => algorithmId2RunMapping.GetBySecond(x).Single())
    804                        .ToDictionary(x => x.Key, x => ExpectedRuntimeHelper.CalculateErt(x.ToList(), "QualityPerEvaluations", GetTarget(bkq, target, max), max).ExpectedRuntime);
     856                       .ToDictionary(x => x.Key, x => Math.Log10(ExpectedRuntimeHelper.CalculateErt(x.ToList(), "QualityPerEvaluations", GetTarget(bkq, target, max), max).ExpectedRuntime));
    805857        var ranks = ClusteringHelper<long>.Cluster(nClasses, values, x => double.IsInfinity(x.Value))
    806858          .GetByCluster().ToList();
Note: See TracChangeset for help on using the changeset viewer.