Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/19/15 21:21:13 (9 years ago)
Author:
abeham
Message:

#2457: Worked on expert system

  • using newly created ERT helper class
Location:
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3
Files:
2 edited

Legend:

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

    r12860 r12957  
    6767    public ItemList<IAlgorithm> AlgorithmInstances {
    6868      get { return algorithmInstances; }
     69      set {
     70        if (algorithmInstances == value) return;
     71        algorithmInstances = value;
     72        OnPropertyChanged("AlgorithmInstances");
     73      }
    6974    }
    7075
     
    8691    public ReadOnlyItemList<IAlgorithm> SuggestedInstances {
    8792      get { return readOnlySuggestedInstances; }
     93    }
     94
     95    [Storable]
     96    private RunCollection problemInstances;
     97    public RunCollection ProblemInstances {
     98      get { return problemInstances; }
     99      set {
     100        if (problemInstances == value) return;
     101        problemInstances = value;
     102        OnPropertyChanged("ProblemInstances");
     103      }
    88104    }
    89105
     
    101117      suggestedInstances = cloner.Clone(original.suggestedInstances);
    102118      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
     119      problemInstances = cloner.Clone(original.problemInstances);
    103120      RegisterEventHandlers();
    104121    }
     
    110127      suggestedInstances = new ItemList<IAlgorithm>();
    111128      readOnlySuggestedInstances = suggestedInstances.AsReadOnly();
     129      problemInstances = new RunCollection();
    112130      RegisterEventHandlers();
    113131    }
     
    137155      var runCollection = sender as RunCollection;
    138156      if (runCollection != null && runCollection.UpdateOfRunsInProgress) return;
     157      UpdateInstanceMap();
    139158      UpdateSuggestions();
     159    }
     160
     161    private void UpdateInstanceMap() {
     162      var flaValues = ProblemInstances.ResultNames
     163                      .Where(x => x.StartsWith("Characteristic.")
     164                        && ProblemInstances.All(y => y.Results.ContainsKey(x) && y.Results[x] is DoubleValue))
     165                      .Select(x => x).ToList();
     166      var ds = new double[ProblemInstances.Count, flaValues.Count];
     167      var instanceCounter = 0;
     168      foreach (var instance in ProblemInstances) {
     169        for (var feature = 0; feature < flaValues.Count; feature++)
     170          ds[instanceCounter, feature] = ((DoubleValue)instance.Results[flaValues[feature]]).Value;
     171        instanceCounter++;
     172      }
     173
     174      int info;
     175      double[] s2;
     176      double[,] v;
     177      alglib.pcabuildbasis(ds, instanceCounter, flaValues.Count, out info, out s2, out v);
     178
     179      var algInstRunDict = AlgorithmInstances.SelectMany(x => x.Runs)
     180                                             .Where(x => x.Parameters.ContainsKey("Problem Name") && x.Parameters["Problem Name"] is StringValue)
     181                                             .GroupBy(x => ((StringValue)x.Parameters["Problem Name"]).Value)
     182                                             .ToDictionary(x => x.Key, x => x.GroupBy(y => ((StringValue)y.Parameters["Algorithm Name"]).Value)
     183                                                                             .ToDictionary(y => y.Key, y => y.ToList()));
     184      ProblemInstances.UpdateOfRunsInProgress = true;
     185      try {
     186        instanceCounter = 0;
     187        foreach (var instance in ProblemInstances) {
     188          IItem probNameParam;
     189          if (!instance.Parameters.TryGetValue("Problem Name", out probNameParam)) continue;
     190          var probInstanceName = ((StringValue)probNameParam).Value;
     191
     192          double x = 0, y = 0;
     193          for (var feature = 0; feature < flaValues.Count; feature++) {
     194            x += ds[instanceCounter, feature] * v[feature, 0];
     195            y += ds[instanceCounter, feature] * v[feature, 1];
     196          }
     197          IItem item;
     198          if (instance.Results.TryGetValue("Projection.PCA1", out item)) {
     199            ((DoubleValue)item).Value = x;
     200          } else instance.Results.Add("Projection.PCA1", new DoubleValue(x));
     201          if (instance.Results.TryGetValue("Projection.PCA2", out item)) {
     202            ((DoubleValue)item).Value = y;
     203          } else instance.Results.Add("Projection.PCA2", new DoubleValue(y));
     204
     205          var bkQuality = ((DoubleValue)instance.Parameters["BestKnownQuality"]).Value;
     206          var maximization = ((BoolValue)instance.Parameters["Maximization"]).Value;
     207          foreach (var kvp in algInstRunDict[probInstanceName]) {
     208            var algInstanceName = kvp.Key;
     209            foreach (var run in kvp.Value) {
     210              // TODO: Things needs to be configurable here (table name, targets)
     211              foreach (var target in new[] { 1, 1.01, 1.05, 1.1, 1.2, 1.5 }) {
     212                var result = ExpectedRuntimeHelper.CalculateErt(kvp.Value, "QualityPerEvaluations", bkQuality * target, maximization);
     213                var resultName = algInstanceName + "@" + ((target - 1) * 100) + "%";
     214                if (run.Results.TryGetValue(resultName, out item))
     215                  ((DoubleValue)item).Value = result.ExpectedRuntime;
     216                else run.Results.Add(resultName, new DoubleValue(result.ExpectedRuntime));
     217              }
     218            }
     219          }
     220        }
     221      } finally { ProblemInstances.UpdateOfRunsInProgress = false; }
    140222    }
    141223
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/HeuristicLab.OptimizationExpertSystem-3.3.csproj

    r12860 r12957  
    7373  </PropertyGroup>
    7474  <ItemGroup>
     75    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     76      <SpecificVersion>False</SpecificVersion>
     77      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
     78      <Private>False</Private>
     79    </Reference>
    7580    <Reference Include="HeuristicLab.Collections-3.3">
    7681      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
Note: See TracChangeset for help on using the changeset viewer.