Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/16 21:26:00 (9 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.