Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/15 12:02:20 (9 years ago)
Author:
mkommend
Message:

#2320: Merged r12422, r12423, r12424, r12480, r12481 and r12482 into stable.

Location:
stable
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r12009 r12706  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927using HeuristicLab.PluginInfrastructure;
     
    3634                                 ISymbolicExpressionTreeSizeConstraintOperator,
    3735                                 ISymbolicExpressionTreeGrammarBasedOperator {
    38     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    39     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    40 
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45 
    46     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    47       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    48     }
    49     #endregion
    50     #region Properties
    51     public IntValue MaximumSymbolicExpressionTreeDepth {
    52       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    53     }
    54 
    55     public IntValue MaximumSymbolicExpressionTreeLength {
    56       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    57     }
    58 
    59     #endregion
    6036
    6137    [StorableConstructor]
     
    6339    protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6440
    65     public FullTreeCreator()
    66       : base() {
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    68         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    69       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    70         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    71     }
     41    public FullTreeCreator() : base() { }
    7242
    7343    public override IDeepCloneable Clone(Cloner cloner) {
     
    7747
    7848    protected override ISymbolicExpressionTree Create(IRandom random) {
    79       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     49      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     50          MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    8051    }
    8152
     
    131102          .ToList();
    132103        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     104
     105#pragma warning disable 612, 618
    133106        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     107#pragma warning restore 612, 618
     108
    134109        var tree = selectedSymbol.CreateTreeNode();
    135110        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    163138          throw new InvalidOperationException("No symbols are available for the tree.");
    164139        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     140
     141#pragma warning disable 612, 618
    165142        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     143#pragma warning restore 612, 618
     144       
    166145        var tree = selectedSymbol.CreateTreeNode();
    167146        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    169148      }
    170149
    171       foreach (var subTree in root.Subtrees)
    172         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
    173           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     150      //additional levels should only be added if the maximum depth is not reached yet
     151      if (maxDepth > currentDepth) {
     152        foreach (var subTree in root.Subtrees)
     153          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
     154            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     155      }
    174156    }
    175157  }
  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs

    r12009 r12706  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927using HeuristicLab.PluginInfrastructure;
     
    3331  [StorableClass]
    3432  [Item("GrowTreeCreator", "An operator that creates new symbolic expression trees using the 'Grow' method")]
    35   public class GrowTreeCreator : SymbolicExpressionTreeCreator,
    36                                  ISymbolicExpressionTreeSizeConstraintOperator,
    37                                  ISymbolicExpressionTreeGrammarBasedOperator {
    38     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    39     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    40 
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45 
    46     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    47       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    48     }
    49 
    50     #endregion
    51     #region Properties
    52     public IntValue MaximumSymbolicExpressionTreeDepth {
    53       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    54     }
    55 
    56     public IntValue MaximumSymbolicExpressionTreeLength {
    57       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    58     }
    59     #endregion
    60 
     33  public class GrowTreeCreator : SymbolicExpressionTreeCreator {
    6134    [StorableConstructor]
    6235    protected GrowTreeCreator(bool deserializing) : base(deserializing) { }
    6336    protected GrowTreeCreator(GrowTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6437
    65     public GrowTreeCreator()
    66       : base() {
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    68         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    69       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    70         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    71     }
     38    public GrowTreeCreator() : base() { }
    7239
    7340    public override IDeepCloneable Clone(Cloner cloner) {
     
    7845    protected override ISymbolicExpressionTree Create(IRandom random) {
    7946      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
    80         MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     47        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    8148    }
    8249
     
    12289        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");
    12390
    124       var allowedSymbols = seedNode.Grammar.AllowedSymbols
    125         .Where(s => s.InitialFrequency > 0.0)
    126         .ToList();
     91      var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    12792
    12893      for (var i = 0; i < arity; i++) {
    129         var possibleSymbols = allowedSymbols
    130           .Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i))
    131           .ToList();
     94        var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList();
    13295        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     96
     97#pragma warning disable 612, 618
    13398        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     99#pragma warning restore 612, 618
     100
    134101        var tree = selectedSymbol.CreateTreeNode();
    135102        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    146113    private static void RecursiveCreate(IRandom random, ISymbolicExpressionTreeNode root, int currentDepth, int maxDepth) {
    147114      var arity = SampleArity(random, root);
    148       if (arity <= 0)
    149         throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
     115      if (arity == 0)
     116        return;
    150117
    151118      var allowedSymbols = root.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();
    152119
    153120      for (var i = 0; i < arity; i++) {
    154         var possibleSymbols = allowedSymbols
    155           .Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) &&
    156             root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth)
    157           .ToList();
     121        var possibleSymbols = allowedSymbols.Where(s => root.Grammar.IsAllowedChildSymbol(root.Symbol, s, i) &&
     122                                                        root.Grammar.GetMinimumExpressionDepth(s) - 1 <= maxDepth - currentDepth).ToList();
    158123
    159124        if (!possibleSymbols.Any())
    160125          throw new InvalidOperationException("No symbols are available for the tree.");
     126
    161127        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();
     128#pragma warning disable 612, 618
    162129        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     130#pragma warning restore 612, 618
     131
    163132        var tree = selectedSymbol.CreateTreeNode();
    164133        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
     
    166135      }
    167136
    168       foreach (var subTree in root.Subtrees)
    169         if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)
    170           RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
     137      if (maxDepth > currentDepth)
     138        foreach (var subTree in root.Subtrees)
     139          if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)
     140            RecursiveCreate(random, subTree, currentDepth + 1, maxDepth);
    171141    }
    172142
  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r12009 r12706  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028using HeuristicLab.PluginInfrastructure;
     
    3735    ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator {
    3836    private const int MAX_TRIES = 100;
    39     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    40     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    41     #region Parameter Properties
    42     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    44     }
    45     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    46       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    47     }
    48     #endregion
    49     #region Properties
    50     public IntValue MaximumSymbolicExpressionTreeLength {
    51       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    52     }
    53     public IntValue MaximumSymbolicExpressionTreeDepth {
    54       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    55     }
    56     #endregion
    5737
    5838    [StorableConstructor]
     
    6141    public ProbabilisticTreeCreator()
    6242      : base() {
    63       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    64       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     43
    6544    }
    6645
     
    7150
    7251    protected override ISymbolicExpressionTree Create(IRandom random) {
    73       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     52      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     53        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    7454    }
    7555
     
    186166          if (allowedSymbols.Count == 0) return false;
    187167          var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList();
     168
     169#pragma warning disable 612, 618
    188170          var selectedSymbol = allowedSymbols.SelectRandom(weights, random);
     171#pragma warning restore 612, 618
     172
    189173          ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode();
    190174          if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random);
     
    232216                             select g).First().ToList();
    233217      var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList();
     218
     219#pragma warning disable 612, 618
    234220      var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
     221#pragma warning restore 612, 618
     222
    235223      var tree = selectedSymbol.CreateTreeNode();
    236224      if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs

    r12009 r12706  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    25 using HeuristicLab.Parameters;
    2624using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2725using HeuristicLab.PluginInfrastructure;
     
    3129  [StorableClass]
    3230  [Item("RampedHalfAndHalfTreeCreator", "An operator that creates new symbolic expression trees in an alternate way: half the trees are created usign the 'Grow' method while the other half are created using the 'Full' method")]
    33   public class RampedHalfAndHalfTreeCreator : SymbolicExpressionTreeCreator,
    34                                  ISymbolicExpressionTreeSizeConstraintOperator,
    35                                  ISymbolicExpressionTreeGrammarBasedOperator {
    36     private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    37     private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    38 
    39     #region Parameter Properties
    40     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
    41       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    42     }
    43 
    44     public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    45       get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
    46     }
    47 
    48     #endregion
    49     #region Properties
    50     public IntValue MaximumSymbolicExpressionTreeDepth {
    51       get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
    52     }
    53 
    54     public IntValue MaximumSymbolicExpressionTreeLength {
    55       get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
    56     }
    57     #endregion
    58 
     31  public class RampedHalfAndHalfTreeCreator : SymbolicExpressionTreeCreator {
    5932    [StorableConstructor]
    6033    protected RampedHalfAndHalfTreeCreator(bool deserializing) : base(deserializing) { }
    6134    protected RampedHalfAndHalfTreeCreator(RampedHalfAndHalfTreeCreator original, Cloner cloner) : base(original, cloner) { }
    6235
    63     public RampedHalfAndHalfTreeCreator()
    64       : base() {
    65       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName,
    66         "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored)."));
    67       Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName,
    68         "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    69     }
     36    public RampedHalfAndHalfTreeCreator() : base() { }
    7037
    7138    public override IDeepCloneable Clone(Cloner cloner) {
     
    7441
    7542    protected override ISymbolicExpressionTree Create(IRandom random) {
    76       return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     43      return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,
     44        MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);
    7745    }
    7846
  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r12009 r12706  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3233  [StorableClass]
    3334  public abstract class SymbolicExpressionTreeCreator : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCreator {
    34     private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     35    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     36    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     37
    3538    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
    3639    private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    3740
    3841    #region Parameter Properties
    39     public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
    40       get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
     42    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     43      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    4144    }
    42 
     45    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     47    }
    4348    public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
    4449      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     
    5560    protected SymbolicExpressionTreeCreator()
    5661      : base() {
    57       Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree that should be created."));
    58       Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName,
    59         "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
    60       Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName,
    61         "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
     62      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
     63      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     64      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
     65      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    6266    }
    6367
     
    7882          (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
    7983      }
    80       SymbolicExpressionTreeParameter.ActualValue = Create(Random);
     84      SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue);
    8185      return base.InstrumentedApply();
    8286    }
Note: See TracChangeset for help on using the changeset viewer.