Changeset 8017 for branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/SelfAdaptiveRoundedNormalAllPositionsManipulator.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/SelfAdaptiveRoundedNormalAllPositionsManipulator.cs
r7715 r8017 36 36 [Item("SelfAdaptiveRoundedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N(0,1) to the current value in each position i. The resulting value is rounded to the next feasible value. The values for sigma_i are looked up dynamically. If there are less elements in the strategy vector than positions, then the strategy vector is cycled.")] 37 37 [StorableClass] 38 public class SelfAdaptiveRoundedNormalAllPositionsManipulator : IntegerVectorManipulator, ISelfAdaptiveManipulator {38 public class SelfAdaptiveRoundedNormalAllPositionsManipulator : BoundedIntegerVectorManipulator, ISelfAdaptiveManipulator { 39 39 public Type StrategyParameterType { 40 40 get { return typeof(IIntegerVectorStdDevStrategyParameterOperator); } … … 51 51 } 52 52 53 public IValueLookupParameter<IntMatrix> BoundsParameter {54 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }55 }56 57 53 [StorableConstructor] 58 54 protected SelfAdaptiveRoundedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { } … … 64 60 : base() { 65 61 Parameters.Add(new LookupParameter<DoubleArray>("StrategyParameter", "The vector containing the endogenous strategy parameters.")); 66 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."));67 62 } 68 63 … … 80 75 /// <param name="random">A random number generator.</param> 81 76 /// <param name="vector">The integer vector to manipulate.</param> 77 /// <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> 82 78 public static void Apply(IRandom random, IntegerVector vector, IntMatrix bounds, DoubleArray strategyParameters) { 83 if (strategyParameters == null || strategyParameters.Length == 0) throw new ArgumentException(" ERROR: Vector containing the standard deviations is not defined.", "sigma");84 if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException(" RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");79 if (strategyParameters == null || strategyParameters.Length == 0) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Vector containing the standard deviations is not defined.", "sigma"); 80 if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("SelfAdaptiveRoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds"); 85 81 var N = new NormalDistributedRandom(random, 0.0, 1.0); 86 82 if (strategyParameters != null) { … … 90 86 91 87 int value = (vector[i] + (int)Math.Round((N.NextDouble() * strategyParameters[i % strategyParameters.Length])) - min) / step; 92 vector[i] = Math.Max(min, Math.Min(max, value * step + min));88 vector[i] = RoundFeasible(min, max, step, value); 93 89 } 94 90 } … … 100 96 /// <param name="random">The random number generator.</param> 101 97 /// <param name="vector">The vector of integer values that is manipulated.</param> 102 protected override void Manipulate(IRandom random, IntegerVector vector) { 103 Apply(random, vector, BoundsParameter.ActualValue, StrategyParameterParameter.ActualValue); 98 /// <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> 99 protected override void ManipulateBounded(IRandom random, IntegerVector vector, IntMatrix bounds) { 100 Apply(random, vector, bounds, StrategyParameterParameter.ActualValue); 104 101 } 105 102 }
Note: See TracChangeset
for help on using the changeset viewer.