Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/12 13:38:17 (12 years ago)
Author:
abeham
Message:

#1775:

  • Renamed some crossovers
  • Ported some additional crossovers from the real-vector plugin
  • Introduced BoundedIntegerVector* base classes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Manipulators/RoundedNormalAllPositionsManipulator.cs

    r7715 r8017  
    3535  [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.")]
    3636  [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 {
    4238
    4339    public IValueParameter<DoubleArray> SigmaParameter {
     
    5450    public RoundedNormalAllPositionsManipulator()
    5551      : 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."));
    5752      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 })));
    5853    }
     
    6964    /// <param name="sigma">The sigma vector determining the strength of the mutation.</param>
    7065    /// <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>
    7268    /// <returns>The manipulated integer vector.</returns>
    7369    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");
    7571      if (bounds == null || bounds.Rows == 0 || bounds.Columns < 2) throw new ArgumentException("RoundedNormalAllPositionsManipulator: Invalid bounds specified.", "bounds");
    7672      var N = new NormalDistributedRandom(random, 0.0, 1.0);
     
    8076
    8177        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);
    8379      }
    8480    }
     
    8985    /// <param name="random">The random number generator.</param>
    9086    /// <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);
    9390    }
    9491  }
Note: See TracChangeset for help on using the changeset viewer.