Changeset 13495 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking
- Timestamp:
- 01/11/16 21:26:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisFragmentLengthAnalyzer.cs
r12156 r13495 61 61 updateCounter.Value = 1; 62 62 63 if (PopulationGraph == null )63 if (PopulationGraph == null || Generation.Value == 0) 64 64 return base.Apply(); 65 65 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; 70 88 71 89 DataTable table; … … 73 91 table = new DataTable("Average fragment length"); 74 92 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); 76 100 table.Rows.Add(row); 77 101 Results.Add(new Result("AverageFragmentLength", table)); 78 102 } else { 79 103 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); 81 107 } 82 108 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.