Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/11 13:47:28 (13 years ago)
Author:
sforsten
Message:

#1669: branch has been merged with the trunk in revision 7081 and methods in RegressionBenchmark have been renamed.

Location:
branches/RegressionBenchmarks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks

  • branches/RegressionBenchmarks/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r6944 r7085  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     32  [NonDiscoverableType]
    3133  [StorableClass]
    3234  [Item("FullTreeCreator", "An operator that creates new symbolic expression trees using the 'Full' method")]
     
    6062    public IntValue MaximumSymbolicExpressionTreeDepth {
    6163      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65
     66    public IntValue MaximumSymbolicExpressionTreeLength {
     67      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    6268    }
    6369
     
    97103
    98104    protected override ISymbolicExpressionTree Create(IRandom random) {
    99       return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeDepth.Value);
     105      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     106    }
     107
     108    public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
     109      return Create(random, grammar, maxTreeLength, maxTreeDepth);
    100110    }
    101111
     
    108118    /// <param name="grammar">Available tree grammar</param>
    109119    /// <param name="maxTreeDepth">Maximum tree depth</param>
     120    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    110121    /// <returns></returns>
    111     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     122    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    112123      var tree = new SymbolicExpressionTree();
    113124      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     
    138149
    139150      for (var i = 0; i != arity; ++i) {
    140         var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol,i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);
     151        var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol, i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);
    141152        var selectedSymbol = possibleSymbols.SelectRandom(random);
    142153        var tree = selectedSymbol.CreateTreeNode();
     
    157168        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    158169
     170      for (var i = 0; i != arity; ++i) {
     171        var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i);
     172        possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 &&
     173                                          root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth &&
     174                                          root.Grammar.GetMaximumExpressionDepth(s) > maxDepth - currentDepth);
    159175
    160       for (var i = 0; i != arity; ++i) {
    161         var possibleSymbols = currentDepth < maxDepth ?
    162           root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0) :
    163           root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0);
     176
     177        if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree.");
    164178        var selectedSymbol = possibleSymbols.SelectRandom(random);
    165179        var tree = selectedSymbol.CreateTreeNode();
Note: See TracChangeset for help on using the changeset viewer.