Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12957


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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.Designer.cs

    r12860 r12957  
    4848      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    4949      this.okbTabPage = new System.Windows.Forms.TabPage();
     50      this.algorithmInstancesViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     51      this.problemInstancesTabPage = new System.Windows.Forms.TabPage();
     52      this.problemInstancesView = new HeuristicLab.Optimization.Views.RunCollectionBubbleChartView();
    5053      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    51       this.algorithmInstancesViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5254      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5355      this.tabControl.SuspendLayout();
     
    5658      this.runsTabPage.SuspendLayout();
    5759      this.okbTabPage.SuspendLayout();
     60      this.problemInstancesTabPage.SuspendLayout();
    5861      this.SuspendLayout();
    5962      //
     
    98101      this.tabControl.Controls.Add(this.runsTabPage);
    99102      this.tabControl.Controls.Add(this.okbTabPage);
     103      this.tabControl.Controls.Add(this.problemInstancesTabPage);
    100104      this.tabControl.Location = new System.Drawing.Point(0, 52);
    101105      this.tabControl.Name = "tabControl";
     
    242246      this.okbTabPage.UseVisualStyleBackColor = true;
    243247      //
    244       // openFileDialog
    245       //
    246       this.openFileDialog.DefaultExt = "hl";
    247       this.openFileDialog.FileName = "Optimizer";
    248       this.openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
    249       this.openFileDialog.Title = "Open Optimizer";
    250       //
    251248      // algorithmInstancesViewHost
    252249      //
     
    263260      this.algorithmInstancesViewHost.ViewType = null;
    264261      //
    265       // ExpertSystemOptimizerView
     262      // problemInstancesTabPage
     263      //
     264      this.problemInstancesTabPage.Controls.Add(this.problemInstancesView);
     265      this.problemInstancesTabPage.Location = new System.Drawing.Point(4, 22);
     266      this.problemInstancesTabPage.Name = "problemInstancesTabPage";
     267      this.problemInstancesTabPage.Padding = new System.Windows.Forms.Padding(3);
     268      this.problemInstancesTabPage.Size = new System.Drawing.Size(538, 335);
     269      this.problemInstancesTabPage.TabIndex = 6;
     270      this.problemInstancesTabPage.Text = "Problem Instances";
     271      this.problemInstancesTabPage.UseVisualStyleBackColor = true;
     272      //
     273      // problemInstancesView
     274      //
     275      this.problemInstancesView.BackColor = System.Drawing.SystemColors.Window;
     276      this.problemInstancesView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     277      this.problemInstancesView.Caption = "Bubble Chart";
     278      this.problemInstancesView.Content = null;
     279      this.problemInstancesView.Dock = System.Windows.Forms.DockStyle.Fill;
     280      this.problemInstancesView.Location = new System.Drawing.Point(3, 3);
     281      this.problemInstancesView.Name = "problemInstancesView";
     282      this.problemInstancesView.ReadOnly = false;
     283      this.problemInstancesView.Size = new System.Drawing.Size(532, 329);
     284      this.problemInstancesView.TabIndex = 0;
     285      //
     286      // openFileDialog
     287      //
     288      this.openFileDialog.DefaultExt = "hl";
     289      this.openFileDialog.FileName = "Optimizer";
     290      this.openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
     291      this.openFileDialog.Title = "Open Optimizer";
     292      //
     293      // ExpertSystemView
    266294      //
    267295      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     
    269297      this.Controls.Add(this.evaluationsLimitabel);
    270298      this.Controls.Add(this.maxEvaluationsTextBox);
    271       this.Name = "ExpertSystemOptimizerView";
     299      this.Name = "ExpertSystemView";
    272300      this.Size = new System.Drawing.Size(549, 413);
    273301      this.Controls.SetChildIndex(this.maxEvaluationsTextBox, 0);
     
    284312      this.runsTabPage.ResumeLayout(false);
    285313      this.okbTabPage.ResumeLayout(false);
     314      this.problemInstancesTabPage.ResumeLayout(false);
    286315      this.ResumeLayout(false);
    287316      this.PerformLayout();
     
    307336    private System.Windows.Forms.TabPage okbTabPage;
    308337    private MainForm.WindowsForms.ViewHost algorithmInstancesViewHost;
     338    private System.Windows.Forms.TabPage problemInstancesTabPage;
     339    private Optimization.Views.RunCollectionBubbleChartView problemInstancesView;
    309340  }
    310341}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/HeuristicLab.OptimizationExpertSystem.Views-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, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    7681      <SpecificVersion>False</SpecificVersion>
     
    121126      <SpecificVersion>False</SpecificVersion>
    122127      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     128      <Private>False</Private>
     129    </Reference>
     130    <Reference Include="HeuristicLab.Visualization.ChartControlsExtensions-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     131      <SpecificVersion>False</SpecificVersion>
     132      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Visualization.ChartControlsExtensions-3.3.dll</HintPath>
    123133      <Private>False</Private>
    124134    </Reference>
  • 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.