Changeset 12894 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
- Timestamp:
- 08/25/15 00:55:53 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs
r12892 r12894 80 80 } 81 81 82 public override void ClearState() {83 base.ClearState();84 UpdateCounter.Value = 0;85 }86 87 82 public override IOperation Apply() { 88 int updateInterval = UpdateIntervalParameter.Value.Value;89 83 IntValue updateCounter = UpdateCounterParameter.ActualValue; 90 84 if (updateCounter == null) { 91 updateCounter = new IntValue( updateInterval);85 updateCounter = new IntValue(0); 92 86 UpdateCounterParameter.ActualValue = updateCounter; 93 } else updateCounter.Value++; 87 } 88 updateCounter.Value++; 89 if (updateCounter.Value != UpdateInterval.Value) return base.Apply(); 90 updateCounter.Value = 0; 94 91 95 if (updateCounter.Value == updateInterval) { 96 updateCounter.Value = 0; 92 var graph = PopulationGraph; 93 if (graph == null || Generation.Value == 0) 94 return base.Apply(); 97 95 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; 101 100 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 106 125 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++; 177 129 if (c.Parents.All(x => x.Quality > averageQuality)) 178 130 aacp++; 179 131 } 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 182 146 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; 188 160 } 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 189 181 return base.Apply(); 190 182 }
Note: See TracChangeset
for help on using the changeset viewer.