Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/14/16 01:20:10 (8 years ago)
Author:
abeham
Message:

#2457: worked on suggestion algorithm

Location:
branches/PerformanceComparison
Files:
3 edited

Legend:

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

    r13757 r13759  
    131131    public KnowledgeCenter() {
    132132      maximumEvaluations = new IntValue(10000);
    133       minimumTarget = new DoubleValue(1.05);
     133      minimumTarget = new DoubleValue(0.05);
    134134      instanceRuns = new RunCollection();
    135135      seededRuns = new RunCollection();
     
    140140      problemCharacteristics = new CheckedItemList<StringValue>();
    141141      problemInstanceProximity = new EnumValue<ProblemInstanceProximityType>(ProblemInstanceProximityType.FeatureSpace);
    142       problemInstanceNeighborhoodFactor = new DoubleValue(1);
     142      problemInstanceNeighborhoodFactor = new DoubleValue(5);
    143143      readonlyProblemCharacteristics = problemCharacteristics.AsReadOnly();
    144144      problem = new SingleObjectiveOKBProblem();
     
    455455        progress.ProgressValue = 0;
    456456        // FIXME: How to tell if refresh is necessary?
    457         queryClient.Refresh();
    458         progress.ProgressValue = 0.5;
    459         progress.Status = "Downloading algorithm and problem instance information...";
    460         // FIXME: How to tell if refresh is necessary?
    461         adminClient.Refresh();
     457        var refreshTasks = new[] {
     458          Task.Factory.StartNew(() => queryClient.Refresh()),
     459          Task.Factory.StartNew(() => adminClient.Refresh())
     460        };
     461        Task.WaitAll(refreshTasks);
    462462
    463463        var probInstance = adminClient.Problems.SingleOrDefault(x => x.Id == Problem.ProblemId);
     
    476476        var characteristics = new HashSet<string>();
    477477        var totalProblems = adminClient.Problems.Count(x => x.ProblemClassId == probClassId);
    478         Parallel.ForEach(adminClient.Problems.Where(x => x.ProblemClassId == probClassId), (pInst) => {
     478        Parallel.ForEach(adminClient.Problems.Where(x => x.ProblemClassId == probClassId), new ParallelOptions { MaxDegreeOfParallelism = 3 }, (pInst) => {
    479479          var charas = new List<string>();
    480480          IRun probRun = null;
     
    512512        progress.ProgressValue = 0;
    513513        p[0] = 0;
    514         Parallel.ForEach(adminClient.Algorithms, (algInst) => {
     514        Parallel.ForEach(adminClient.Algorithms, new ParallelOptions { MaxDegreeOfParallelism = 3 }, (algInst) => {
    515515          IAlgorithm alg = null;
    516516          var data = Clients.OKB.Administration.AdministrationClient.GetAlgorithmData(algInst.Id);
     
    544544        var runIds = queryClient.GetRunIds(problemClassFilter).ToList();
    545545        var batches = runIds.Select((v, i) => new { Idx = i, Val = v }).GroupBy(x => x.Idx / 500, x => x.Val);
    546         Parallel.ForEach(batches.Select(x => x.ToList()), (batch) => {
     546        Parallel.ForEach(batches.Select(x => x.ToList()), new ParallelOptions { MaxDegreeOfParallelism = 3 }, (batch) => {
    547547          var okbRuns = queryClient.GetRunsWithValues(batch, true, interestingValues);
    548548          var hlRuns = okbRuns.AsParallel().Select(x => new { AlgorithmId = x.Algorithm.Id, Run = queryClient.ConvertToOptimizationRun(x) }).ToList();
     
    630630      if (Problem == null) return;
    631631      var piDistances = GetProblemDistances();
    632       var maxDistance = piDistances.Max();
    633       // Weighted combination of algorithm performances using distance-based exponentially falling weights
    634       // Scale distances by maxDistance
    635       // Parameter to influence dampening factor
    636       // Algorithm performances are given in expected run time
    637       // Using convergence graphs up to maximum evaluations effort
    638       // Care has to be taken if not every algorithm has been executed on every problem instance
     632      var maxDist = piDistances.Max(x => x.Value);
    639633      var instances = new SortedList<double, IAlgorithm>();
    640634      foreach (var relevantRuns in knowledgeBase.GroupBy(x => algorithmId2RunMapping.GetBySecond(x).Single())) {
    641635        var algorithm = algorithmId2AlgorithmInstanceMapping.GetByFirst(relevantRuns.Key);
    642         var avgQuality = 0.0;
    643         var counter = 0;
     636        Func<double, double> distFunc = (d) => Math.Exp(ProblemInstanceNeighborhoodFactor.Value * (-d / maxDist));
     637        var pis = relevantRuns.Select(x => ((StringValue)x.Parameters["Problem Name"]).Value).Distinct()
     638                              .Select(x => Tuple.Create(x, ProblemInstances.SingleOrDefault(y => ((StringValue)y.Parameters["Problem Name"]).Value == x)))
     639                              .Where(x => x.Item2 != null)
     640                              .Select(x => Tuple.Create(x.Item1, distFunc(piDistances[x.Item2]), ((DoubleValue)x.Item2.Parameters["BestKnownQuality"]).Value))
     641                              .ToDictionary(x => x.Item1, x => Tuple.Create(x.Item2, x.Item3));
     642        var sumPis = pis.Sum(x => x.Value.Item1);
     643        var avgERT = 0.0;
    644644        foreach (var problemRuns in relevantRuns.GroupBy(x => ((StringValue)x.Parameters["Problem Name"]).Value)) {
    645           var probInstance = ProblemInstances.SingleOrDefault(x => x.Name == problemRuns.Key);
    646           if (probInstance == null) continue;
    647           var bkQuality = ((DoubleValue)probInstance.Parameters["BestKnownQuality"]).Value;
     645          Tuple<double, double> info;
     646          if (!pis.TryGetValue(problemRuns.Key, out info)) continue;
     647          var convGraph = new List<List<Tuple<double, double>>>();
    648648          foreach (var run in problemRuns) {
     649            var current = new List<Tuple<double, double>>();
    649650            var performanceGraph = ((IndexedDataTable<double>)run.Results["QualityPerEvaluations"]);
    650             try {
    651               avgQuality += performanceGraph.Rows.First().Values.TakeWhile(x => x.Item1 < MaximumEvaluations.Value).Last().Item2 / bkQuality;
    652               counter++;
    653             } catch {
    654               continue;
    655             }
    656           }
    657         }
    658         avgQuality /= counter;
    659         instances.Add(avgQuality, algorithm);
     651            current.AddRange(performanceGraph.Rows.First().Values.TakeWhile(v => v.Item1 < MaximumEvaluations.Value));
     652            if (current.Count > 0) {
     653              current.Add(Tuple.Create((double)MaximumEvaluations.Value, current.Last().Item2));
     654              convGraph.Add(current);
     655            }
     656          }
     657          var ert = ExpectedRuntimeHelper.CalculateErt(convGraph, (Maximization ? (1 - MinimumTarget.Value) : (1 + MinimumTarget.Value)) * info.Item2, Maximization).ExpectedRuntime;
     658          if (double.IsNaN(ert)) {
     659            ert = ExpectedRuntimeHelper.CalculateErt(problemRuns.ToList(), "QualityPerEvaluations", (Maximization ? (1 - MinimumTarget.Value) : (1 + MinimumTarget.Value)) * info.Item2, Maximization).ExpectedRuntime;
     660            if (double.IsNaN(ert)) ert = int.MaxValue;
     661          }
     662          avgERT += info.Item1 * ert;
     663        }
     664        avgERT /= sumPis;
     665        if (instances.ContainsKey(avgERT)) {
     666          avgERT += new System.Random().NextDouble();
     667        }
     668        instances.Add(avgERT, algorithm);
    660669      }
    661670
    662671      var instanceLadder = instances.Select(x => (IAlgorithm)x.Value.Clone()).ToList();
    663       if (Maximization) instanceLadder.Reverse();
    664672      suggestedInstances.Replace(instanceLadder);
    665673    }
    666674
    667     private DoubleMatrix GetProblemDistances() {
    668       var matrix = new DoubleMatrix(ProblemInstances.Count, ProblemInstances.Count);
     675    private Dictionary<IRun, double> GetProblemDistances() {
     676      var result = new Dictionary<IRun, double>();
     677      var currentInstance = problemId2ProblemInstanceMapping.GetByFirst(Problem.ProblemId);
    669678      switch (ProblemInstanceProximity.Value) {
    670679        case ProblemInstanceProximityType.MDS:
    671680        case ProblemInstanceProximityType.PCA:
    672681        case ProblemInstanceProximityType.SOM:
    673           int i = 0, j = 0;
    674           foreach (var a in ProblemInstances) {
    675             double xa, ya;
    676             GetProjectionCoordinates(a, out xa, out ya);
    677             j = 0;
    678             foreach (var b in ProblemInstances) {
    679               double xb, yb;
    680               GetProjectionCoordinates(b, out xb, out yb);
    681               matrix[i, j] = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
    682               j++;
    683             }
    684             i++;
     682          double xa, ya;
     683          GetProjectionCoordinates(currentInstance, out xa, out ya);
     684          foreach (var b in ProblemInstances) {
     685            double xb, yb;
     686            GetProjectionCoordinates(b, out xb, out yb);
     687            var d = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));
     688            result[b] = d;
    685689          }
    686690          break;
    687691        case ProblemInstanceProximityType.FeatureSpace:
    688           int k = 0, l = 0;
    689692          var features = GetProblemCharacteristics();
    690           foreach (var a in ProblemInstances) {
    691             l = 0;
    692             var fa = features[a];
    693             foreach (var b in ProblemInstances) {
    694               var sum = features[b].Select((t, f) => (fa[f] - t) * (fa[f] - t)).Sum();
    695               matrix[k, l] = Math.Sqrt(sum);
    696               l++;
    697             }
    698             k++;
     693          var cF = features[currentInstance];
     694          foreach (var b in ProblemInstances) {
     695            var sum = features[b].Select((t, f) => (cF[f] - t) * (cF[f] - t)).Sum();
     696            result[b] = Math.Sqrt(sum);
    699697          }
    700698          break;
    701699        default: throw new InvalidOperationException(string.Format("Unkonwn proximity type {0}", ProblemInstanceProximity.Value));
    702700      }
    703       return matrix;
     701      return result;
    704702    }
    705703
     
    707705      x = ((DoubleValue)problemInstance.Results["Projection." + ProblemInstanceProximity.Value + ".X"]).Value;
    708706      y = ((DoubleValue)problemInstance.Results["Projection." + ProblemInstanceProximity.Value + ".Y"]).Value;
     707      if (ProblemInstanceProximity.Value == ProblemInstanceProximityType.SOM) {
     708        x = Math.Floor(x);
     709        y = Math.Floor(y);
     710      }
    709711    }
    710712
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/SolverView.Designer.cs

    r13722 r13759  
    6060      WeifenLuo.WinFormsUI.Docking.TabGradient tabGradient6 = new WeifenLuo.WinFormsUI.Docking.TabGradient();
    6161      WeifenLuo.WinFormsUI.Docking.TabGradient tabGradient7 = new WeifenLuo.WinFormsUI.Docking.TabGradient();
     62      this.minTargetView = new HeuristicLab.Data.Views.StringConvertibleValueView();
     63      this.maxEvaluationsView = new HeuristicLab.Data.Views.StringConvertibleValueView();
     64      this.algorithmCloneButton = new System.Windows.Forms.Button();
    6265      this.seedingStrategyPanel = new System.Windows.Forms.Panel();
    6366      this.solverTabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
     
    6770      this.runsTabPage = new System.Windows.Forms.TabPage();
    6871      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     72      this.seededRunsTabPage = new System.Windows.Forms.TabPage();
     73      this.seededRunsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    6974      this.solutionSeedingTabPage = new System.Windows.Forms.TabPage();
    7075      this.parametersTabPage = new System.Windows.Forms.TabPage();
     
    7378      this.operatorGraphViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    7479      this.algorithmStartButton = new System.Windows.Forms.Button();
    75       this.label1 = new System.Windows.Forms.Label();
     80      this.minimumTargetLabel = new System.Windows.Forms.Label();
     81      this.seedingStrategyLabel = new System.Windows.Forms.Label();
    7682      this.evaluationsLimitabel = new System.Windows.Forms.Label();
    7783      this.algorithmSuggestionLabel = new System.Windows.Forms.Label();
    7884      this.suggestedInstancesComboBox = new System.Windows.Forms.ComboBox();
    79       this.algorithmCloneButton = new System.Windows.Forms.Button();
    80       this.maxEvaluationsView = new HeuristicLab.Data.Views.StringConvertibleValueView();
    81       this.seededRunsTabPage = new System.Windows.Forms.TabPage();
    82       this.seededRunsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    8385      this.solverTabControl.SuspendLayout();
    8486      this.resultsTabPage.SuspendLayout();
    8587      this.runsTabPage.SuspendLayout();
     88      this.seededRunsTabPage.SuspendLayout();
    8689      this.parametersTabPage.SuspendLayout();
    8790      this.operatorGraphTabPage.SuspendLayout();
    88       this.seededRunsTabPage.SuspendLayout();
    8991      this.SuspendLayout();
     92      //
     93      // minTargetView
     94      //
     95      this.minTargetView.Caption = "StringConvertibleValue View";
     96      this.minTargetView.Content = null;
     97      this.minTargetView.LabelVisible = false;
     98      this.minTargetView.Location = new System.Drawing.Point(431, 3);
     99      this.minTargetView.Name = "minTargetView";
     100      this.minTargetView.ReadOnly = false;
     101      this.minTargetView.Size = new System.Drawing.Size(255, 21);
     102      this.minTargetView.TabIndex = 16;
     103      //
     104      // maxEvaluationsView
     105      //
     106      this.maxEvaluationsView.Caption = "StringConvertibleValue View";
     107      this.maxEvaluationsView.Content = null;
     108      this.maxEvaluationsView.LabelVisible = false;
     109      this.maxEvaluationsView.Location = new System.Drawing.Point(91, 3);
     110      this.maxEvaluationsView.Name = "maxEvaluationsView";
     111      this.maxEvaluationsView.ReadOnly = false;
     112      this.maxEvaluationsView.Size = new System.Drawing.Size(255, 21);
     113      this.maxEvaluationsView.TabIndex = 16;
     114      //
     115      // algorithmCloneButton
     116      //
     117      this.algorithmCloneButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     118      this.algorithmCloneButton.Location = new System.Drawing.Point(823, 56);
     119      this.algorithmCloneButton.Name = "algorithmCloneButton";
     120      this.algorithmCloneButton.Size = new System.Drawing.Size(26, 23);
     121      this.algorithmCloneButton.TabIndex = 15;
     122      this.algorithmCloneButton.Text = "Clone";
     123      this.algorithmCloneButton.UseVisualStyleBackColor = true;
     124      this.algorithmCloneButton.Click += new System.EventHandler(this.AlgorithmCloneButtonOnClick);
    90125      //
    91126      // seedingStrategyPanel
     
    217252      this.runsView.TabIndex = 0;
    218253      //
     254      // seededRunsTabPage
     255      //
     256      this.seededRunsTabPage.Controls.Add(this.seededRunsView);
     257      this.seededRunsTabPage.Location = new System.Drawing.Point(4, 22);
     258      this.seededRunsTabPage.Name = "seededRunsTabPage";
     259      this.seededRunsTabPage.Padding = new System.Windows.Forms.Padding(3);
     260      this.seededRunsTabPage.Size = new System.Drawing.Size(841, 454);
     261      this.seededRunsTabPage.TabIndex = 5;
     262      this.seededRunsTabPage.Text = "Seeded Runs";
     263      this.seededRunsTabPage.UseVisualStyleBackColor = true;
     264      //
     265      // seededRunsView
     266      //
     267      this.seededRunsView.Caption = "RunCollection View";
     268      this.seededRunsView.Content = null;
     269      this.seededRunsView.Dock = System.Windows.Forms.DockStyle.Fill;
     270      this.seededRunsView.Location = new System.Drawing.Point(3, 3);
     271      this.seededRunsView.Name = "seededRunsView";
     272      this.seededRunsView.ReadOnly = false;
     273      this.seededRunsView.Size = new System.Drawing.Size(835, 448);
     274      this.seededRunsView.TabIndex = 1;
     275      //
    219276      // solutionSeedingTabPage
    220277      //
     
    287344      this.algorithmStartButton.Click += new System.EventHandler(this.AlgorithmStartButtonOnClick);
    288345      //
    289       // label1
    290       //
    291       this.label1.AutoSize = true;
    292       this.label1.Location = new System.Drawing.Point(3, 33);
    293       this.label1.Name = "label1";
    294       this.label1.Size = new System.Drawing.Size(91, 13);
    295       this.label1.TabIndex = 8;
    296       this.label1.Text = "Seeding Strategy:";
     346      // minimumTargetLabel
     347      //
     348      this.minimumTargetLabel.AutoSize = true;
     349      this.minimumTargetLabel.Location = new System.Drawing.Point(384, 6);
     350      this.minimumTargetLabel.Name = "minimumTargetLabel";
     351      this.minimumTargetLabel.Size = new System.Drawing.Size(41, 13);
     352      this.minimumTargetLabel.TabIndex = 13;
     353      this.minimumTargetLabel.Text = "Target:";
     354      //
     355      // seedingStrategyLabel
     356      //
     357      this.seedingStrategyLabel.AutoSize = true;
     358      this.seedingStrategyLabel.Location = new System.Drawing.Point(3, 33);
     359      this.seedingStrategyLabel.Name = "seedingStrategyLabel";
     360      this.seedingStrategyLabel.Size = new System.Drawing.Size(91, 13);
     361      this.seedingStrategyLabel.TabIndex = 8;
     362      this.seedingStrategyLabel.Text = "Seeding Strategy:";
    297363      //
    298364      // evaluationsLimitabel
     
    326392      this.suggestedInstancesComboBox.SelectedIndexChanged += new System.EventHandler(this.SuggestedInstancesComboBoxOnSelectedIndexChanged);
    327393      //
    328       // algorithmCloneButton
    329       //
    330       this.algorithmCloneButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    331       this.algorithmCloneButton.Location = new System.Drawing.Point(823, 56);
    332       this.algorithmCloneButton.Name = "algorithmCloneButton";
    333       this.algorithmCloneButton.Size = new System.Drawing.Size(26, 23);
    334       this.algorithmCloneButton.TabIndex = 15;
    335       this.algorithmCloneButton.Text = "Clone";
    336       this.algorithmCloneButton.UseVisualStyleBackColor = true;
    337       this.algorithmCloneButton.Click += new System.EventHandler(this.AlgorithmCloneButtonOnClick);
    338       //
    339       // maxEvaluationsView
    340       //
    341       this.maxEvaluationsView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    342             | System.Windows.Forms.AnchorStyles.Right)));
    343       this.maxEvaluationsView.Caption = "StringConvertibleValue View";
    344       this.maxEvaluationsView.Content = null;
    345       this.maxEvaluationsView.LabelVisible = false;
    346       this.maxEvaluationsView.Location = new System.Drawing.Point(91, 3);
    347       this.maxEvaluationsView.Name = "maxEvaluationsView";
    348       this.maxEvaluationsView.ReadOnly = false;
    349       this.maxEvaluationsView.Size = new System.Drawing.Size(758, 21);
    350       this.maxEvaluationsView.TabIndex = 16;
    351       //
    352       // seededRunsTabPage
    353       //
    354       this.seededRunsTabPage.Controls.Add(this.seededRunsView);
    355       this.seededRunsTabPage.Location = new System.Drawing.Point(4, 22);
    356       this.seededRunsTabPage.Name = "seededRunsTabPage";
    357       this.seededRunsTabPage.Padding = new System.Windows.Forms.Padding(3);
    358       this.seededRunsTabPage.Size = new System.Drawing.Size(841, 454);
    359       this.seededRunsTabPage.TabIndex = 5;
    360       this.seededRunsTabPage.Text = "Seeded Runs";
    361       this.seededRunsTabPage.UseVisualStyleBackColor = true;
    362       //
    363       // seededRunsView
    364       //
    365       this.seededRunsView.Caption = "RunCollection View";
    366       this.seededRunsView.Content = null;
    367       this.seededRunsView.Dock = System.Windows.Forms.DockStyle.Fill;
    368       this.seededRunsView.Location = new System.Drawing.Point(3, 3);
    369       this.seededRunsView.Name = "seededRunsView";
    370       this.seededRunsView.ReadOnly = false;
    371       this.seededRunsView.Size = new System.Drawing.Size(835, 448);
    372       this.seededRunsView.TabIndex = 1;
    373       //
    374394      // SolverView
    375395      //
    376396      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    377397      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     398      this.Controls.Add(this.minTargetView);
    378399      this.Controls.Add(this.maxEvaluationsView);
    379400      this.Controls.Add(this.algorithmCloneButton);
     
    381402      this.Controls.Add(this.solverTabControl);
    382403      this.Controls.Add(this.algorithmStartButton);
    383       this.Controls.Add(this.label1);
     404      this.Controls.Add(this.minimumTargetLabel);
     405      this.Controls.Add(this.seedingStrategyLabel);
    384406      this.Controls.Add(this.evaluationsLimitabel);
    385407      this.Controls.Add(this.algorithmSuggestionLabel);
     
    391413      this.resultsTabPage.PerformLayout();
    392414      this.runsTabPage.ResumeLayout(false);
     415      this.seededRunsTabPage.ResumeLayout(false);
    393416      this.parametersTabPage.ResumeLayout(false);
    394417      this.operatorGraphTabPage.ResumeLayout(false);
    395       this.seededRunsTabPage.ResumeLayout(false);
    396418      this.ResumeLayout(false);
    397419      this.PerformLayout();
     
    410432    private MainForm.WindowsForms.ViewHost operatorGraphViewHost;
    411433    private System.Windows.Forms.Button algorithmStartButton;
    412     private System.Windows.Forms.Label label1;
     434    private System.Windows.Forms.Label seedingStrategyLabel;
    413435    private System.Windows.Forms.Label evaluationsLimitabel;
    414436    private System.Windows.Forms.Label algorithmSuggestionLabel;
     
    422444    private System.Windows.Forms.TabPage seededRunsTabPage;
    423445    private Optimization.Views.RunCollectionView seededRunsView;
     446    private System.Windows.Forms.Label minimumTargetLabel;
     447    private Data.Views.StringConvertibleValueView minTargetView;
    424448  }
    425449}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/SolverView.cs

    r13722 r13759  
    6060        if (Content == null) {
    6161          maxEvaluationsView.Content = null;
     62          minTargetView.Content = null;
    6263          solverParametersView.Content = null;
    6364          runsView.Content = null;
     
    6768        } else {
    6869          maxEvaluationsView.Content = Content.MaximumEvaluations;
     70          minTargetView.Content = Content.MinimumTarget;
    6971          runsView.Content = Content.InstanceRuns;
    7072          seededRunsView.Content = Content.SeededRuns;
Note: See TracChangeset for help on using the changeset viewer.