Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4934


Ignore:
Timestamp:
11/25/10 12:37:36 (14 years ago)
Author:
swinkler
Message:

Worked on structural population diversity analysis (#1278):

  • Added storing of descendant nodes.
  • Added storing of level information.
  • Added level filtering.
  • Added prevention of multiple consideration of descendant nodes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs

    r4928 r4934  
    6262      IList<GeneticInformationItem>[] geneticInformationItemsList = new List<GeneticInformationItem>[n];
    6363      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);
    6565      }
    6666      double[,] result = new double[n, n];
     
    9696      }
    9797
    98       private int myLevelDelta;
    99       public int LevelDelta {
    100         get { return myLevelDelta; }
     98      private int myAncestorLevel;
     99      public int AncestorLevel {
     100        get { return myAncestorLevel; }
    101101      }
    102102
     
    138138      public int DescendantTimeOffset {
    139139        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); }
    140154      }
    141155
     
    369383      }*/
    370384
    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) {
    372400        // Idea: collect all descendants' lists and then add new items using the retrieved ones.
    373401        // 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
    374403        if (node.Symbol is ProgramRootSymbol)
    375           return getGeneticInformationItems(node.SubTrees[0], variableNames);
     404          return getGeneticInformationItems(node.SubTrees[0], variableNames, level + 1);
    376405        List<GeneticInformationItem> list = new List<GeneticInformationItem>();
    377406        // 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>();
    380412        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);
    382414          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            }
    386421        }
    387422        return list;
    388423      }
    389424
    390       private GeneticInformationItem (SymbolicExpressionTreeNode node, List<string> variableNames) {
     425      private GeneticInformationItem (SymbolicExpressionTreeNode node, List<string> variableNames, int level) {
    391426        myAncestorIndex = -1;
    392427        VariableTreeNode variableTreeNode = node as VariableTreeNode;
     
    409444        else
    410445          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) {
    415453        myAncestorIndex = ancestorIndex;
    416         myLevelDelta = descendantGeneticInformationItem.LevelDelta + 1;
     454        myAncestorLevel = parentNodeLevel;
    417455        myAncestorDefinition = parentNode.Symbol.GetType();
    418456        myDescendantCoefficient = descendantGeneticInformationItem.DescendantCoefficient;
     
    420458        myDescendantTimeOffset = descendantGeneticInformationItem.DescendantTimeOffset;
    421459        myDescendantVariableIndex = descendantGeneticInformationItem.DescendantVariableIndex;
     460        myDescendantLevel = descendantGeneticInformationItem.DescendantLevel;
     461        myDescendantTreeNode = descendantGeneticInformationItem.DescendantTreeNode;
    422462      }
    423463
    424464      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;
    428469      }
    429470
Note: See TracChangeset for help on using the changeset viewer.