Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/19 07:43:25 (6 years ago)
Author:
gkronber
Message:

#2925 added crossover probability (important for multi-encoding in this case), re-added scaling of targets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r15583 r16616  
    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 IValueParameter<PercentValue> CrossoverProbabilityParameter {
     58      get { return (IValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; }
    5559    }
    5660    #endregion
     
    6468    public IntValue MaximumSymbolicExpressionTreeDepth {
    6569      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     70    }
     71    public PercentValue CrossoverProbability {
     72      get { return CrossoverProbabilityParameter.Value; }
    6673    }
    6774    #endregion
     
    7481      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    7582      Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9)));
     83      Parameters.Add(new ValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability to apply crossover (default 100%).", new PercentValue(1)));
    7684    }
    7785
    7886    public override IDeepCloneable Clone(Cloner cloner) {
    7987      return new SubtreeCrossover(this, cloner);
     88    }
     89
     90    [StorableHook(HookType.AfterDeserialization)]
     91    private void AfterDeserialization() {
     92      if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) {
     93        Parameters.Add(new ValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability to apply crossover (default 100%).", new PercentValue(1)));
     94      }
    8095    }
    8196
     
    8398      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    8499      return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
    85         MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
     100        MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value, CrossoverProbability.Value);
    86101    }
    87102
    88103    public static ISymbolicExpressionTree Cross(IRandom random,
    89104      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1,
    90       double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) {
     105      double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth, double crossoverProbability = 1.0) {
     106      if (random.NextDouble() >= crossoverProbability) {
     107        return random.NextDouble() < 0.5 ? parent0 : parent1;
     108      }
     109
    91110      // select a random crossover point in the first parent
    92111      CutPoint crossoverPoint0;
Note: See TracChangeset for help on using the changeset viewer.