Changeset 13747 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 04/07/16 15:13:41 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Tracking/Analyzers/SymbolicDataAnalysisFragmentLengthAnalyzer.cs
r13495 r13747 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 28 29 using HeuristicLab.EvolutionTracking; 29 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Parameters; 30 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 33 … … 34 36 [StorableClass] 35 37 public class SymbolicDataAnalysisFragmentLengthAnalyzer : EvolutionTrackingAnalyzer<ISymbolicExpressionTree> { 38 private const string StoreHistoryParameterName = "StoryHistory"; 39 40 public IFixedValueParameter<BoolValue> StoreHistoryParameter { 41 get { return (IFixedValueParameter<BoolValue>)Parameters[StoreHistoryParameterName]; } 42 } 43 44 public bool StoreHistory { 45 get { return StoreHistoryParameter.Value.Value; } 46 set { StoreHistoryParameter.Value.Value = value; } 47 } 48 36 49 [StorableConstructor] 37 50 protected SymbolicDataAnalysisFragmentLengthAnalyzer(bool deserializing) : base(deserializing) { } … … 39 52 public SymbolicDataAnalysisFragmentLengthAnalyzer() { 40 53 UpdateCounterParameter.ActualName = "FragmentLengthAnalyzerUpdateCounter"; 54 55 Parameters.Add(new FixedValueParameter<BoolValue>(StoreHistoryParameterName, new BoolValue(false))); 41 56 } 42 57 … … 65 80 66 81 // 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 82 var vertices = PopulationGraph.Vertices.Where(x => x.Rank > Generation.Value - 1); 83 var crossoverFragmentLengthDistribution = new List<double>(); 84 var replacedCrossoverFragmentLengthDistribution = new List<double>(); 85 var mutationFragmentLengthDistribution = new List<double>(); 86 var replacedMutationFragmentLengthDistribution = new List<double>(); 73 87 foreach (var v in vertices) { 74 88 if (!v.InArcs.Any() || v.InArcs.Last().Data == null) … … 76 90 var fragment = (IFragment<ISymbolicExpressionTreeNode>)v.InArcs.Last().Data; 77 91 if (v.InDegree == 2) { 78 averageCrossoverFragmentLength += fragment.Root.GetLength(); 79 crossoverChildren++; 92 crossoverFragmentLengthDistribution.Add(fragment.Root.GetLength()); 93 int index = 0; 94 foreach (var s in v.Parents.First().Data.IterateNodesPrefix()) { 95 if (index == fragment.Index1) { 96 replacedCrossoverFragmentLengthDistribution.Add(s.GetLength()); 97 break; 98 } 99 index++; 100 } 80 101 } else { 81 averageMutationFragmentLength += fragment.Root.GetLength(); 82 mutationChildren++; 102 mutationFragmentLengthDistribution.Add(fragment.Root.GetLength()); 103 int index = 0; 104 foreach (var s in v.Parents.First().Data.IterateNodesPrefix()) { 105 if (index == fragment.Index1) { 106 replacedMutationFragmentLengthDistribution.Add(s.GetLength()); 107 break; 108 } 109 index++; 110 } 83 111 } 84 112 } 85 var averageFragmentLength = (averageCrossoverFragmentLength + averageMutationFragmentLength) / (crossoverChildren + mutationChildren); 86 averageCrossoverFragmentLength /= crossoverChildren; 87 averageMutationFragmentLength /= mutationChildren; 88 113 var averageFragmentLength = (crossoverFragmentLengthDistribution.Average() + mutationFragmentLengthDistribution.Average()) / 2d; 89 114 DataTable table; 90 115 if (!Results.ContainsKey("AverageFragmentLength")) { … … 94 119 table.Rows.Add(row); 95 120 row = new DataRow("Average crossover fragment length") { VisualProperties = { StartIndexZero = true } }; 96 row.Values.Add(averageCrossoverFragmentLength); 121 row.Values.Add(crossoverFragmentLengthDistribution.Average()); 122 table.Rows.Add(row); 123 row = new DataRow("Average replaced crossover fragment length") { VisualProperties = { StartIndexZero = true } }; 124 row.Values.Add(replacedCrossoverFragmentLengthDistribution.Average()); 97 125 table.Rows.Add(row); 98 126 row = new DataRow("Average mutation fragment length") { VisualProperties = { StartIndexZero = true } }; 99 row.Values.Add(averageMutationFragmentLength); 127 row.Values.Add(mutationFragmentLengthDistribution.Average()); 128 table.Rows.Add(row); 129 row = new DataRow("Average replaced mutation fragment length") { VisualProperties = { StartIndexZero = true } }; 130 row.Values.Add(replacedMutationFragmentLengthDistribution.Average()); 100 131 table.Rows.Add(row); 101 132 Results.Add(new Result("AverageFragmentLength", table)); … … 103 134 table = (DataTable)Results["AverageFragmentLength"].Value; 104 135 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); 136 table.Rows["Average crossover fragment length"].Values.Add(crossoverFragmentLengthDistribution.Average()); 137 table.Rows["Average replaced crossover fragment length"].Values.Add(replacedCrossoverFragmentLengthDistribution.Average()); 138 table.Rows["Average mutation fragment length"].Values.Add(mutationFragmentLengthDistribution.Average()); 139 table.Rows["Average replaced mutation fragment length"].Values.Add(replacedMutationFragmentLengthDistribution.Average()); 140 } 141 if (!Results.ContainsKey("FragmentLengthDistribution")) { 142 table = new DataTable("Table length distribution"); 143 var row = new DataRow("Crossover fragment length distribution") { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Histogram } }; 144 row.Values.Replace(crossoverFragmentLengthDistribution); 145 table.Rows.Add(row); 146 row = new DataRow("Replaced crossover fragment length distribution") { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Histogram } }; 147 row.Values.Replace(replacedCrossoverFragmentLengthDistribution); 148 table.Rows.Add(row); 149 row = new DataRow("Mutation fragment length distribution") { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Histogram } }; 150 row.Values.Replace(mutationFragmentLengthDistribution); 151 table.Rows.Add(row); 152 row = new DataRow("Replaced mutation fragment length distribution") { VisualProperties = { StartIndexZero = true, ChartType = DataRowVisualProperties.DataRowChartType.Histogram } }; 153 row.Values.Replace(replacedMutationFragmentLengthDistribution); 154 table.Rows.Add(row); 155 Results.Add(new Result("FragmentLengthDistribution", table)); 156 } else { 157 table = (DataTable)Results["FragmentLengthDistribution"].Value; 158 table.Rows["Crossover fragment length distribution"].Values.Replace(crossoverFragmentLengthDistribution); 159 table.Rows["Mutation fragment length distribution"].Values.Replace(mutationFragmentLengthDistribution); 160 table.Rows["Replaced crossover fragment length distribution"].Values.Replace(replacedCrossoverFragmentLengthDistribution); 161 table.Rows["Replaced mutation fragment length distribution"].Values.Replace(replacedMutationFragmentLengthDistribution); 162 } 163 if (StoreHistory) { 164 if (!Results.ContainsKey("FragmentLengthDistributionHistory")) { 165 var history = new DataTableHistory(); 166 history.Add(table); 167 Results.Add(new Result("FragmentLengthDistributionHistory", history)); 168 } else { 169 var history = (DataTableHistory)Results["FragmentLengthDistributionHistory"].Value; 170 history.Add(table); 171 } 107 172 } 108 173 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.