Changeset 4934 for branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression
- Timestamp:
- 11/25/10 12:37:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs
r4928 r4934 62 62 IList<GeneticInformationItem>[] geneticInformationItemsList = new List<GeneticInformationItem>[n]; 63 63 for (int i = 0; i < n; i++) { 64 geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames );64 geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 1, 5); 65 65 } 66 66 double[,] result = new double[n, n]; … … 96 96 } 97 97 98 private int my LevelDelta;99 public int LevelDelta{100 get { return my LevelDelta; }98 private int myAncestorLevel; 99 public int AncestorLevel { 100 get { return myAncestorLevel; } 101 101 } 102 102 … … 138 138 public int DescendantTimeOffset { 139 139 get { return myDescendantTimeOffset; } 140 } 141 142 private SymbolicExpressionTreeNode myDescendantTreeNode; 143 public SymbolicExpressionTreeNode DescendantTreeNode { 144 get { return myDescendantTreeNode; } 145 } 146 147 private int myDescendantLevel; 148 public int DescendantLevel { 149 get { return myDescendantLevel; } 150 } 151 152 public int LevelDelta { 153 get { return (myDescendantLevel - myAncestorLevel); } 140 154 } 141 155 … … 369 383 }*/ 370 384 371 public static IList<GeneticInformationItem> getGeneticInformationItems(SymbolicExpressionTreeNode node, List<string> variableNames) { 385 public static IList<GeneticInformationItem> getGeneticInformationItems(SymbolicExpressionTreeNode node, List<string> variableNames, 386 int MinimumLevelDelta, int MaximumLevelDelta) { 387 // first we have to collect all items, then we filter; it is not possible to filter while collecting because the items are 388 // collected recursively and used for collecting the parents' items. 389 if (MinimumLevelDelta > MaximumLevelDelta) 390 return new List<GeneticInformationItem>(); 391 IList<GeneticInformationItem> list = getGeneticInformationItems(node, variableNames, 0); 392 List<GeneticInformationItem> resultList = new List<GeneticInformationItem>(); 393 foreach (GeneticInformationItem item in list) 394 if (item.LevelDelta >= MinimumLevelDelta && item.LevelDelta <= MaximumLevelDelta) 395 resultList.Add(item); 396 return resultList; 397 } 398 399 private static IList<GeneticInformationItem> getGeneticInformationItems(SymbolicExpressionTreeNode node, List<string> variableNames, int level) { 372 400 // Idea: collect all descendants' lists and then add new items using the retrieved ones. 373 401 // This should save lots of time and reduce complexity of the items retrieval process. 402 // Program roots are not considered, neither are start symbol nodes 374 403 if (node.Symbol is ProgramRootSymbol) 375 return getGeneticInformationItems(node.SubTrees[0], variableNames );404 return getGeneticInformationItems(node.SubTrees[0], variableNames, level + 1); 376 405 List<GeneticInformationItem> list = new List<GeneticInformationItem>(); 377 406 // add item for this node: 378 list.Add(new GeneticInformationItem(node, variableNames)); 379 // add items for the descendants: 407 if (!(node.Symbol is StartSymbol)) { 408 list.Add(new GeneticInformationItem(node, variableNames, level)); 409 } 410 // add items for the descendants, but prevent multiple references to descendant nodes: 411 List<SymbolicExpressionTreeNode> descendantNodes = new List<SymbolicExpressionTreeNode>(); 380 412 for (int i = 0; i < node.SubTrees.Count; i++) { 381 IList<GeneticInformationItem> descendantItems = getGeneticInformationItems(node.SubTrees[i], variableNames );413 IList<GeneticInformationItem> descendantItems = getGeneticInformationItems(node.SubTrees[i], variableNames, level + 1); 382 414 list.AddRange(descendantItems); 383 foreach (GeneticInformationItem item in descendantItems) { 384 list.Add(new GeneticInformationItem(node, item, i)); 385 } 415 if (!(node.Symbol is StartSymbol)) 416 foreach (GeneticInformationItem item in descendantItems) { 417 if (!descendantNodes.Contains(item.DescendantTreeNode)) 418 list.Add(new GeneticInformationItem(node, item, i, level)); 419 descendantNodes.Add(item.DescendantTreeNode); 420 } 386 421 } 387 422 return list; 388 423 } 389 424 390 private GeneticInformationItem (SymbolicExpressionTreeNode node, List<string> variableNames ) {425 private GeneticInformationItem (SymbolicExpressionTreeNode node, List<string> variableNames, int level) { 391 426 myAncestorIndex = -1; 392 427 VariableTreeNode variableTreeNode = node as VariableTreeNode; … … 409 444 else 410 445 myDescendantVariableIndex = -1; 411 myLevelDelta = 0; 412 } 413 414 private GeneticInformationItem(SymbolicExpressionTreeNode parentNode, GeneticInformationItem descendantGeneticInformationItem, int ancestorIndex) { 446 myAncestorLevel = level; 447 myDescendantLevel = level; 448 myDescendantTreeNode = node; 449 } 450 451 private GeneticInformationItem(SymbolicExpressionTreeNode parentNode, GeneticInformationItem descendantGeneticInformationItem, 452 int ancestorIndex, int parentNodeLevel) { 415 453 myAncestorIndex = ancestorIndex; 416 my LevelDelta = descendantGeneticInformationItem.LevelDelta + 1;454 myAncestorLevel = parentNodeLevel; 417 455 myAncestorDefinition = parentNode.Symbol.GetType(); 418 456 myDescendantCoefficient = descendantGeneticInformationItem.DescendantCoefficient; … … 420 458 myDescendantTimeOffset = descendantGeneticInformationItem.DescendantTimeOffset; 421 459 myDescendantVariableIndex = descendantGeneticInformationItem.DescendantVariableIndex; 460 myDescendantLevel = descendantGeneticInformationItem.DescendantLevel; 461 myDescendantTreeNode = descendantGeneticInformationItem.DescendantTreeNode; 422 462 } 423 463 424 464 public override string ToString() { 425 return "ancestor: " + AncestorDefinition.Name.ToString() + ", [" + AncestorIndex + "], delta " + LevelDelta 426 + "; descendant: " + DescendantDefinition.Name.ToString() + " (varIndex " + DescendantVariableIndex + ", " 427 + DescendantCoefficient + ", t-" + DescendantTimeOffset + ")"; 465 return "ancestor: " + AncestorDefinition.Name.ToString() + ", [" + AncestorIndex + "]; " 466 + "descendant: " + DescendantDefinition.Name.ToString() + " (varIndex " + DescendantVariableIndex + ", " 467 + DescendantCoefficient + ", t-" + DescendantTimeOffset + ");" 468 + " level delta = " + DescendantLevel + "-" + AncestorLevel + " = " + LevelDelta; 428 469 } 429 470
Note: See TracChangeset
for help on using the changeset viewer.