Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/11 19:01:00 (14 years ago)
Author:
gkronber
Message:

#1418 changes in symbolic expression tree encoding.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4

    • Property svn:ignore
      •  

        old new  
        22obj
        33HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs
         4*.user
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/CrossoverPoint.cs

    r5445 r5499  
    2121
    2222
    23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
    24   public class CrossoverPoint {
     23namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     24  internal class CrossoverPoint {
    2525    public SymbolicExpressionTreeNode Parent { get; set; }
    2626    public SymbolicExpressionTreeNode Child { get; set; }
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r5445 r5499  
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
     31namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    3232  /// <summary>
    3333  /// Takes two parent individuals P0 and P1 each. Selects a random node N0 of P0 and a random node N1 of P1.
     
    3838  [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")]
    3939  [StorableClass]
    40   public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover {
     40  public sealed class SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {
     41    private const string InternalCrossoverPointProbabilityParameterName = "InternalCrossoverPointProbability";
     42    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     43    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     44    #region Parameter Properties
    4145    public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter {
    42       get { return (IValueLookupParameter<PercentValue>)Parameters["InternalCrossoverPointProbability"]; }
    43     }
     46      get { return (IValueLookupParameter<PercentValue>)Parameters[InternalCrossoverPointProbabilityParameterName]; }
     47    }
     48    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     49      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     50    }
     51    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
     52      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     53    }
     54    #endregion
     55    #region Properties
     56    public PercentValue InternalCrossoverPointProbability {
     57      get { return InternalCrossoverPointProbabilityParameter.ActualValue; }
     58    }
     59    public IntValue MaximumSymbolicExpressionTreeLength {
     60      get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }
     61    }
     62    public IntValue MaximumSymbolicExpressionTreeDepth {
     63      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     64    }
     65    #endregion
    4466    [StorableConstructor]
    4567    private SubtreeCrossover(bool deserializing) : base(deserializing) { }
     
    4769    public SubtreeCrossover()
    4870      : base() {
    49       Parameters.Add(new ValueLookupParameter<PercentValue>("InternalCrossoverPointProbability", "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
     71      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
     72      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
     73      Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
    5074    }
    5175
     
    5579
    5680    protected override SymbolicExpressionTree Cross(IRandom random,
    57       SymbolicExpressionTree parent0, SymbolicExpressionTree parent1,
    58       IntValue maxTreeSize, IntValue maxTreeHeight, out bool success) {
    59       return Cross(random, parent0, parent1, InternalCrossoverPointProbabilityParameter.ActualValue.Value, maxTreeSize.Value, maxTreeHeight.Value, out success);
     81      SymbolicExpressionTree parent0, SymbolicExpressionTree parent1) {
     82      return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
     83        MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    6084    }
    6185
    6286    public static SymbolicExpressionTree Cross(IRandom random,
    6387      SymbolicExpressionTree parent0, SymbolicExpressionTree parent1,
    64       double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight, out bool success) {
     88      double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight) {
    6589      // select a random crossover point in the first parent
    6690      SymbolicExpressionTreeNode crossoverPoint0;
     
    81105
    82106      if (allowedBranches.Count == 0) {
    83         success = false;
    84107        return parent0;
    85108      } else {
     
    90113        crossoverPoint0.RemoveSubTree(replacedSubtreeIndex);
    91114        crossoverPoint0.InsertSubTree(replacedSubtreeIndex, selectedBranch);
    92         success = true;
    93115        return parent0;
    94116      }
     
    190212    }
    191213
    192     private static int GetBranchLevel(SymbolicExpressionTreeNode root, SymbolicExpressionTreeNode point) {
     214    private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {
    193215      if (root == point) return 0;
    194216      foreach (var subtree in root.SubTrees) {
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs

    r5445 r5499  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
    2726using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers {
     29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    3130  /// <summary>
    3231  /// A base class for operators that perform a crossover of symbolic expression trees.
     
    3736    private const string ParentsParameterName = "Parents";
    3837    private const string ChildParameterName = "Child";
    39     private const string FailedCrossoverEventsParameterName = "FailedCrossoverEvents";
     38    #region Parameter Properties
    4039    public ILookupParameter<ItemArray<SymbolicExpressionTree>> ParentsParameter {
    4140      get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[ParentsParameterName]; }
     
    4443      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ChildParameterName]; }
    4544    }
    46     public IValueParameter<IntValue> FailedCrossoverEventsParameter {
    47       get { return (ValueParameter<IntValue>)Parameters[FailedCrossoverEventsParameterName]; }
     45    #endregion
     46    #region Properties
     47    public ItemArray<SymbolicExpressionTree> Parents {
     48      get { return ParentsParameter.ActualValue; }
    4849    }
    49 
    50     public IntValue FailedCrossoverEvents {
    51       get { return FailedCrossoverEventsParameter.Value; }
     50    public SymbolicExpressionTree Child {
     51      get { return ChildParameter.ActualValue; }
     52      set { ChildParameter.ActualValue = value; }
    5253    }
     54    #endregion
    5355    [StorableConstructor]
    5456    protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { }
     
    5860      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
    5961      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
    60       Parameters.Add(new ValueParameter<IntValue>(FailedCrossoverEventsParameterName, "The number of failed crossover events (child is an exact copy of a parent)", new IntValue()));
    6162    }
    6263
    6364    public sealed override IOperation Apply() {
    64       if (ParentsParameter.ActualValue.Length != 2)
     65      if (Parents.Length != 2)
    6566        throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
    6667
    67       SymbolicExpressionTree parent0 = ParentsParameter.ActualValue[0];
    68       SymbolicExpressionTree parent1 = ParentsParameter.ActualValue[1];
     68      SymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]);
    6969
    70       IRandom random = RandomParameter.ActualValue;
    71 
    72       bool success;
    73       SymbolicExpressionTree result = Cross(random, parent0, parent1,
    74         MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue, out success);
    75 
    76       if (!success) FailedCrossoverEvents.Value++;
    77 
    78       ChildParameter.ActualValue = result;
     70      Child = result;
    7971      return base.Apply();
    8072    }
    8173
    8274    protected abstract SymbolicExpressionTree Cross(IRandom random,
    83       SymbolicExpressionTree parent0, SymbolicExpressionTree parent1,
    84       IntValue maxTreeSize, IntValue maxTreeHeight, out bool success);
     75      SymbolicExpressionTree parent0, SymbolicExpressionTree parent1);
    8576  }
    8677}
Note: See TracChangeset for help on using the changeset viewer.