Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16090


Ignore:
Timestamp:
08/28/18 11:27:43 (6 years ago)
Author:
lkammere
Message:

#2886: Explicitely store all pareto-optimal RegressionSolution objects at the end of the algorithm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/BestSolutionAnalyzer.cs

    r16088 r16090  
    4545    public static readonly string ParetoFrontResultName = "Pareto Front";
    4646    public static readonly string ParetoFrontAnalysisResultName = "Pareto Front Analysis";
     47    public static readonly string ParetoFrontSolutionsResultName = "Pareto Front Solutions";
    4748
    4849    private static readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter();
     
    6263    public void Deregister(GrammarEnumerationAlgorithm algorithm) {
    6364      algorithm.DistinctSentenceGenerated -= AlgorithmDistinctSentenceGenerated;
     65      algorithm.Stopped -= AlgorithmOnStopped;
    6466    }
    6567
    6668    public void Register(GrammarEnumerationAlgorithm algorithm) {
    6769      algorithm.DistinctSentenceGenerated += AlgorithmDistinctSentenceGenerated;
     70      algorithm.Stopped += AlgorithmOnStopped;
     71    }
     72
     73    private void AlgorithmOnStopped(object sender, EventArgs eventArgs) {
     74      var algorithm = (GrammarEnumerationAlgorithm)sender;
     75
     76      IResult paretoFrontResult;
     77      if (algorithm.Results.TryGetValue(ParetoFrontAnalysisResultName, out paretoFrontResult)) {
     78        var plot = (ScatterPlot)paretoFrontResult.Value;
     79
     80        var solutions = plot.Rows.First().Points.Select(p => (ISymbolicRegressionSolution)p.Tag);
     81
     82        algorithm.Results.AddOrUpdateResult(ParetoFrontSolutionsResultName, new ItemList<ISymbolicRegressionSolution>(solutions));
     83      }
    6884    }
    6985
     
    145161      ItemList<DoubleArray> paretoFront = (ItemList<DoubleArray>)algorithm.Results[ParetoFrontResultName].Value;
    146162
    147       DoubleArray precedingRank = paretoFront.OrderByDescending(v => v[0]).FirstOrDefault(v => v[0] <= currRank);
    148 
    149       return precedingRank == null || currQuality > precedingRank[1];
     163      int preceedingRankIndex = -1;
     164      int lastIndex = paretoFront.Count - 1;
     165      while (preceedingRankIndex < lastIndex) {
     166        if (preceedingRankIndex + 1 > currRank)
     167          break;
     168        preceedingRankIndex++;
     169      }
     170
     171      return preceedingRankIndex < 0 || paretoFront[preceedingRankIndex][1] < currQuality;
    150172    }
    151173
     
    166188      ScatterPlotDataRow plot = ((ScatterPlot)algorithm.Results[ParetoFrontAnalysisResultName].Value).Rows.First();
    167189
    168 
    169190      // Delete solutions with higher rank, which are now dominated.
    170       foreach (DoubleArray succeedingRank in paretoFront.Where(k => k[0] >= currRank).ToArray()) {
    171         if (succeedingRank[1] < currQuality) {
    172           paretoFront.Remove(succeedingRank);
    173           RemovePoint(plot, succeedingRank[0]);
     191      int i = 0;
     192      while (i < paretoFront.Count) {
     193        if (paretoFront[i][0] >= currRank) { // Go to current rank
     194          double quality = paretoFront[i][1];
     195          if (quality <= currQuality) { // If existing solution is worse, delete it
     196            RemovePoint(plot, currRank);
     197            paretoFront.RemoveAt(i);
     198          } else { // Otherwise stop, since following solutions can only be better
     199            break;
     200          }
     201        } else {
     202          i++;
    174203        }
    175204      }
    176205
    177       paretoFront.Add(new DoubleArray(new double[] { currRank, currQuality }));
     206      paretoFront.Insert(i, new DoubleArray(new double[] { currRank, currQuality }));
    178207      plot.Points.Add(new Point2D<double>(currRank, currQuality, solution));
    179208    }
Note: See TracChangeset for help on using the changeset viewer.