Changeset 16616 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Timestamp:
- 02/20/19 07:43:25 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r15583 r16616 43 43 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 44 44 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 45 private const string CrossoverProbabilityParameterName = "CrossoverProbability"; 45 46 46 47 #region Parameter Properties … … 53 54 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 54 55 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 56 } 57 public IValueParameter<PercentValue> CrossoverProbabilityParameter { 58 get { return (IValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; } 55 59 } 56 60 #endregion … … 64 68 public IntValue MaximumSymbolicExpressionTreeDepth { 65 69 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 70 } 71 public PercentValue CrossoverProbability { 72 get { return CrossoverProbabilityParameter.Value; } 66 73 } 67 74 #endregion … … 74 81 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 75 82 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))); 76 84 } 77 85 78 86 public override IDeepCloneable Clone(Cloner cloner) { 79 87 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 } 80 95 } 81 96 … … 83 98 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 84 99 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value, 85 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value );100 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value, CrossoverProbability.Value); 86 101 } 87 102 88 103 public static ISymbolicExpressionTree Cross(IRandom random, 89 104 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 91 110 // select a random crossover point in the first parent 92 111 CutPoint crossoverPoint0;
Note: See TracChangeset
for help on using the changeset viewer.