Changeset 11462 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 10/14/14 01:37:43 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
-
Property
svn:ignore
set to
BuidingBlocks
-
Property
svn:ignore
set to
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/BuildingBlockAnalyzers/SymbolicDataAnalysisPoly10Analyzer.cs
r11461 r11462 46 46 private const string UpdateCounterParameterName = "UpdateCounter"; 47 47 private const string UpdateIntervalParameterName = "UpdateInterval"; 48 private const string buildingBlocksFrequenciesTableName = "Building blocks frequencies";48 private const string BuildingBlocksFrequenciesTableName = "Building blocks frequencies"; 49 49 50 50 … … 175 175 } 176 176 } 177 var table = (DataTable)results[ buildingBlocksFrequenciesTableName].Value;177 var table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value; 178 178 foreach (var pair in bbFrequencies) { 179 179 var label = prettyLabels[pair.Key]; … … 232 232 var results = ResultCollectionParameter.ActualValue; 233 233 DataTable table; 234 if (!results.ContainsKey( buildingBlocksFrequenciesTableName)) {235 table = new DataTable( buildingBlocksFrequenciesTableName);236 results.Add(new Result( buildingBlocksFrequenciesTableName, table));234 if (!results.ContainsKey(BuildingBlocksFrequenciesTableName)) { 235 table = new DataTable(BuildingBlocksFrequenciesTableName); 236 results.Add(new Result(BuildingBlocksFrequenciesTableName, table)); 237 237 } else { 238 table = (DataTable)results[ buildingBlocksFrequenciesTableName].Value;238 table = (DataTable)results[BuildingBlocksFrequenciesTableName].Value; 239 239 } 240 240 table.Rows.Clear(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisUsefulGenesAnalyzer.cs
r11461 r11462 45 45 private const string UpdateCounterParameterName = "UpdateCounter"; 46 46 private const string UpdateIntervalParameterName = "UpdateInterval"; 47 private const string MinimumGenerationsParameterName = "MinimumGenerations"; 47 48 private const string PruningProbabilityParameterName = "PruningProbability"; 48 49 private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions"; 49 50 private const string PromotedSubtreesResultName = "Promoted subtrees"; 51 private const string AverageQualityImprovementResultName = "Average quality improvement"; 52 private const string AverageLengthReductionResultName = "Average length reduction"; 50 53 private const string RandomParameterName = "Random"; 51 54 … … 85 88 public ValueParameter<IntValue> UpdateIntervalParameter { 86 89 get { return (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 90 } 91 92 public ValueParameter<IntValue> MinimumGenerationsParameter { 93 get { return (ValueParameter<IntValue>)Parameters[MinimumGenerationsParameterName]; } 87 94 } 88 95 … … 105 112 get { return UpdateIntervalParameter.Value.Value; } 106 113 set { UpdateIntervalParameter.Value.Value = value; } 114 } 115 116 public int MinimumGenerations { 117 get { return MinimumGenerationsParameter.Value.Value; } 118 set { MinimumGenerationsParameter.Value.Value = value; } 107 119 } 108 120 … … 129 141 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, new IntValue(0))); 130 142 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, new IntValue(1))); 131 Parameters.Add(new ValueParameter<PercentValue>(PercentageOfBestSolutionsParameterName, "How many of the best individuals should be pruned using this method.")); 132 Parameters.Add(new ValueParameter<PercentValue>(PruningProbabilityParameterName, "The probability to apply pruning")); 143 Parameters.Add(new ValueParameter<IntValue>(MinimumGenerationsParameterName, "The minimum number of generations the algorithm must be let to evolve before applying this analyzer.", new IntValue(50))); 144 Parameters.Add(new ValueParameter<PercentValue>(PercentageOfBestSolutionsParameterName, "How many of the best individuals should be pruned using this method.", new PercentValue(1.0))); 145 Parameters.Add(new ValueParameter<PercentValue>(PruningProbabilityParameterName, "The probability to apply pruning", new PercentValue(0.1))); 133 146 #endregion 134 147 } … … 150 163 } 151 164 165 public override void InitializeState() { 166 UpdateCounter = 0; 167 base.InitializeState(); 168 } 169 152 170 public override IOperation Apply() { 171 int generations = GenerationsParameter.ActualValue.Value; 153 172 #region Update counter & update interval 173 if (generations < MinimumGenerations) 174 return base.Apply(); 154 175 UpdateCounter++; 155 176 if (UpdateCounter != UpdateInterval) { … … 162 183 var qualities = QualityParameter.ActualValue.ToArray(); 163 184 164 // order trees by quality 165 Array.Sort(qualities, trees); 185 Array.Sort(qualities, trees); // sort trees array based on qualities 166 186 167 187 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; … … 171 191 172 192 int replacedTrees = 0; 193 int avgLengthReduction = 0; 194 double avgQualityImprovement = 0; 173 195 174 196 var count = (int)Math.Floor(trees.Length * PercentageOfBestSolutions); 175 197 176 for (int i = 0; i < count; ++i) { 198 for (int i = trees.Length - 1; i >= trees.Length - count; --i) { 199 if (random.NextDouble() > PruningProbability) continue; 177 200 var tree = trees[i]; 178 201 var quality = qualities[i].Value; 179 202 var root = tree.Root.GetSubtree(0).GetSubtree(0); 180 203 181 foreach (var s in root.IterateNodesPrefix()) { 182 if (random.NextDouble() < PruningProbability) continue; 204 foreach (var s in root.IterateNodesPrefix().Skip(1)) { 183 205 var r2 = EvaluateSubtree(s, interpreter, problemData, rows); 184 if (s == root || r2 < quality) continue; 206 if (double.IsNaN(r2) || r2 <= quality) continue; 207 avgQualityImprovement += (r2 - quality); 208 avgLengthReduction += (tree.Length - s.GetLength()); 209 replacedTrees++; 210 // replace tree with its own subtree 185 211 var startNode = tree.Root.GetSubtree(0); 186 212 startNode.RemoveSubtree(0); 187 213 startNode.AddSubtree(s); 188 replacedTrees++; 214 // update tree quality 215 qualities[i].Value = r2; 216 189 217 break; 190 218 } 191 219 } 220 221 avgQualityImprovement /= replacedTrees; 222 avgLengthReduction = (int)Math.Round((double)avgLengthReduction / replacedTrees); 192 223 193 224 var results = ResultCollectionParameter.ActualValue; … … 202 233 table.Rows[PromotedSubtreesResultName].Values.Add(replacedTrees); 203 234 235 if (results.ContainsKey(AverageQualityImprovementResultName)) { 236 table = (DataTable)results[AverageQualityImprovementResultName].Value; 237 } else { 238 table = new DataTable(AverageQualityImprovementResultName); 239 table.Rows.Add(new DataRow(AverageQualityImprovementResultName)); 240 results.Add(new Result(AverageQualityImprovementResultName, table)); 241 } 242 table.Rows[AverageQualityImprovementResultName].Values.Add(avgQualityImprovement); 243 244 if (results.ContainsKey(AverageLengthReductionResultName)) { 245 table = (DataTable)results[AverageLengthReductionResultName].Value; 246 } else { 247 table = new DataTable(AverageLengthReductionResultName); 248 table.Rows.Add(new DataRow(AverageLengthReductionResultName)); 249 results.Add(new Result(AverageLengthReductionResultName, table)); 250 } 251 table.Rows[AverageLengthReductionResultName].Values.Add(avgLengthReduction); 252 204 253 return base.Apply(); 205 254 }
Note: See TracChangeset
for help on using the changeset viewer.