Changeset 3123 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs
- Timestamp:
- 03/19/10 15:59:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.