Changeset 8017 for branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs
- Timestamp:
- 06/17/12 13:38:17 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs
r7715 r8017 35 35 [Item("RoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N_i(0,1) to the current value in each position i given the values for sigma_i in the parameter. The result is rounded to the next feasible value. If there are less elements in Sigma than positions, then Sigma is cycled.")] 36 36 [StorableClass] 37 public class RoundedNormalAllPositionsManipulator : IntegerVectorManipulator { 38 39 public IValueLookupParameter<IntMatrix> BoundsParameter { 40 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; } 41 } 37 public class RoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator { 42 38 43 39 public IValueParameter<DoubleArray> SigmaParameter { … … 54 50 public RoundedNormalAllPositionsManipulator() 55 51 : base() { 56 Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));57 52 Parameters.Add(new ValueParameter<DoubleArray>("Sigma", "The vector containing the standard deviations used for manipulating each dimension. If it is only of length one the same sigma will be used for every dimension.", new DoubleArray(new double[] { 1 }))); 58 53 } … … 69 64 /// <param name="sigma">The sigma vector determining the strength of the mutation.</param> 70 65 /// <param name="random">A random number generator.</param> 71 /// <param name="vector">The integer vector to manipulate.</param> 66 /// <param name="vector">The integer vector to manipulate.</param># 67 /// <param name="bounds">The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).</param> 72 68 /// <returns>The manipulated integer vector.</returns> 73 69 public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray sigma) { 74 if (sigma == null || sigma.Length == 0) throw new ArgumentException(" ERROR: Vector containing the standard deviations is not defined.", "sigma");70 if (sigma == null || sigma.Length == 0) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma"); 75 71 if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds"); 76 72 var N = new NormalDistributedRandom(random, 0.0, 1.0); … … 80 76 81 77 int value = (vector[i] + (int)Math.Round((N.NextDouble() * sigma[i % sigma.Length])) - min) / step; 82 vector[i] = Math.Max(min, Math.Min(max, value * step + min));78 vector[i] = RoundFeasible(min, max, step, value); 83 79 } 84 80 } … … 89 85 /// <param name="random">The random number generator.</param> 90 86 /// <param name="vector">The vector of integer values that is manipulated.</param> 91 protected override void Manipulate(IRandom random, IntegerVector vector) { 92 Apply(random, vector, BoundsParameter.ActualValue, SigmaParameter.Value); 87 /// <param name="bounds">The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).</param> 88 protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) { 89 Apply(random, vector, bounds, SigmaParameter.Value); 93 90 } 94 91 }
Note: See TracChangeset
for help on using the changeset viewer.