Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12894


Ignore:
Timestamp:
08/25/15 00:55:53 (9 years ago)
Author:
bburlacu
Message:

#1772: Small updates to SelectionSchemeAnalyzer and SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
2 edited

Legend:

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

    r12163 r12894  
    6161      // to make sure the solutions are analyzed on the first application of this operator
    6262      if (updateCounter == null) {
    63         updateCounter = new IntValue(updateInterval);
     63        updateCounter = new IntValue(0);
    6464        UpdateCounterParameter.ActualValue = updateCounter;
    6565      }
     66      updateCounter.Value++;
    6667      //analyze solutions only every 'updateInterval' times
    67       if (updateCounter.Value != updateInterval) {
    68         updateCounter.Value++;
    69         return base.Apply();
    70       }
    71       updateCounter.Value = 1;
     68      if (updateCounter.Value != updateInterval) return base.Apply();
     69      updateCounter.Value = 0;
    7270
    7371      if (PopulationGraph == null)
    7472        return base.Apply();
    75 
    7673      double selectionRatio = 1;
    7774
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs

    r12892 r12894  
    8080    }
    8181
    82     public override void ClearState() {
    83       base.ClearState();
    84       UpdateCounter.Value = 0;
    85     }
    86 
    8782    public override IOperation Apply() {
    88       int updateInterval = UpdateIntervalParameter.Value.Value;
    8983      IntValue updateCounter = UpdateCounterParameter.ActualValue;
    9084      if (updateCounter == null) {
    91         updateCounter = new IntValue(updateInterval);
     85        updateCounter = new IntValue(0);
    9286        UpdateCounterParameter.ActualValue = updateCounter;
    93       } else updateCounter.Value++;
     87      }
     88      updateCounter.Value++;
     89      if (updateCounter.Value != UpdateInterval.Value) return base.Apply();
     90      updateCounter.Value = 0;
    9491
    95       if (updateCounter.Value == updateInterval) {
    96         updateCounter.Value = 0;
     92      var graph = PopulationGraph;
     93      if (graph == null || Generation.Value == 0)
     94        return base.Apply();
    9795
    98         var graph = PopulationGraph;
    99         if (graph == null || Generation.Value == 0)
    100           return base.Apply();
     96      var generation = Generation.Value;
     97      var averageQuality = QualityParameter.ActualValue.Average(x => x.Value);
     98      var population = PopulationParameter.ActualValue;
     99      var populationSize = population.Length;
    101100
    102         var generation = Generation.Value;
    103         var averageQuality = QualityParameter.ActualValue.Average(x => x.Value);
    104         var population = PopulationParameter.ActualValue;
    105         var populationSize = population.Length;
     101      var vertices = population.Select(graph.GetByContent).ToList();
     102      DataTable table;
     103      double aac = 0; // ratio of above average children produced
     104      double aacp = 0; // ratio of above average children from above average parents
     105      #region crossover improvement
     106      if (!Results.ContainsKey("Crossover improvement")) {
     107        table = new DataTable("Crossover improvement");
     108        Results.Add(new Result("Crossover improvement", table));
     109        table.Rows.AddRange(new[]
     110          {
     111              new DataRow("Average crossover improvement (root parent)") { VisualProperties = { StartIndexZero = true } },
     112              new DataRow("Average crossover improvement (non-root parent)") { VisualProperties = { StartIndexZero = true } },
     113              new DataRow("Average child-parents quality difference") { VisualProperties = { StartIndexZero = true } },
     114              new DataRow("Best crossover improvement (root parent)") { VisualProperties = { StartIndexZero = true } },
     115              new DataRow("Best crossover improvement (non-root parent)") { VisualProperties = { StartIndexZero = true }},
     116              new DataRow("Above average children") { VisualProperties = { StartIndexZero = true }},
     117              new DataRow("Above average children from above average parents") { VisualProperties = { StartIndexZero = true } },
     118            });
     119      } else {
     120        table = (DataTable)Results["Crossover improvement"].Value;
     121      }
     122      var crossoverChildren = vertices.Where(x => x.InDegree == 2).ToList();
     123      if (CountIntermediateChildren)
     124        crossoverChildren.AddRange(vertices.Where(x => x.InDegree == 1).Select(v => v.Parents.First()).Where(p => p.Rank.IsAlmost(generation - 0.5))); // add intermediate children
    106125
    107         var vertices = population.Select(graph.GetByContent).ToList();
    108         DataTable table;
    109         double aac = 0; // ratio of above average children produced
    110         double aacp = 0; // ratio of above average children from above average parents
    111         #region crossover improvement
    112         if (!Results.ContainsKey("Crossover improvement")) {
    113           table = new DataTable("Crossover improvement");
    114           Results.Add(new Result("Crossover improvement", table));
    115           table.Rows.AddRange(
    116             new[]
    117             {
    118               new DataRow("Average crossover improvement (root parent)") {VisualProperties = {StartIndexZero = true}},
    119               new DataRow("Average crossover improvement (non-root parent)") {VisualProperties = {StartIndexZero = true}},
    120               new DataRow("Average child-parents quality difference") {VisualProperties = {StartIndexZero = true}},
    121               new DataRow("Best crossover improvement (root parent)") {VisualProperties = {StartIndexZero = true}},
    122               new DataRow("Best crossover improvement (non-root parent)") {VisualProperties = {StartIndexZero = true}},
    123               new DataRow("Above average children") {VisualProperties = {StartIndexZero = true}},
    124               new DataRow("Above average children from above average parents") {VisualProperties = {StartIndexZero = true}},
    125             });
    126         } else {
    127           table = (DataTable)Results["Crossover improvement"].Value;
    128         }
    129         var crossoverChildren = vertices.Where(x => x.InDegree == 2).ToList();
    130         if (CountIntermediateChildren)
    131           crossoverChildren.AddRange(vertices.Where(x => x.InDegree == 1).Select(v => v.Parents.First()).Where(p => p.Rank.IsAlmost(generation - 0.5))); // add intermediate children
    132 
    133         foreach (var c in crossoverChildren) {
    134           if (c.Quality > averageQuality) {
    135             aac++;
    136             if (c.Parents.All(x => x.Quality > averageQuality))
    137               aacp++;
    138           }
    139         }
    140         var avgRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.First().Quality);
    141         var avgNonRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.Last().Quality);
    142         var avgChildParentQuality = crossoverChildren.Average(x => x.Quality - x.Parents.Average(p => p.Quality));
    143         var bestRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.First().Quality);
    144         var bestNonRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.Last().Quality);
    145         table.Rows["Average crossover improvement (root parent)"].Values.Add(avgRootParentQualityImprovement);
    146         table.Rows["Average crossover improvement (non-root parent)"].Values.Add(avgNonRootParentQualityImprovement);
    147         table.Rows["Best crossover improvement (root parent)"].Values.Add(bestRootParentQualityImprovement);
    148         table.Rows["Best crossover improvement (non-root parent)"].Values.Add(bestNonRootParentQualityImprovement);
    149         table.Rows["Average child-parents quality difference"].Values.Add(avgChildParentQuality);
    150         table.Rows["Above average children"].Values.Add(aac / populationSize);
    151         table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
    152         #endregion
    153 
    154         #region mutation improvement
    155         if (!Results.ContainsKey("Mutation improvement")) {
    156           table = new DataTable("Mutation improvement");
    157           Results.Add(new Result("Mutation improvement", table));
    158           table.Rows.AddRange(
    159             new[]
    160             {
    161               new DataRow("Average mutation improvement") {VisualProperties = {StartIndexZero = true}},
    162               new DataRow("Best mutation improvement") {VisualProperties = {StartIndexZero = true}},
    163               new DataRow("Above average children") {VisualProperties = {StartIndexZero = true}},
    164               new DataRow("Above average children from above average parents") {VisualProperties = {StartIndexZero = true}},
    165             });
    166         } else {
    167           table = (DataTable)Results["Mutation improvement"].Value;
    168         }
    169 
    170         aac = 0;
    171         aacp = 0;
    172         var mutationChildren = vertices.Where(x => x.InDegree == 1).ToList();
    173 
    174         foreach (var c in mutationChildren) {
    175           if (c.Quality > averageQuality)
    176             aac++;
     126      foreach (var c in crossoverChildren) {
     127        if (c.Quality > averageQuality) {
     128          aac++;
    177129          if (c.Parents.All(x => x.Quality > averageQuality))
    178130            aacp++;
    179131        }
    180         var avgMutationImprovement = mutationChildren.Average(x => x.Quality - x.Parents.First().Quality);
    181         var bestMutationImprovement = mutationChildren.Max(x => x.Quality - x.Parents.First().Quality);
     132      }
     133      var avgRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.First().Quality);
     134      var avgNonRootParentQualityImprovement = crossoverChildren.Average(x => x.Quality - x.Parents.Last().Quality);
     135      var avgChildParentQuality = crossoverChildren.Average(x => x.Quality - x.Parents.Average(p => p.Quality));
     136      var bestRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.First().Quality);
     137      var bestNonRootParentQualityImprovement = crossoverChildren.Max(x => x.Quality - x.Parents.Last().Quality);
     138      table.Rows["Average crossover improvement (root parent)"].Values.Add(avgRootParentQualityImprovement);
     139      table.Rows["Average crossover improvement (non-root parent)"].Values.Add(avgNonRootParentQualityImprovement);
     140      table.Rows["Best crossover improvement (root parent)"].Values.Add(bestRootParentQualityImprovement);
     141      table.Rows["Best crossover improvement (non-root parent)"].Values.Add(bestNonRootParentQualityImprovement);
     142      table.Rows["Average child-parents quality difference"].Values.Add(avgChildParentQuality);
     143      table.Rows["Above average children"].Values.Add(aac / populationSize);
     144      table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
     145      #endregion
    182146
    183         table.Rows["Average mutation improvement"].Values.Add(avgMutationImprovement);
    184         table.Rows["Best mutation improvement"].Values.Add(bestMutationImprovement);
    185         table.Rows["Above average children"].Values.Add(aac / populationSize);
    186         table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
    187         #endregion
     147      #region mutation improvement
     148      if (!Results.ContainsKey("Mutation improvement")) {
     149        table = new DataTable("Mutation improvement");
     150        Results.Add(new Result("Mutation improvement", table));
     151        table.Rows.AddRange(new[]
     152          {
     153              new DataRow("Average mutation improvement") { VisualProperties = { StartIndexZero = true } },
     154              new DataRow("Best mutation improvement") { VisualProperties = { StartIndexZero = true } },
     155              new DataRow("Above average children") { VisualProperties = { StartIndexZero = true } },
     156              new DataRow("Above average children from above average parents") { VisualProperties = { StartIndexZero = true } },
     157            });
     158      } else {
     159        table = (DataTable)Results["Mutation improvement"].Value;
    188160      }
     161
     162      aac = 0;
     163      aacp = 0;
     164      var mutationChildren = vertices.Where(x => x.InDegree == 1).ToList();
     165
     166      foreach (var c in mutationChildren) {
     167        if (c.Quality > averageQuality) {
     168          aac++;
     169          if (c.Parents.All(x => x.Quality > averageQuality))
     170            aacp++;
     171        }
     172      }
     173      var avgMutationImprovement = mutationChildren.Average(x => x.Quality - x.Parents.First().Quality);
     174      var bestMutationImprovement = mutationChildren.Max(x => x.Quality - x.Parents.First().Quality);
     175
     176      table.Rows["Average mutation improvement"].Values.Add(avgMutationImprovement);
     177      table.Rows["Best mutation improvement"].Values.Add(bestMutationImprovement);
     178      table.Rows["Above average children"].Values.Add(aac / populationSize);
     179      table.Rows["Above average children from above average parents"].Values.Add(aacp / populationSize);
     180      #endregion
    189181      return base.Apply();
    190182    }
Note: See TracChangeset for help on using the changeset viewer.