Changeset 9419 for branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Analyzers/SymbolicExpressionTreePopulationDiversityAnalyzer.cs
- Timestamp:
- 05/02/13 13:18:57 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking/3.4/Analyzers/SymbolicExpressionTreePopulationDiversityAnalyzer.cs
r9296 r9419 44 44 public sealed class SymbolicExpressionTreePopulationDiversityAnalyzer : SingleSuccessorOperator, IAnalyzer { 45 45 #region Parameter names 46 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 46 47 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; 47 48 private const string UpdateIntervalParameterName = "UpdateInterval"; … … 56 57 private const string SortSubtreesParameterName = "SortSubtrees"; 57 58 private const string SimilarityValuesParmeterName = "Similarity"; 58 // population graph59 private const string PopulationGraphParameterName = "PopulationGraph";60 59 // clone map 61 60 private const string GlobalCloneMapParameterName = "GlobalCloneMap"; … … 64 63 65 64 #region Parameters 65 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 66 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 67 } 66 68 67 69 public ValueParameter<IntValue> UpdateIntervalParameter { … … 116 118 117 119 #region Parameter properties 120 public IntValue MaximumSymbolicExpressionTreeDepth { 121 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 122 } 118 123 119 124 public IntValue UpdateInterval { … … 164 169 Parameters.Add(new ValueLookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored.")); 165 170 Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations so far.")); 166 Parameters.Add(new ValueParameter<BoolValue>(MatchVariablesParameterName, "Specify if the symbolic expression tree comparer should match variable names." ));167 Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specify if the symbolic expression tree comparer should match variable weights." ));168 Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specify if the symbolic expression tree comparer should match constant values." ));171 Parameters.Add(new ValueParameter<BoolValue>(MatchVariablesParameterName, "Specify if the symbolic expression tree comparer should match variable names.", new BoolValue(true))); 172 Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specify if the symbolic expression tree comparer should match variable weights.", new BoolValue(true))); 173 Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specify if the symbolic expression tree comparer should match constant values.", new BoolValue(true))); 169 174 Parameters.Add(new ValueParameter<BoolValue>(SortSubtreesParameterName, "Specifies whether the subtrees of a tree should be sorted before comparison.")); 170 175 Parameters.Add(new LookupParameter<CloneMapType>(GlobalCloneMapParameterName, "A global map keeping track of trees and their clones (made during selection).")); 171 176 Parameters.Add(new ValueParameter<BoolValue>(StoreHistoryParameterName, "True if the tree lengths history of the population should be stored.", new BoolValue(false))); 172 177 Parameters.Add(new LookupParameter<DoubleValue>(SimilarityValuesParmeterName, "")); 178 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 173 179 UpdateCounterParameter.Hidden = true; 174 180 UpdateIntervalParameter.Hidden = true; … … 177 183 [StorableHook(HookType.AfterDeserialization)] 178 184 private void AfterDeserialization() { 185 if (!Parameters.ContainsKey(MaximumSymbolicExpressionTreeDepthParameterName)) { 186 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 187 } 179 188 } 180 189 181 190 #region IStatefulItem members 182 191 public override void InitializeState() { 192 UpdateCounter.Value = 0; 183 193 base.InitializeState(); 184 UpdateCounter.Value = 0;185 }186 187 public override void ClearState() {188 base.ClearState();189 UpdateCounter.Value = 0;190 194 } 191 195 #endregion … … 199 203 UpdateCounter.Value++; 200 204 if (UpdateCounter.Value != UpdateInterval.Value) return base.Apply(); 201 202 205 UpdateCounter.Value = 0; 203 206 var trees = SymbolicExpressionTreeParameter.ActualValue.ToList(); … … 208 211 209 212 SimilarityParameter.ActualValue = new DoubleValue(); 213 // needed only with the old (and inefficient) geneticitem-based similarity measure 214 // var geneticItems = trees.ToDictionary(tree => tree, tree => tree.GetGeneticItems(1, MaximumSymbolicExpressionTreeDepth.Value - 2).ToArray()); 210 215 211 216 var comp = new SymbolicExpressionTreeNodeSimilarityComparer { … … 217 222 var operations = new OperationCollection { Parallel = true }; 218 223 foreach (var tree in trees) { 219 var op = new SymbolicDataAnalysisExpressionTreeSimilarityCalculator { CurrentSymbolicExpressionTree = tree, SimilarityComparer = comp };224 var op = new SymbolicDataAnalysisExpressionTreeSimilarityCalculator { CurrentSymbolicExpressionTree = tree, SimilarityComparer = comp, MaximumTreeDepth = MaximumSymbolicExpressionTreeDepth.Value }; 220 225 var operation = ExecutionContext.CreateChildOperation(op, ExecutionContext.Scope); 221 226 operations.Add(operation); … … 256 261 relativeSelectionCountsTable.Rows["SelectedIndividuals"].Values.Add(relativeSelectionCount); 257 262 258 // build a selection frequencies histogram259 var graph = (SymbolicExpressionTreeGenealogyGraph)results[PopulationGraphParameterName].Value;260 // get graph nodes corresponding to individuals of the previous generation261 var prevGen = graph.Nodes.Where(node => node.Rank.IsAlmost(Generations.Value - 1)).OrderByDescending(n => n.Quality).ToList();262 var frequencies = new double[SymbolicExpressionTreeParameter.ActualValue.Length];263 for (int i = 0; i != prevGen.Count; ++i) {264 int selFreq = GlobalCloneMap.Values.Count(t => t == prevGen[i].SymbolicExpressionTree);265 frequencies[i] = selFreq;266 }267 DataTable selectionFrequenciesTable;268 if (!results.ContainsKey("SelectionFrequencies")) {269 selectionFrequenciesTable = new DataTable("Selection Frequencies") { VisualProperties = { YAxisTitle = "Selection Count" } };270 results.Add(new Result("SelectionFrequencies", selectionFrequenciesTable));271 }272 selectionFrequenciesTable = (DataTable)results["SelectionFrequencies"].Value;273 DataRow histoRow;274 if (!selectionFrequenciesTable.Rows.ContainsKey("SelectionFrequencies")) {275 histoRow = new DataRow("SelectionFrequencies") { VisualProperties = { StartIndexZero = true } };276 selectionFrequenciesTable.Rows.Add(histoRow);277 }278 histoRow = selectionFrequenciesTable.Rows["SelectionFrequencies"];279 histoRow.Values.Replace(frequencies);280 281 bool storeHistory = StoreHistory.Value;282 if (storeHistory) {283 DataTableHistory selectionFrequenciesHistory;284 if (!results.ContainsKey("SelectionFrequenciesHistory")) {285 selectionFrequenciesHistory = new DataTableHistory();286 results.Add(new Result("SelectionFrequenciesHistory", selectionFrequenciesHistory));287 }288 selectionFrequenciesHistory = (DataTableHistory)results["SelectionFrequenciesHistory"].Value;289 selectionFrequenciesHistory.Add((DataTable)selectionFrequenciesTable.Clone());290 }291 263 return base.Apply(); 292 264 }
Note: See TracChangeset
for help on using the changeset viewer.