Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Crossover
- Timestamp:
- 07/26/17 19:34:13 (7 years ago)
- Location:
- branches/PushGP/HeuristicLab.PushGP
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP
-
Property
svn:ignore
set to
*.user
-
Property
svn:ignore
set to
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Crossover/AlternationCrossover.cs
r15275 r15289 10 10 using HeuristicLab.Parameters; 11 11 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 12 using HeuristicLab.Problems.ProgramSynthesis.Base.Extensions; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 13 14 using HeuristicLab.Random; … … 23 24 public AlternationCrossover() { 24 25 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 26 25 27 Parameters.Add(new ScopeTreeLookupParameter<PlushVector>("Parents", "The parent vectors which should be crossed.")); 26 28 ParentsParameter.ActualName = "PlushVector"; 29 27 30 Parameters.Add(new LookupParameter<PlushVector>("Child", "The child vector resulting from the crossover.")); 28 31 ChildParameter.ActualName = "PlushVector"; 32 29 33 Parameters.Add(new FixedValueParameter<PercentValue>("AlternationRate", "Specifies the probability of switching to another parent.", new PercentValue(0.5))); 30 34 Parameters.Add(new FixedValueParameter<DoubleValue>("AlignmentDeviation", "When alternating between parents, the index at which to continue copying may be offset backward or forward some amount based on a random sample from a normal distribution with mean 0 and standard deviation set by the alignment deviation parameter", new DoubleValue(1.0))); … … 90 94 91 95 public sealed override IOperation InstrumentedApply() { 92 ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue); 96 ChildParameter.ActualValue = Cross( 97 RandomParameter.ActualValue, 98 ParentsParameter.ActualValue, 99 AlternationRate, 100 MaxLength, 101 AlignmentDeviation); 93 102 return base.InstrumentedApply(); 94 103 } 95 104 96 private PlushVector Cross(IRandom random, ItemArray<PlushVector> parents) { 97 var normalDistributedRandom = new NormalDistributedRandom(random, Mean, AlignmentDeviation); 105 private static PlushVector Cross( 106 IRandom random, 107 ItemArray<PlushVector> parents, 108 double alternationRate, 109 int maxChildLength, 110 double alignmentDeviation) { 111 var normalDistributedRandom = new NormalDistributedRandom(random, Mean, alignmentDeviation); 98 112 var maxLength = parents.Max(p => p.Entries.Count); 99 113 var parentIndex = random.Next(0, 2); 100 114 var parent = parents[parentIndex]; 101 115 var child = new PlushVector(maxLength); 102 var maxChildLength = MaxLength;103 116 104 117 for (var i = 0; i < maxLength && child.Entries.Count <= maxChildLength; i++) { … … 109 122 110 123 // switch parent? 111 if (random.NextDouble() < AlternationRate) {124 if (random.NextDouble() < alternationRate) { 112 125 parentIndex = parentIndex == 0 ? 1 : 0; 113 126 parent = parents[parentIndex]; 114 i += normalDistributedRandom.Next ();127 i += normalDistributedRandom.NextRounded(); 115 128 i = Math.Max(i, 0); 116 129 }
Note: See TracChangeset
for help on using the changeset viewer.