Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/30/10 19:38:22 (14 years ago)
Author:
gkronber
Message:

Worked on symbolic expression tree encoding.
Added view for expression trees (simple textual view in s-exp format).
Implemented SubtreeCrossover.
Fixed bugs in ProbabilisticTreeCreator.
#937 (Data types and operators for symbolic expression tree encoding)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3223 r3237  
    5151      do {
    5252        try {
    53           // determine possible root symbols to create a tree of the target size
    54           var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0)
    55                                     where treeSize <= grammar.MaximalExpressionLength(symbol)
    56                                     where treeSize >= grammar.MinimalExpressionLength(symbol)
    57                                     select symbol;
    58           Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols);
    59           tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight);
     53          tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1);
     54          //// determine possible root symbols to create a tree of the target size
     55          //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0)
     56          //                          where treeSize <= grammar.MaximalExpressionLength(symbol)
     57          //                          where treeSize >= grammar.MinimalExpressionLength(symbol)
     58          //                          select symbol;
     59          //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols);
     60          //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight);
    6061        }
    6162        catch (ArgumentException) {
     
    149150      int minArity = grammar.MinSubTrees(symbol);
    150151      int maxArity = grammar.MaxSubTrees(symbol);
    151       if (maxArity >= targetSize) {
     152      if (maxArity > targetSize) {
    152153        maxArity = targetSize;
    153154      }
    154155      // the min number of sub-trees has to be set to a value that is large enough so that the largest possible tree is at least tree size
    155156      // if 1..3 trees are possible and the largest possible first sub-tree is smaller larger than the target size then minArity should be at least 2
    156       int aggregatedLongestExpressionLength = 1;
     157      long aggregatedLongestExpressionLength = 0;
    157158      for (int i = 0; i < maxArity; i++) {
    158159        aggregatedLongestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i)
    159                                               select grammar.MaximalExpressionLength(symbol)).Max();
     160                                              select grammar.MaximalExpressionLength(s)).Max();
    160161        if (aggregatedLongestExpressionLength < targetSize) minArity = i;
    161162        else break;
     
    164165      // the max number of sub-trees has to be set to a value that is small enough so that the smallest possible tree is at most tree size
    165166      // if 1..3 trees are possible and the smallest possible first sub-tree is already larger than the target size then maxArity should be at most 0
    166       int aggregatedShortestExpressionLength = 1;
     167      long aggregatedShortestExpressionLength = 0;
    167168      for (int i = 0; i < maxArity; i++) {
    168169        aggregatedShortestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i)
    169                                                select grammar.MinimalExpressionLength(symbol)).Min();
     170                                               select grammar.MinimalExpressionLength(s)).Min();
    170171        if (aggregatedShortestExpressionLength > targetSize) {
    171172          maxArity = i;
Note: See TracChangeset for help on using the changeset viewer.