Changeset 13495


Ignore:
Timestamp:
01/11/16 21:26:00 (6 years ago)
Author:
bburlacu
Message:

#1772: Improve the average operator improvement and average fragment length analyzers. Update genealogy analyzer to always evaluate the intermediate children.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/Analyzers/GenealogyAnalyzer.cs

    r13482 r13495  
    314314      }
    315315      // update qualities for intermediate vertices
    316       if (!TrimOlderGenerations)
    317         EvaluateIntermediateChildren();
     316      EvaluateIntermediateChildren();
    318317
    319318      // remove extra graph nodes (added by the instrumented operators in the case of offspring selection)
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs

    r12966 r13495  
    105105      var vertices = population.Select(graph.GetByContent).ToList();
    106106      DataTable table;
    107       double aac = 0; // ratio of above average children produced
    108       double aacp = 0; // ratio of above average children from above average parents
    109107      #region crossover improvement
    110108      if (!Results.ContainsKey("Crossover improvement")) {
    111109        table = new DataTable("Crossover improvement");
    112110        Results.Add(new Result("Crossover improvement", table));
    113         table.Rows.AddRange(new[]
    114           {
    115               new DataRow("Average crossover improvement (root parent)") { VisualProperties = { StartIndexZero = true } },
    116               new DataRow("Average crossover improvement (non-root parent)") { VisualProperties = { StartIndexZero = true } },
    117               new DataRow("Average child-parents quality difference") { VisualProperties = { StartIndexZero = true } },
    118               new DataRow("Best crossover improvement (root parent)") { VisualProperties = { StartIndexZero = true } },
    119               new DataRow("Best crossover improvement (non-root parent)") { VisualProperties = { StartIndexZero = true }},
    120               new DataRow("Above average children") { VisualProperties = { StartIndexZero = true }},
    121               new DataRow("Above average children from above average parents") { VisualProperties = { StartIndexZero = true } },
    122             });
     111        table.Rows.AddRange(new[] {
     112          new DataRow("Average crossover child quality") { VisualProperties = { StartIndexZero = true } },
     113          new DataRow("Average crossover parent quality") { VisualProperties = { StartIndexZero = true } },
     114          new DataRow("Best crossover child quality") { VisualProperties = { StartIndexZero = true } },
     115          new DataRow("Best crossover parent quality") { VisualProperties = { StartIndexZero = true } },
     116        });
    123117      } else {
    124118        table = (DataTable)Results["Crossover improvement"].Value;
     
    128122        crossoverChildren.AddRange(vertices.Where(x => x.InDegree == 1).Select(v => v.Parents.First()).Where(p => p.Rank.IsAlmost(generation - 0.5))); // add intermediate children
    129123
    130       foreach (var c in crossoverChildren) {
    131         if (c.Quality > averageQuality) {
    132           aac++;
    133           if (c.Parents.All(x => x.Quality > averageQuality))
    134             aacp++;
    135         }
    136       }
    137       var avgRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.First().Quality);
    138       var avgNonRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.Last().Quality);
    139       var avgChildParentQuality = crossoverChildren.Average(x => x.Quality - x.Parents.Average(p => p.Quality));
    140       var bestRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.First().Quality);
    141       var bestNonRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.Last().Quality);
    142       table.Rows["Average crossover improvement (root parent)"].Values.Add(avgRootParentQualityImprovement);
    143       table.Rows["Average crossover improvement (non-root parent)"].Values.Add(avgNonRootParentQualityImprovement);
    144       table.Rows["Best crossover improvement (root parent)"].Values.Add(bestRootParentQualityImprovement);
    145       table.Rows["Best crossover improvement (non-root parent)"].Values.Add(bestNonRootParentQualityImprovement);
    146       table.Rows["Average child-parents quality difference"].Values.Add(avgChildParentQuality);
    147       table.Rows["Above average children"].Values.Add(aac / populationSize);
    148       table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
     124      var avgCrossoverParentQuality = crossoverChildren.SelectMany(x => x.Parents).Average(x => x.Quality);
     125      var avgCrossoverChildQuality = crossoverChildren.Average(x => x.Quality);
     126
     127      var bestCrossoverChildQuality = crossoverChildren.OrderBy(x => x.Quality).Last().Quality;
     128      var bestCrossoverParentQuality = crossoverChildren.OrderBy(x => x.Quality).Last().Parents.First().Quality;
     129
     130      table.Rows["Average crossover child quality"].Values.Add(avgCrossoverChildQuality);
     131      table.Rows["Average crossover parent quality"].Values.Add(avgCrossoverParentQuality);
     132      table.Rows["Best crossover child quality"].Values.Add(bestCrossoverChildQuality);
     133      table.Rows["Best crossover parent quality"].Values.Add(bestCrossoverParentQuality);
    149134      #endregion
    150135
     
    153138        table = new DataTable("Mutation improvement");
    154139        Results.Add(new Result("Mutation improvement", table));
    155         table.Rows.AddRange(new[]
    156           {
    157               new DataRow("Average mutation improvement") { VisualProperties = { StartIndexZero = true } },
    158               new DataRow("Best mutation improvement") { VisualProperties = { StartIndexZero = true } },
    159               new DataRow("Above average children") { VisualProperties = { StartIndexZero = true } },
    160               new DataRow("Above average children from above average parents") { VisualProperties = { StartIndexZero = true } },
    161             });
     140        table.Rows.AddRange(new[] {
     141          new DataRow("Average mutation child quality") { VisualProperties = { StartIndexZero = true } },
     142          new DataRow("Average mutation parent quality") { VisualProperties = { StartIndexZero = true } },
     143          new DataRow("Best mutation child quality") { VisualProperties = { StartIndexZero = true } },
     144          new DataRow("Best mutation parent quality") { VisualProperties = { StartIndexZero = true } },
     145        });
    162146      } else {
    163147        table = (DataTable)Results["Mutation improvement"].Value;
    164148      }
    165149
    166       aac = 0;
    167       aacp = 0;
    168150      var mutationChildren = vertices.Where(x => x.InDegree == 1).ToList();
    169151
    170       foreach (var c in mutationChildren) {
    171         if (c.Quality > averageQuality) {
    172           aac++;
    173           if (c.Parents.All(x => x.Quality > averageQuality))
    174             aacp++;
    175         }
    176       }
    177       var avgMutationImprovement = mutationChildren.Average(x => x.Quality - x.Parents.First().Quality);
    178       var bestMutationImprovement = mutationChildren.Max(x => x.Quality - x.Parents.First().Quality);
     152      var avgMutationParentQuality = mutationChildren.SelectMany(x => x.Parents).Average(x => x.Quality);
     153      var avgMutationChildQuality = mutationChildren.Average(x => x.Quality);
    179154
    180       table.Rows["Average mutation improvement"].Values.Add(avgMutationImprovement);
    181       table.Rows["Best mutation improvement"].Values.Add(bestMutationImprovement);
    182       table.Rows["Above average children"].Values.Add(aac / populationSize);
    183       table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
     155      var bestMutationChildQuality = mutationChildren.OrderBy(x => x.Quality).Last().Quality;
     156      var bestMutationParentQuality = mutationChildren.OrderBy(x => x.Quality).Last().Parents.First().Quality;
     157
     158      table.Rows["Average mutation child quality"].Values.Add(avgMutationChildQuality);
     159      table.Rows["Average mutation parent quality"].Values.Add(avgMutationParentQuality);
     160      table.Rows["Best mutation child quality"].Values.Add(bestMutationChildQuality);
     161      table.Rows["Best mutation parent quality"].Values.Add(bestMutationParentQuality);
     162
    184163      #endregion
    185164      return base.Apply();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisFragmentLengthAnalyzer.cs

    r12156 r13495  
    6161      updateCounter.Value = 1;
    6262
    63       if (PopulationGraph == null)
     63      if (PopulationGraph == null || Generation.Value == 0)
    6464        return base.Apply();
    6565
    66       var children = PopulationGraph.GetByRank(Generation.Value).Where(x => x.InDegree > 0).ToList();
    67       double avgFragmentLength = 0;
    68       if (children.Any())
    69         avgFragmentLength = children.Select(x => (IFragment<ISymbolicExpressionTreeNode>)x.InArcs.Last().Data).Where(f => f != null).Average(x => x.Root.GetLength());
     66      // consider all fragments (including those of the intermediate crossover children)
     67      double averageCrossoverFragmentLength = 0;
     68      double averageMutationFragmentLength = 0;
     69      int crossoverChildren = 0;
     70      int mutationChildren = 0;
     71
     72      var vertices = PopulationGraph.Vertices.Where(x => x.Rank > Generation.Value - 1);
     73      foreach (var v in vertices) {
     74        if (!v.InArcs.Any() || v.InArcs.Last().Data == null)
     75          continue;
     76        var fragment = (IFragment<ISymbolicExpressionTreeNode>)v.InArcs.Last().Data;
     77        if (v.InDegree == 2) {
     78          averageCrossoverFragmentLength += fragment.Root.GetLength();
     79          crossoverChildren++;
     80        } else {
     81          averageMutationFragmentLength += fragment.Root.GetLength();
     82          mutationChildren++;
     83        }
     84      }
     85      var averageFragmentLength = (averageCrossoverFragmentLength + averageMutationFragmentLength) / (crossoverChildren + mutationChildren);
     86      averageCrossoverFragmentLength /= crossoverChildren;
     87      averageMutationFragmentLength /= mutationChildren;
    7088
    7189      DataTable table;
     
    7391        table = new DataTable("Average fragment length");
    7492        var row = new DataRow("Average fragment length") { VisualProperties = { StartIndexZero = true } };
    75         row.Values.Add(avgFragmentLength);
     93        row.Values.Add(averageFragmentLength);
     94        table.Rows.Add(row);
     95        row = new DataRow("Average crossover fragment length") { VisualProperties = { StartIndexZero = true } };
     96        row.Values.Add(averageCrossoverFragmentLength);
     97        table.Rows.Add(row);
     98        row = new DataRow("Average mutation fragment length") { VisualProperties = { StartIndexZero = true } };
     99        row.Values.Add(averageMutationFragmentLength);
    76100        table.Rows.Add(row);
    77101        Results.Add(new Result("AverageFragmentLength", table));
    78102      } else {
    79103        table = (DataTable)Results["AverageFragmentLength"].Value;
    80         table.Rows["Average fragment length"].Values.Add(avgFragmentLength);
     104        table.Rows["Average fragment length"].Values.Add(averageFragmentLength);
     105        table.Rows["Average crossover fragment length"].Values.Add(averageCrossoverFragmentLength);
     106        table.Rows["Average mutation fragment length"].Values.Add(averageMutationFragmentLength);
    81107      }
    82108      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.