Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13485 for branches


Ignore:
Timestamp:
12/18/15 12:42:13 (9 years ago)
Author:
abeham
Message:

#2457:

  • fixed bugs in iterated sampling view
  • worked on download runs from okb feature
Location:
branches/PerformanceComparison
Files:
7 edited

Legend:

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

    r13475 r13485  
    2626using System.Linq;
    2727using System.Windows.Forms.DataVisualization.Charting;
    28 using HeuristicLab.MainForm.WindowsForms;
    29 using HeuristicLab.MainForm;
    3028using HeuristicLab.Analysis;
    3129using HeuristicLab.Common;
    3230using HeuristicLab.Data;
     31using HeuristicLab.MainForm;
     32using HeuristicLab.MainForm.WindowsForms;
    3333
    3434namespace HeuristicLab.Optimization.Views.RunCollectionViews {
     
    268268      bestProbability = 1.0;
    269269      var bestProbabilityEffort = 0.0;
     270      var succ = 0;
    270271      foreach (var d in data) {
    271272        if (double.IsNaN(d.Item2)) continue;
    272         double succ = 0.0, unsucc = 0.0;
    273         foreach (var e in data) {
    274           if (e.Item1 <= d.Item1 && HasAchievedTarget(maximization, e, target)) succ++;
    275           else if (e.Item1 >= d.Item1) unsucc++;
    276         }
     273        if (HasAchievedTarget(maximization, d, target)) succ++;
    277274        // probability of having no successful run with effort d.Item1
    278         var prob = (1.0 - succ / (succ + unsucc));
     275        var prob = (1.0 - succ / (double)data.Count);
    279276        // normalizing probability to effort 1 (assuming exponential convergence)
    280277        prob = Math.Pow(prob, 1.0 / d.Item1);
     
    293290    private void UpdateGraph(double cutoff, double bestProbability, double target, bool maximization) {
    294291      var table = (string)dataTableComboBox.SelectedItem;
    295       var result = ExpectedRuntimeHelper.CalculateErt(GetRunsFiltered().ToList(), table, target, maximization);
    296       var lambda = 1.0 / result.ExpectedRuntime;
    297292      var runs = GetRunsFiltered().Select(x => (IndexedDataTable<double>)x.Results[table]).ToList();
    298293      var evaluations = runs.SelectMany(x => x.Rows.First().Values.Select(y => y.Item1)).Distinct().OrderBy(x => x).ToList();
     
    332327      }
    333328
    334       var minimum = hits.First(x => x.Value > 0).Key;
    335 
    336329      enhancedChart.SuspendRepaint();
    337330
     
    346339      var series2 = enhancedChart.Series["rldApproximationSeries"];
    347340      series2.Points.Clear();
    348       foreach (var e in Enumerable.Range(0, (int)Math.Ceiling(evaluations.Max()))) {
    349         series2.Points.AddXY(e, Math.Max(0, 1.0 - Math.Exp(-lambda * (e - minimum))));
     341      var evalMax = evaluations.Max();
     342      var steps = evalMax / 100.0;
     343
     344      var result = ExpectedRuntimeHelper.CalculateErt(GetRunsFiltered().ToList(), table, target, maximization);
     345      var lambda = 1.0 / result.ExpectedRuntime;
     346      foreach (var e in Enumerable.Range(0, 100)) {
     347        var x = e * steps;
     348        series2.Points.AddXY(x, Math.Max(0, 1.0 - Math.Exp(-lambda * x)));
    350349      }
    351350      var series3 = enhancedChart.Series["optimalSeries"];
    352351      series3.Points.Clear();
    353       lambda = -Math.Log(bestProbability);
    354       foreach (var e in Enumerable.Range(0, (int)Math.Ceiling(evaluations.Max())))
    355         series3.Points.AddXY(e, Math.Max(0, 1.0 - Math.Exp(-lambda * (e - minimum))));
     352      if (bestProbability <= 0) bestProbability = 1 - lambda;
     353      foreach (var e in Enumerable.Range(0, 100)) {
     354        var x = e * steps;
     355        series3.Points.AddXY(x, Math.Max(0, 1.0 - Math.Pow(bestProbability, x)));
     356      }
    356357
    357358      enhancedChart.Annotations.Clear();
     
    359360        var annotation = new VerticalLineAnnotation();
    360361        annotation.AnchorDataPoint = series.Points[cutOffIdx];
    361         annotation.Height = -20;
     362        annotation.Height = series.Points[cutOffIdx].YValues[0] > enhancedChart.ChartAreas[series.ChartArea].AxisY.Maximum / 2.0 ? 10 : -10;
    362363        annotation.LineWidth = 2;
    363364        annotation.StartCap = LineAnchorCapStyle.Arrow;
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.Designer.cs

    r13475 r13485  
    4747      this.suggestedInstancesComboBox = new System.Windows.Forms.ComboBox();
    4848      this.runsTabPage = new System.Windows.Forms.TabPage();
    49       this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    5049      this.okbTabPage = new System.Windows.Forms.TabPage();
    5150      this.algorithmInstancesViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     
    5756      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    5857      this.okbDownloadButton = new System.Windows.Forms.Button();
     58      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     59      this.progressPanel = new System.Windows.Forms.Panel();
    5960      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6061      this.tabControl.SuspendLayout();
     
    230231      this.runsTabPage.UseVisualStyleBackColor = true;
    231232      //
    232       // runsView
    233       //
    234       this.runsView.Caption = "RunCollection View";
    235       this.runsView.Content = null;
    236       this.runsView.Dock = System.Windows.Forms.DockStyle.Fill;
    237       this.runsView.Location = new System.Drawing.Point(3, 3);
    238       this.runsView.Name = "runsView";
    239       this.runsView.ReadOnly = false;
    240       this.runsView.Size = new System.Drawing.Size(532, 329);
    241       this.runsView.TabIndex = 1;
    242       //
    243233      // okbTabPage
    244234      //
     235      this.okbTabPage.Controls.Add(this.progressPanel);
    245236      this.okbTabPage.Controls.Add(this.okbDownloadButton);
    246237      this.okbTabPage.Controls.Add(this.algorithmInstancesViewHost);
     
    351342      this.okbDownloadButton.UseVisualStyleBackColor = true;
    352343      this.okbDownloadButton.Click += new System.EventHandler(this.okbDownloadButton_Click);
     344      //
     345      // runsView
     346      //
     347      this.runsView.Caption = "RunCollection View";
     348      this.runsView.Content = null;
     349      this.runsView.Dock = System.Windows.Forms.DockStyle.Fill;
     350      this.runsView.Location = new System.Drawing.Point(3, 3);
     351      this.runsView.Name = "runsView";
     352      this.runsView.ReadOnly = false;
     353      this.runsView.Size = new System.Drawing.Size(532, 329);
     354      this.runsView.TabIndex = 1;
     355      //
     356      // progressPanel
     357      //
     358      this.progressPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     359            | System.Windows.Forms.AnchorStyles.Left)
     360            | System.Windows.Forms.AnchorStyles.Right)));
     361      this.progressPanel.Location = new System.Drawing.Point(6, 35);
     362      this.progressPanel.Name = "progressPanel";
     363      this.progressPanel.Size = new System.Drawing.Size(526, 294);
     364      this.progressPanel.TabIndex = 2;
     365      this.progressPanel.Visible = false;
    353366      //
    354367      // ExpertSystemView
     
    405418    private MainForm.WindowsForms.ViewHost problemInstancesView;
    406419    private System.Windows.Forms.Button okbDownloadButton;
     420    private System.Windows.Forms.Panel progressPanel;
    407421  }
    408422}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs

    r13475 r13485  
    2323using System.Collections;
    2424using System.ComponentModel;
    25 using System.IO;
    2625using System.Linq;
    2726using System.Windows.Forms;
    28 using HeuristicLab.Clients.OKB.Administration;
    29 using HeuristicLab.Clients.OKB.Query;
    3027using HeuristicLab.Common;
    3128using HeuristicLab.Common.Resources;
    32 using HeuristicLab.Core;
    3329using HeuristicLab.Core.Views;
    3430using HeuristicLab.MainForm;
    3531using HeuristicLab.Optimization;
    36 using HeuristicLab.Persistence.Default.Xml;
    3732using HeuristicLab.PluginInfrastructure;
    3833
     
    4338    protected TypeSelectorDialog problemTypeSelectorDialog;
    4439    protected virtual bool SuppressEvents { get; set; }
     40    private bool okbDownloadInProgress;
    4541
    4642    public new ExpertSystem Content {
     
    8581      base.OnContentChanged();
    8682      SuppressEvents = true;
     83      okbDownloadInProgress = false;
    8784      try {
    8885        if (Content == null) {
     
    114111      algorithmViewHost.Enabled = Content != null && !ReadOnly && !Locked;
    115112      runsView.Enabled = Content != null;
    116       algorithmInstancesViewHost.Enabled = Content != null;
     113      algorithmInstancesViewHost.Enabled = Content != null && !okbDownloadInProgress;
    117114      refreshMapButton.Enabled = Content != null;
    118       okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked;
     115      okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked && !okbDownloadInProgress;
    119116    }
    120117
     
    293290
    294291    private void okbDownloadButton_Click(object sender, EventArgs e) {
    295       var queryClient = QueryClient.Instance;
    296       queryClient.Refresh();
    297 
    298       var problemTypeFilter = (StringComparisonAvailableValuesFilter)queryClient.Filters.Single(x => x.Label == "Problem Data Type Name");
    299       problemTypeFilter.Value = Content.Problem.GetType().Name;
    300 
    301       var runIds = queryClient.GetRunIds(problemTypeFilter).ToList();
    302       var count = queryClient.GetNumberOfRuns(problemTypeFilter);
    303       if (count > 0) {
    304         var list = new ItemList<IAlgorithm>();
    305         var adminClient = AdministrationClient.Instance;
    306         adminClient.Refresh();
    307         var runs = queryClient.GetRuns(runIds, true).ToList();
    308         foreach (var rGroup in runs.GroupBy(x => x.Algorithm.Id)) {
    309           var data = AdministrationClient.GetAlgorithmData(rGroup.Key);
    310           if (data != null) {
    311             using (var stream = new MemoryStream(data)) {
    312               try {
    313                 var alg = (IAlgorithm)XmlParser.Deserialize<IContent>(stream);
    314                 alg.Runs.AddRange(rGroup.Select(x => queryClient.ConvertToOptimizationRun(x)));
    315                 list.Add(alg);
    316               } catch (Exception) { }
    317               stream.Close();
    318             }
    319           }
    320         }
    321         Content.AlgorithmInstances = list;
     292      var progress = new Progress();
     293      progress.ProgressStateChanged += OkbDownloadProgressOnStateChanged;
     294      Content.UpdateKnowledgeBaseAsync(progress);
     295      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(progressPanel, progress);
     296      progressPanel.Visible = true;
     297      SetEnabledStateOfControls();
     298    }
     299
     300    private void OkbDownloadProgressOnStateChanged(object sender, EventArgs eventArgs) {
     301      var progress = (IProgress)sender;
     302      okbDownloadInProgress = progress.ProgressState == ProgressState.Started;
     303      SetEnabledStateOfControls();
     304      if (!okbDownloadInProgress) {
     305        progressPanel.Visible = false;
     306        progress.ProgressStateChanged -= OkbDownloadProgressOnStateChanged;
    322307      }
    323308    }
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.resx

    r13475 r13485  
    121121    <value>17, 17</value>
    122122  </metadata>
     123  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     124    <value>17, 17</value>
     125  </metadata>
    123126  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124127    <value>140, 17</value>
     
    128131    <value>
    129132        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6
    130         JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAACXBIWXMAAAsPAAALDwGS+QOlAAACeUlE
     133        JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAACXBIWXMAAAsMAAALDAE/QCLIAAACeUlE
    131134        QVQ4T6WSWUiUURiG/4suurJIjUIwskQsEAMjqosQpUVNKbdCSRPKrQVDMddmXEedGdcpFXNGnUYdrSzF
    132135        sEIoFInQcqHE1CwoKsXUUMnt6XfEye0munjgnO+c9+HjO0cA/osNi2tJLdA6SXN13MwoI12lJ06uiV8+
     
    145148    <value>
    146149        iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6
    147         JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAACXBIWXMAAAsPAAALDwGS+QOlAAABmElE
     150        JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAACXBIWXMAAAsMAAALDAE/QCLIAAABmElE
    148151        QVQ4T42QTUsCURSGJWgVtWkb9AfatKhN1L4I2rRoX9BvEIJ+QG4qFNKKCAMtEPqAUMiKamESEmpoWiKa
    149152        YuZnmuOo83bufKUYgy+8c849957n3jk6ALJXOWAxBAulfrKwEAOW+L/9/y0locEzXs9SI3BB8UXKxVp1
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ExpertSystem.cs

    r13475 r13485  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.ComponentModel;
    24 using System.Collections.Generic;
    2525using System.Drawing;
     26using System.IO;
    2627using System.Linq;
     28using System.Threading.Tasks;
    2729using HeuristicLab.Analysis;
     30using HeuristicLab.Common;
     31using HeuristicLab.Common.Resources;
    2832using HeuristicLab.Core;
     33using HeuristicLab.Data;
     34using HeuristicLab.MainForm;
    2935using HeuristicLab.Optimization;
    3036using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Common;
    32 using HeuristicLab.Common.Resources;
    33 using HeuristicLab.Data;
     37using HeuristicLab.Persistence.Default.Xml;
    3438
    3539namespace HeuristicLab.OptimizationExpertSystem {
     
    222226        }
    223227      } finally { ProblemInstances.UpdateOfRunsInProgress = false; }
     228    }
     229
     230    private static readonly HashSet<string> InterestingValueNames = new HashSet<string>() {
     231      "QualityPerEvaluations", "Problem Name", "Problem Type", "Algorithm Name", "Algorithm Type", "Maximization"
     232    };
     233
     234    public async void UpdateKnowledgeBaseAsync(IProgress progress) {
     235      progress.Start("Updating Knowledge Base from OKB");
     236      await Task.Factory.StartNew(() => { DoUpdateKnowledgeBase(progress); }, TaskCreationOptions.LongRunning);
     237    }
     238
     239    public void UpdateKnowledgeBase() {
     240      DoUpdateKnowledgeBase(new Progress(string.Empty, ProgressState.Started));
     241    }
     242
     243    private void DoUpdateKnowledgeBase(IProgress progress) {
     244      var queryClient = Clients.OKB.Query.QueryClient.Instance;
     245      var adminClient = Clients.OKB.Administration.AdministrationClient.Instance;
     246      try {
     247        progress.Status = "Refreshing query client...";
     248        queryClient.Refresh();
     249        var interestingValues = queryClient.ValueNames.Where(x => InterestingValueNames.Contains(x.Name)).ToList();
     250
     251        var problemTypeFilter = (Clients.OKB.Query.StringComparisonAvailableValuesFilter)queryClient.Filters.Single(x => x.Label == "Problem Data Type Name");
     252        problemTypeFilter.Value = Problem.GetType().Name;
     253
     254        progress.Status = "Obtaining number of runs...";
     255        var count = queryClient.GetNumberOfRuns(problemTypeFilter);
     256        if (count == 0) return;
     257
     258        var runIds = queryClient.GetRunIds(problemTypeFilter).ToList();
     259        adminClient.Refresh();
     260        var i = 0;
     261        var conversions = new List<Task>();
     262        var runGroup = new Dictionary<Tuple<long, string>, List<IRun>>();
     263        while (i < count) {
     264          var nextIds = runIds.Skip(i).Take(500).ToList();
     265          progress.Status = string.Format("Downloading runs {0} to {1} of {2}...", i, i + nextIds.Count, count);
     266          var okbRuns = queryClient.GetRunsWithValues(nextIds, true, interestingValues);
     267          conversions.Add(Task.Factory.StartNew(() => {
     268            var hlRuns = okbRuns.AsParallel().Select(x => new { Id = x.Algorithm.Id, Name = x.Algorithm.Name, Run = queryClient.ConvertToOptimizationRun(x) })
     269                                .GroupBy(x => Tuple.Create(x.Id, x.Name)).ToList();
     270            lock (runGroup) {
     271              foreach (var hr in hlRuns) {
     272                List<IRun> runList;
     273                if (!runGroup.TryGetValue(hr.Key, out runList)) {
     274                  runList = new List<IRun>();
     275                  runGroup[hr.Key] = runList;
     276                }
     277                runList.AddRange(hr.Select(x => x.Run));
     278              }
     279            }
     280          }));
     281          i += nextIds.Count;
     282          progress.ProgressValue = 0.8 * (i / (double)count);
     283        }
     284        Task.WaitAll(conversions.ToArray());
     285        var list = new ItemList<IAlgorithm>();
     286        i = 0;
     287        foreach (var rGroup in runGroup) {
     288          progress.Status = string.Format("Downloading algorithm {0}...", rGroup.Key.Item2);
     289          var data = Clients.OKB.Administration.AdministrationClient.GetAlgorithmData(rGroup.Key.Item1);
     290          if (data != null) {
     291            using (var stream = new MemoryStream(data)) {
     292              try {
     293                var alg = (IAlgorithm)XmlParser.Deserialize<IContent>(stream);
     294                alg.Runs.AddRange(rGroup.Value);
     295                list.Add(alg);
     296              } catch (Exception) { }
     297              stream.Close();
     298            }
     299          }
     300          i++;
     301          progress.ProgressValue = 0.8 + 0.2 * (i / (double)runGroup.Count);
     302        }
     303        AlgorithmInstances = list;
     304      } finally { progress.Finish(); }
    224305    }
    225306
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/HeuristicLab.OptimizationExpertSystem-3.3.csproj

    r12957 r13485  
    7878      <Private>False</Private>
    7979    </Reference>
     80    <Reference Include="HeuristicLab.Clients.OKB-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     81      <SpecificVersion>False</SpecificVersion>
     82      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Clients.OKB-3.3.dll</HintPath>
     83      <Private>False</Private>
     84    </Reference>
    8085    <Reference Include="HeuristicLab.Collections-3.3">
    8186      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     
    99104      <Private>False</Private>
    100105    </Reference>
     106    <Reference Include="HeuristicLab.MainForm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     107      <SpecificVersion>False</SpecificVersion>
     108      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm-3.3.dll</HintPath>
     109      <Private>False</Private>
     110    </Reference>
    101111    <Reference Include="HeuristicLab.Persistence-3.3">
    102112      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     
    110120    <Reference Include="System.Core" />
    111121    <Reference Include="System.Drawing" />
     122    <Reference Include="System.Runtime.Serialization" />
    112123    <Reference Include="System.Xml.Linq" />
    113124    <Reference Include="System.Data.DataSetExtensions" />
  • branches/PerformanceComparison/PerformanceComparison.sln

    r12842 r13485  
    22Microsoft Visual Studio Solution File, Format Version 12.00
    33# Visual Studio 2013
    4 VisualStudioVersion = 12.0.31101.0
     4VisualStudioVersion = 12.0.40629.0
    55MinimumVisualStudioVersion = 10.0.40219.1
    66Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Analysis-3.3", "HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj", "{887425B4-4348-49ED-A457-B7D2C26DDBF9}"
     
    102102    HideSolutionNode = FALSE
    103103  EndGlobalSection
     104  GlobalSection(Performance) = preSolution
     105    HasPerformanceSessions = true
     106  EndGlobalSection
    104107EndGlobal
Note: See TracChangeset for help on using the changeset viewer.