Changeset 15289 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Manipulator/UniformMutation.cs
- 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/Manipulator/UniformMutation.cs
r15275 r15289 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Manipulator { 2 2 3 using HeuristicLab.Common; 3 4 using HeuristicLab.Core; … … 11 12 using HeuristicLab.Problems.ProgramSynthesis.Push.Encoding; 12 13 using HeuristicLab.Problems.ProgramSynthesis.Push.Generators.CodeGenerator; 13 using HeuristicLab.Random;14 14 15 15 /// <summary> … … 23 23 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 24 24 Parameters.Add(new LookupParameter<PlushVector>("PlushVector", "The vector which should be manipulated.")); 25 Parameters.Add(new ValueLookupParameter<IntValue>("MinLength", "The min length of the vector."));26 Parameters.Add(new ValueLookupParameter<IntValue>("MaxLength", "The max length of the vector."));27 25 Parameters.Add(new ValueLookupParameter<IReadOnlyExpressionsConfiguration>("Instructions", "The enabled instructions")); 28 26 Parameters.Add(new ValueLookupParameter<IReadOnlyErcOptions>("ErcOptions", "ERC options")); 29 27 Parameters.Add(new ValueLookupParameter<PercentValue>("InInstructionProbability", "The probability of IN Instructions")); 30 28 31 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability a value gets mutated", new PercentValue(0.02))); 32 Parameters.Add(new FixedValueParameter<DoubleValue>("CloseMutationDeviation", "When mutating individual, the amount of which the close marker is incremented or decrement is based on a random sample from a normal distribution with mean 0 and standard deviation set by the close mutation deviation parameter", new DoubleValue(1.0))); 29 Parameters.Add(new FixedValueParameter<PercentValue>("InstructionMutationProbability", "The probability an instruction gets mutated", new PercentValue(0.02))); 30 Parameters.Add(new FixedValueParameter<PercentValue>("CloseMutationProbability", "The probability close gets mutated", new PercentValue(0.02))); 31 Parameters.Add(new FixedValueParameter<PercentValue>("CloseIncrementRate", "When mutating individual, the increment rate specifies if close should be increased or decreased by 1.", new PercentValue(0.5))); 33 32 } 34 33 … … 50 49 } 51 50 52 public IValueParameter<PercentValue> CloseMutation DeviationParameter51 public IValueParameter<PercentValue> CloseMutationProbabilityParameter 53 52 { 54 get { return (IValueParameter<PercentValue>)Parameters["CloseMutation Deviation"]; }53 get { return (IValueParameter<PercentValue>)Parameters["CloseMutationProbability"]; } 55 54 } 56 55 57 public double CloseMutation Deviation56 public double CloseMutationProbability 58 57 { 59 get { return CloseMutationDeviationParameter.Value.Value; } 60 set { CloseMutationDeviationParameter.Value.Value = value; } 58 get { return CloseMutationProbabilityParameter.Value.Value; } 59 set { CloseMutationProbabilityParameter.Value.Value = value; } 60 } 61 62 public IValueParameter<PercentValue> CloseIncrementRateParameter 63 { 64 get { return (IValueParameter<PercentValue>)Parameters["CloseIncrementRate"]; } 65 } 66 67 public double CloseIncrementRate 68 { 69 get { return CloseIncrementRateParameter.Value.Value; } 70 set { CloseIncrementRateParameter.Value.Value = value; } 61 71 } 62 72 … … 72 82 { 73 83 get { return (ILookupParameter<PlushVector>)Parameters["PlushVector"]; } 74 }75 public IValueLookupParameter<IntValue> MinLengthParameter76 {77 get { return (IValueLookupParameter<IntValue>)Parameters["MinLength"]; }78 }79 public IValueLookupParameter<IntValue> MaxLengthParameter80 {81 get { return (IValueLookupParameter<IntValue>)Parameters["MaxLength"]; }82 84 } 83 85 public IValueLookupParameter<IReadOnlyExpressionsConfiguration> InstructionsParameter … … 99 101 100 102 public sealed override IOperation InstrumentedApply() { 101 Manipulate(RandomParameter.ActualValue, PlushVectorParameter.ActualValue); 103 Manipulate( 104 RandomParameter.ActualValue, 105 PlushVectorParameter.ActualValue, 106 CloseIncrementRate, 107 ErcOptionsParameter.ActualValue, 108 InstructionsParameter.ActualValue, 109 InInstructionProbabilityParameter.ActualValue.Value, 110 CloseMutationProbability, 111 InstructionMutationProbability); 102 112 return base.InstrumentedApply(); 103 113 } 104 114 105 private void Manipulate(IRandom random, PlushVector plushVector) { 106 var normalDistributedRandom = new NormalDistributedRandom(random, 0, CloseMutationDeviation); 107 var ercOptions = ErcOptionsParameter.ActualValue; 108 var instructions = InstructionsParameter.ActualValue; 109 var inInstructionProbability = InInstructionProbabilityParameter.ActualValue.Value; 110 var instructionMutationProbability = InstructionMutationProbability; 115 private static void Manipulate( 116 IRandom random, 117 PlushVector plushVector, 118 double closeIncrementRate, 119 IReadOnlyErcOptions ercOptions, 120 IReadOnlyExpressionsConfiguration instructions, 121 double inInstructionProbability, 122 double closeMutationProbability, 123 double instructionMutationProbability 124 ) { 111 125 112 126 for (var i = 0; i < plushVector.Entries.Count; i++) { … … 123 137 } 124 138 125 entry.Close += normalDistributedRandom.Next(); 139 x = random.NextDouble(); 140 141 if (x < closeMutationProbability) { 142 x = random.NextDouble(); 143 entry.Close += x < closeIncrementRate ? 1 : -1; 144 145 if (entry.Close < 0) 146 entry.Close = 0; 147 } 126 148 } 127 149
Note: See TracChangeset
for help on using the changeset viewer.