Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/10 15:59:37 (15 years ago)
Author:
abeham
Message:

Updated RealVector encoding to use a double matrix as bounds #929

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/UniformOnePositionManipulator.cs

    r3060 r3123  
    3333  /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.
    3434  /// </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.")]
    3636  [StorableClass]
    3737  public class UniformOnePositionManipulator : RealVectorManipulator {
    3838    /// <summary>
    39     /// The lower bound of the values in the real vector.
     39    /// The bounds of the values in the real vector.
    4040    /// </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"]; }
    4943    }
    5044
    5145    /// <summary>
    52     /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with two parameters
    53     /// (<c>Minimum</c> and <c>Maximum</c>).
     46    /// Initializes a new instance of <see cref="UniformOnePositionManipulator"/> with one parameter
     47    /// (<c>Bounds</c>).
    5448    /// </summary>
    5549    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."));
    5851    }
    5952
     
    6356    /// <param name="random">A random number generator.</param>
    6457    /// <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) {
    7060      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);
    7264    }
    7365
    7466    /// <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)"/>.
    7668    /// </summary>
    7769    /// <param name="random">The random number generator to use.</param>
    7870    /// <param name="realVector">The real vector to manipulate.</param>
    7971    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);
    8374    }
    8475  }
Note: See TracChangeset for help on using the changeset viewer.