Changeset 17975
- Timestamp:
- 05/06/21 12:14:02 (4 years ago)
- Location:
- stable
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17490-17492,17871-17872
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding merged: 17490-17491,17871-17872
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r17181 r17975 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 IFixedValueParameter<PercentValue> CrossoverProbabilityParameter { 58 get { return (IFixedValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; } 55 59 } 56 60 #endregion … … 64 68 public IntValue MaximumSymbolicExpressionTreeDepth { 65 69 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 70 } 71 public double CrossoverProbability { 72 get { return CrossoverProbabilityParameter.Value.Value; } 73 set { CrossoverProbabilityParameter.Value.Value = value; } 66 74 } 67 75 #endregion … … 73 81 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 74 82 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 75 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 ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9, true))); 84 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true))); 85 } 86 87 [StorableHook(HookType.AfterDeserialization)] 88 private void AfterDeserialization() { 89 // replace with PercentValue for files which had CrossoverProbability as DoubleValue 90 if (Parameters.ContainsKey(CrossoverProbabilityParameterName) && (Parameters[CrossoverProbabilityParameterName] is IFixedValueParameter<DoubleValue> oldParam)) { 91 var oldValue = oldParam.Value.Value; 92 Parameters.Remove(oldParam); 93 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(oldValue))); 94 } 95 if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) { 96 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true))); 97 } 76 98 } 77 99 … … 82 104 public override ISymbolicExpressionTree Crossover(IRandom random, 83 105 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 84 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,106 return Cross(random, parent0, parent1, CrossoverProbability, InternalCrossoverPointProbability.Value, 85 107 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 86 108 } … … 88 110 public static ISymbolicExpressionTree Cross(IRandom random, 89 111 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, 112 double probability, 90 113 double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) { 114 if ((probability < 1) && (random.NextDouble() >= probability)) return parent0; 91 115 // select a random crossover point in the first parent 92 116 CutPoint crossoverPoint0; -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 17492
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/AllArchitectureAlteringOperatorsTest.cs
r17181 r17975 86 86 par1 = (SymbolicExpressionTree)trees.SampleRandom(random).Clone(); 87 87 } while (par0.Length > MAX_TREE_LENGTH || par1.Length > MAX_TREE_LENGTH); 88 var newTree = SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH);88 var newTree = SubtreeCrossover.Cross(random, par0, par1, 1.0, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH); 89 89 stopwatch.Stop(); 90 90 Util.IsValid(newTree); -
stable/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/SubtreeCrossoverTest.cs
r17181 r17975 54 54 var par0 = (ISymbolicExpressionTree)trees.SampleRandom(random).Clone(); 55 55 var par1 = (ISymbolicExpressionTree)trees.SampleRandom(random).Clone(); 56 children[i] = SubtreeCrossover.Cross(random, par0, par1, 0.9, 100, 10);56 children[i] = SubtreeCrossover.Cross(random, par0, par1, 1.0, 0.9, 100, 10); 57 57 } 58 58 trees = children;
Note: See TracChangeset
for help on using the changeset viewer.