Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/03/10 14:11:02 (13 years ago)
Author:
mkommend
Message:

Corrected SubTreeCrossover and ReplaceBranchManipulation to handle MaxExpressionDepth correctly. Additionally MaxExpressionDepth < 3 is not allowed.
(ticket #1315).

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs

    r4722 r5014  
    6666      SymbolicExpressionTreeNode crossoverPoint0;
    6767      int replacedSubtreeIndex;
    68       SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize - 1, maxTreeHeight - 1, out crossoverPoint0, out replacedSubtreeIndex);
     68      SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize, maxTreeHeight, out crossoverPoint0, out replacedSubtreeIndex);
    6969
    7070      // calculate the max size and height that the inserted branch can have
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs

    r4722 r5014  
    5353                               from subtree in parent.SubTrees
    5454                               select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random);
     55
     56      int maxSize = maxTreeSize - symbolicExpressionTree.Size + manipulationPoint.Node.GetSize();
     57      int maxHeight = maxTreeHeight - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight();
    5558      // find possible symbols for the node (also considering the existing branches below it)
    56       var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)
     59      var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index, maxHeight)
    5760                           select symbol;
     61      if (allowedSymbols.Count() <= 1) return;
    5862
    59       if (allowedSymbols.Count() <= 1) {
    60         return;
    61       }
    62       var oldBranch = manipulationPoint.Node;
    63       int oldBranchSize = manipulationPoint.Node.GetSize();
    64 
    65       var seedSymbol = SelectRandomSymbol(random, allowedSymbols);
    66 
    67       // replace the old node with the new node
     63      var seedSymbol = SelectRandomSymbol(random, allowedSymbols);  // replace the old node with the new node
    6864      var seedNode = seedSymbol.CreateTreeNode();
    6965      if (seedNode.HasLocalParameters)
     
    7268      manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index);
    7369      manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, seedNode);
    74       int maxSize = Math.Max(oldBranchSize, seedNode.Grammar.GetMinExpressionLength(seedNode.Symbol)) * 2;
    75       var bla = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxSize, 0, 0);
     70      seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxHeight, 0, 0);
    7671      success = true;
    7772    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs

    r4722 r5014  
    178178      return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex));
    179179    }
     180    public IEnumerable<Symbol> GetAllowedSymbols(int argumentIndex, int maxExpressionDepth) {
     181      return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex) && Grammar.GetMinExpressionDepth(s) <= maxExpressionDepth);
     182    }
     183
    180184    public int GetMinSubtreeCount() {
    181185      return Grammar.GetMinSubtreeCount(Symbol);
Note: See TracChangeset for help on using the changeset viewer.