Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17490


Ignore:
Timestamp:
04/02/20 09:40:32 (5 years ago)
Author:
gkronber
Message:

#3067: add crossover probability for subtree crossover and initialized it to 100%

File:
1 edited

Legend:

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

    r17180 r17490  
    4343    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4444    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     45    private const string CrossoverProbabilityParameterName = "CrossoverProbability";
    4546
    4647    #region Parameter Properties
     
    5354    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    5455      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     56    }
     57    public IFixedValueParameter<DoubleValue> CrossoverProbabilityParameter {
     58      get { return (IFixedValueParameter<DoubleValue>)Parameters[CrossoverProbabilityParameterName]; }
    5559    }
    5660    #endregion
     
    6468    public IntValue MaximumSymbolicExpressionTreeDepth {
    6569      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     70    }
     71    public double CrossoverProbability {
     72      get { return CrossoverProbabilityParameter.Value.Value; }
     73      set { CrossoverProbabilityParameter.Value.Value = value; }
    6674    }
    6775    #endregion
     
    7482      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    7583      Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
     84      Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1)));
     85    }
     86
     87    [StorableHook(HookType.AfterDeserialization)]
     88    private void AfterDeserialization() {
     89      if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) {
     90        Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1)));
     91      }
    7692    }
    7793
     
    8298    public override ISymbolicExpressionTree Crossover(IRandom random,
    8399      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    84       return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
     100      return Cross(random, parent0, parent1, CrossoverProbability, InternalCrossoverPointProbability.Value,
    85101        MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    86102    }
     
    88104    public static ISymbolicExpressionTree Cross(IRandom random,
    89105      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1,
     106      double probability,
    90107      double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) {
     108      if (random.NextDouble() >= probability) return random.NextDouble() < 0.5 ? parent0 : parent1;
    91109      // select a random crossover point in the first parent
    92110      CutPoint crossoverPoint0;
Note: See TracChangeset for help on using the changeset viewer.