Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/11 13:47:28 (12 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/GrowTreeCreator.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("GrowTreeCreator", "An operator that creates new symbolic expression trees using the 'Grow' 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
     
    107117    /// <param name="grammar">Available tree grammar</param>
    108118    /// <param name="maxTreeDepth">Maximum tree depth</param>
     119    /// <param name="maxTreeLength">Maximum tree length. This parameter is not used.</param>
    109120    /// <returns></returns>
    110     public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeDepth) {
     121    public static ISymbolicExpressionTree Create(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) {
    111122      var tree = new SymbolicExpressionTree();
    112123      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     
    155166        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    156167
    157 
    158168      for (var i = 0; i != arity; ++i) {
    159         var possibleSymbols = currentDepth < maxDepth
    160                                 ? root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0)
    161                                 : root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(
    162                                   s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0);
     169        var possibleSymbols = root.Grammar.GetAllowedChildSymbols(root.Symbol, i);
     170        possibleSymbols = possibleSymbols.Where(s => s.InitialFrequency > 0.0 &&
     171                                          root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth);
     172        if (!possibleSymbols.Any()) throw new InvalidOperationException("No symbols are available for the tree.");
    163173        var selectedSymbol = possibleSymbols.SelectRandom(random);
    164174        var tree = selectedSymbol.CreateTreeNode();
Note: See TracChangeset for help on using the changeset viewer.