- Timestamp:
- 08/28/18 11:27:43 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/Analysis/BestSolutionAnalyzer.cs
r16088 r16090 45 45 public static readonly string ParetoFrontResultName = "Pareto Front"; 46 46 public static readonly string ParetoFrontAnalysisResultName = "Pareto Front Analysis"; 47 public static readonly string ParetoFrontSolutionsResultName = "Pareto Front Solutions"; 47 48 48 49 private static readonly ISymbolicDataAnalysisExpressionTreeInterpreter expressionTreeLinearInterpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); … … 62 63 public void Deregister(GrammarEnumerationAlgorithm algorithm) { 63 64 algorithm.DistinctSentenceGenerated -= AlgorithmDistinctSentenceGenerated; 65 algorithm.Stopped -= AlgorithmOnStopped; 64 66 } 65 67 66 68 public void Register(GrammarEnumerationAlgorithm algorithm) { 67 69 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 } 68 84 } 69 85 … … 145 161 ItemList<DoubleArray> paretoFront = (ItemList<DoubleArray>)algorithm.Results[ParetoFrontResultName].Value; 146 162 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; 150 172 } 151 173 … … 166 188 ScatterPlotDataRow plot = ((ScatterPlot)algorithm.Results[ParetoFrontAnalysisResultName].Value).Rows.First(); 167 189 168 169 190 // 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++; 174 203 } 175 204 } 176 205 177 paretoFront. Add(new DoubleArray(new double[] { currRank, currQuality }));206 paretoFront.Insert(i, new DoubleArray(new double[] { currRank, currQuality })); 178 207 plot.Points.Add(new Point2D<double>(currRank, currQuality, solution)); 179 208 }
Note: See TracChangeset
for help on using the changeset viewer.