- Timestamp:
- 03/19/10 15:59:37 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/BreederGeneticAlgorithmManipulator.cs
r3060 r3123 38 38 public class BreederGeneticAlgorithmManipulator : RealVectorManipulator { 39 39 private static readonly double[] powerOfTwo = new double[] { 1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 0.00006103515625, 0.000030517578125 }; 40 public ValueLookupParameter<DoubleValue> MinimumParameter { 41 get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; } 42 } 43 public ValueLookupParameter<DoubleValue> MaximumParameter { 44 get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; } 40 public ValueLookupParameter<DoubleMatrix> BoundsParameter { 41 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 45 42 } 46 43 public ValueLookupParameter<DoubleValue> SearchIntervalFactorParameter { … … 48 45 } 49 46 /// <summary> 50 /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with t hree variable51 /// infos (<c>Minimum</c>, <c>Maximum</c> and <c>SearchIntervalFactor</c>).47 /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with two 48 /// parameters (<c>Bounds</c> and <c>SearchIntervalFactor</c>). 52 49 /// </summary> 53 50 public BreederGeneticAlgorithmManipulator() 54 51 : base() { 55 Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "The lower bound for each element in the vector.")); 56 Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "The upper bound for each element in the vector.")); 52 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each element in the vector.")); 57 53 Parameters.Add(new ValueLookupParameter<DoubleValue>("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", new DoubleValue(0.1))); 58 54 } … … 63 59 /// <param name="random">A random number generator.</param> 64 60 /// <param name="vector">The real vector to manipulate.</param> 65 /// <param name="min">The minimum number of the sampling range for the vector element (inclusive).</param> 66 /// <param name="max">The maximum number of the sampling range for the vector element (exclusive).</param> 61 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 67 62 /// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param> 68 public static void Apply(IRandom random, RealVector vector, Double Value min, DoubleValue max, DoubleValue searchIntervalFactor) {63 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, DoubleValue searchIntervalFactor) { 69 64 int length = vector.Length; 70 65 double prob, value; … … 72 67 value = Sigma(random); 73 68 } while (value == 0); 74 value *= searchIntervalFactor.Value * (max.Value - min.Value);75 69 76 70 prob = 1.0 / (double)length; … … 79 73 for (int i = 0; i < length; i++) { 80 74 if (random.NextDouble() < prob) { 75 double range = bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0]; 81 76 if (random.NextDouble() < 0.5) { 82 vector[i] = vector[i] + value ;77 vector[i] = vector[i] + value * searchIntervalFactor.Value * range; 83 78 } else { 84 vector[i] = vector[i] - value ;79 vector[i] = vector[i] - value * searchIntervalFactor.Value * range; 85 80 } 86 81 wasMutated = true; … … 91 86 if (!wasMutated) { 92 87 int pos = random.Next(length); 88 double range = bounds[pos % bounds.Rows, 1] - bounds[pos % bounds.Rows, 0]; 93 89 if (random.NextDouble() < 0.5) { 94 vector[pos] = vector[pos] + value ;90 vector[pos] = vector[pos] + value * searchIntervalFactor.Value * range; 95 91 } else { 96 vector[pos] = vector[pos] - value ;92 vector[pos] = vector[pos] - value * searchIntervalFactor.Value * range; 97 93 } 98 94 } … … 114 110 115 111 /// <summary> 116 /// Checks the parameters Minimum, Maximum, and SearchIntervalFactor and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue, DoubleValue)"/>.112 /// Checks the parameters Bounds, and SearchIntervalFactor and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue, DoubleValue)"/>. 117 113 /// </summary> 118 114 /// <param name="random">A random number generator.</param> 119 115 /// <param name="realVector">The real vector to manipulate.</param> 120 116 protected override void Manipulate(IRandom random, RealVector realVector) { 121 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 122 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + MaximumParameter.ActualName + " could not be found."); 117 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 123 118 if (SearchIntervalFactorParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + SearchIntervalFactorParameter.ActualName + " could not be found."); 124 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, SearchIntervalFactorParameter.ActualValue);119 Apply(random, realVector, BoundsParameter.ActualValue, SearchIntervalFactorParameter.ActualValue); 125 120 } 126 121 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs
r3060 r3123 38 38 public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator { 39 39 /// <summary> 40 /// The lower bound of the values in the real vector.40 /// The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled. 41 41 /// </summary> 42 public ValueLookupParameter<DoubleValue> MinimumParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; } 44 } 45 /// <summary> 46 /// The upper bound of the values in the real vector. 47 /// </summary> 48 public ValueLookupParameter<DoubleValue> MaximumParameter { 49 get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; } 42 public ValueLookupParameter<DoubleMatrix> BoundsParameter { 43 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 50 44 } 51 45 /// <summary> … … 70 64 /// <summary> 71 65 /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with 72 /// f ive parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,66 /// four parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, 73 67 /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>). 74 68 /// </summary> 75 69 public MichalewiczNonUniformAllPositionsManipulator() 76 70 : base() { 77 Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)")); 78 Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 71 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.")); 79 72 Parameters.Add(new LookupParameter<IntValue>("Generation", "Current generation of the algorithm")); 80 73 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations")); … … 89 82 /// <param name="random">The random number generator.</param> 90 83 /// <param name="vector">The real vector to manipulate.</param> 91 /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param> 92 /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param> 84 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 93 85 /// <param name="currentGeneration">The current generation of the algorithm.</param> 94 86 /// <param name="maximumGenerations">Maximum number of generations.</param> 95 87 /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param> 96 88 /// <returns>The manipulated real vector.</returns> 97 public static void Apply(IRandom random, RealVector vector, Double Value min, DoubleValue max, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {89 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) { 98 90 if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); 99 91 int length = vector.Length; … … 102 94 103 95 for (int i = 0; i < length; i++) { 96 double min = bounds[i % bounds.Rows, 0]; 97 double max = bounds[i % bounds.Rows, 1]; 104 98 if (random.NextDouble() < 0.5) { 105 vector[i] = vector[i] + (max .Value- vector[i]) * (1 - Math.Pow(random.NextDouble(), prob));99 vector[i] = vector[i] + (max - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob)); 106 100 } else { 107 vector[i] = vector[i] - (vector[i] - min .Value) * (1 - Math.Pow(random.NextDouble(), prob));101 vector[i] = vector[i] - (vector[i] - min) * (1 - Math.Pow(random.NextDouble(), prob)); 108 102 } 109 103 } … … 116 110 /// <param name="realVector">The real vector that should be manipulated.</param> 117 111 protected override void Manipulate(IRandom random, RealVector realVector) { 118 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 119 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 112 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 120 113 if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); 121 114 if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); 122 115 if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); 123 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);116 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); 124 117 } 125 118 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
r3060 r3123 38 38 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator { 39 39 /// <summary> 40 /// The lower bound of the values in the real vector.40 /// The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled. 41 41 /// </summary> 42 public ValueLookupParameter<DoubleValue> MinimumParameter { 43 get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; } 44 } 45 /// <summary> 46 /// The upper bound of the values in the real vector. 47 /// </summary> 48 public ValueLookupParameter<DoubleValue> MaximumParameter { 49 get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; } 42 public ValueLookupParameter<DoubleMatrix> BoundsParameter { 43 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 50 44 } 51 45 /// <summary> … … 69 63 70 64 /// <summary> 71 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with f ive72 /// parameters (<c> Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>65 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four 66 /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c> 73 67 /// and <c>GenerationDependency</c>). 74 68 /// </summary> 75 69 public MichalewiczNonUniformOnePositionManipulator() 76 70 : base() { 77 Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)")); 78 Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 71 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.")); 79 72 Parameters.Add(new LookupParameter<IntValue>("Generation", "Current generation of the algorithm")); 80 73 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations")); … … 89 82 /// <param name="random">The random number generator.</param> 90 83 /// <param name="vector">The real vector to manipulate.</param> 91 /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param> 92 /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param> 84 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 93 85 /// <param name="currentGeneration">The current generation of the algorithm.</param> 94 86 /// <param name="maximumGenerations">Maximum number of generations.</param> 95 87 /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param> 96 88 /// <returns>The manipulated real vector.</returns> 97 public static void Apply(IRandom random, RealVector vector, Double Value min, DoubleValue max, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {89 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) { 98 90 if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); 99 91 int length = vector.Length; … … 102 94 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value))); 103 95 96 double min = bounds[index % bounds.Rows, 0]; 97 double max = bounds[index % bounds.Rows, 1]; 98 104 99 if (random.NextDouble() < 0.5) { 105 vector[index] = vector[index] + (max .Value- vector[index]) * prob;100 vector[index] = vector[index] + (max - vector[index]) * prob; 106 101 } else { 107 vector[index] = vector[index] - (vector[index] - min .Value) * prob;102 vector[index] = vector[index] - (vector[index] - min) * prob; 108 103 } 109 104 } … … 115 110 /// <param name="realVector">The real vector that should be manipulated.</param> 116 111 protected override void Manipulate(IRandom random, RealVector realVector) { 117 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 118 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 112 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 119 113 if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); 120 114 if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); 121 115 if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); 122 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);116 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); 123 117 } 124 118 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs
r3060 r3123 33 33 /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg. 34 34 /// </remarks> 35 [Item("UniformOnePositionManipulator", "Changes a single position in the vector by sampling uniformly from the interval [Minimum , Maximum). It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]35 [Item("UniformOnePositionManipulator", "Changes a single position in the vector by sampling uniformly from the interval [Minimum_i, Maximum_i) in dimension i. It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 36 36 [StorableClass] 37 37 public class UniformOnePositionManipulator : RealVectorManipulator { 38 38 /// <summary> 39 /// The lower boundof the values in the real vector.39 /// The bounds of the values in the real vector. 40 40 /// </summary> 41 public ValueLookupParameter<DoubleValue> MinimumParameter { 42 get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; } 43 } 44 /// <summary> 45 /// The upper bound of the values in the real vector. 46 /// </summary> 47 public ValueLookupParameter<DoubleValue> MaximumParameter { 48 get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; } 41 public ValueLookupParameter<DoubleMatrix> BoundsParameter { 42 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 49 43 } 50 44 51 45 /// <summary> 52 /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two parameters53 /// (<c> Minimum</c> and <c>Maximum</c>).46 /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with one parameter 47 /// (<c>Bounds</c>). 54 48 /// </summary> 55 49 public UniformOnePositionManipulator() { 56 Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)")); 57 Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 50 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "Lower and upper bound of the positions in the vector.")); 58 51 } 59 52 … … 63 56 /// <param name="random">A random number generator.</param> 64 57 /// <param name="vector">The real vector to manipulate.</param> 65 /// <param name="min">The minimum value of the sampling range for 66 /// the vector element to change (inclusive).</param> 67 /// <param name="max">The maximum value of the sampling range for 68 /// the vector element to change (exclusive).</param> 69 public static void Apply(IRandom random, RealVector vector, DoubleValue min, DoubleValue max) { 58 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 59 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds) { 70 60 int index = random.Next(vector.Length); 71 vector[index] = min.Value + random.NextDouble() * (max.Value - min.Value); 61 double min = bounds[index % bounds.Rows, 0]; 62 double max = bounds[index % bounds.Rows, 1]; 63 vector[index] = min + random.NextDouble() * (max - min); 72 64 } 73 65 74 66 /// <summary> 75 /// Checks if the minimum and maximum parameters are available and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue)"/>.67 /// Checks if the bounds parameters is available and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleMatrix)"/>. 76 68 /// </summary> 77 69 /// <param name="random">The random number generator to use.</param> 78 70 /// <param name="realVector">The real vector to manipulate.</param> 79 71 protected override void Manipulate(IRandom random, RealVector realVector) { 80 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 81 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("UniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 82 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue); 72 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 73 Apply(random, realVector, BoundsParameter.ActualValue); 83 74 } 84 75 }
Note: See TracChangeset
for help on using the changeset viewer.