Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3123


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

Location:
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3
Files:
12 edited

Legend:

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

    r3060 r3123  
    2929namespace HeuristicLab.Encodings.RealVectorEncoding {
    3030  /// <summary>
    31   /// Checks if all elements of a real vector are inside a given minimum and maximum value.
     31  /// Checks if all elements of a real vector are inside the bounds.
    3232  /// If not, the elements are corrected.
    3333  /// </summary>
    34   [Item("BoundsChecker", "Checks if all elements of a real vector are inside a given minimum and maximum value. If not, elements are corrected.")]
     34  [Item("BoundsChecker", "Checks if all elements of a real vector are inside the bounds. If not, elements are corrected.")]
    3535  [StorableClass]
    3636  public class BoundsChecker : SingleSuccessorOperator {
     
    3838      get { return (LookupParameter<RealVector>)Parameters["RealVector"]; }
    3939    }
    40     public ValueLookupParameter<DoubleValue> MinimumParameter {
    41       get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; }
    42     }
    43     public ValueLookupParameter<DoubleValue> MaximumParameter {
    44       get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; }
     40    public ValueLookupParameter<DoubleMatrix> BoundsParameter {
     41      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4542    }
    4643
    4744    /// <summary>
    48     /// Initializes a new instance of <see cref="BoundsChecker"/> with three parameters
    49     /// (<c>RealVector</c>, <c>Minimum</c> and <c>Maximum</c>).
     45    /// Initializes a new instance of <see cref="BoundsChecker"/> with two parameters
     46    /// (<c>RealVector</c>, <c>Bounds</c>).
    5047    /// </summary>
    5148    public BoundsChecker()
    5249      : base() {
    5350      Parameters.Add(new LookupParameter<RealVector>("RealVector", "The real-valued vector for which the bounds should be checked."));
    54       Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "The lower bound for each element in the vector."));
    55       Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "The upper bound for each element in the vector."));
     51      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("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."));
    5652    }
    5753
    5854    /// <summary>
    59     /// Checks if all elements of the given <paramref name="vector"/> are inside the given minimum
    60     /// and maximum value and if not they are corrected.
     55    /// Checks if all elements of the given <paramref name="vector"/> are inside the bounds and if not they are corrected.
    6156    /// </summary>
    62     /// <param name="min">The minimum value of the range (inclusive).</param>
    63     /// <param name="max">The maximum value of the range (inclusive).</param>
     57    /// <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>
    6458    /// <param name="vector">The vector to check.</param>
    6559    /// <returns>The corrected real vector.</returns>
    66     public static void Apply(RealVector vector, DoubleValue min, DoubleValue max) {
     60    public static void Apply(RealVector vector, DoubleMatrix bounds) {
    6761      for (int i = 0; i < vector.Length; i++) {
    68         if (vector[i] < min.Value) vector[i] = min.Value;
    69         if (vector[i] > max.Value) vector[i] = max.Value;
     62        double min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1];
     63        if (vector[i] < min) vector[i] = min;
     64        if (vector[i] > max) vector[i] = max;
    7065      }
    7166    }
    7267
    7368    /// <summary>
    74     /// Checks if all elements of the given <paramref name="vector"/> are inside the given minimum
    75     /// and maximum value and if not they are corrected.
     69    /// Checks if all elements of the given <paramref name="vector"/> are inside the bounds and if not they are corrected.
    7670    /// </summary>
    77     /// <exception cref="InvalidOperationException">Thrown when one of the three parameters (vector, minimum, or maximum) could not be found.</exception>
    78     /// <remarks>Calls <see cref="Apply(double, double, double[])"/>.</remarks>
     71    /// <exception cref="InvalidOperationException">Thrown when either vector or bounds could not be found.</exception>
     72    /// <remarks>Calls <see cref="Apply(RealVector, DoubleMatrix)"/>.</remarks>
    7973    /// <inheritdoc select="returns" />
    8074    public override IOperation Apply() {
    8175      if (RealVectorParameter.ActualValue == null) throw new InvalidOperationException("BoundsChecker: Parameter " + RealVectorParameter.ActualName + " could not be found.");
    82       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("BoundsChecker: Parameter " + MinimumParameter.ActualName + " could not be found.");
    83       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("BoundsChecker: Parameter " + MaximumParameter.ActualName + " could not be found.");
    84       Apply(RealVectorParameter.ActualValue, MinimumParameter.ActualValue, MaximumParameter.ActualValue);
     76      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("BoundsChecker: Parameter " + BoundsParameter.ActualName + " could not be found.");
     77      Apply(RealVectorParameter.ActualValue, BoundsParameter.ActualValue);
    8578      return base.Apply();
    8679    }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Creators/UniformRandomRealVectorCreator.cs

    r3060 r3123  
    4848    /// <param name="random">The random number generator.</param>
    4949    /// <param name="length">The length of the real vector.</param>
    50     /// <param name="min">The minimum value of the sampling range for each vector element (inclusive).</param>
    51     /// <param name="max">The maximum value of the sampling range for each vector element (exclusive).</param>
     50    /// <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>
    5251    /// <returns>The newly created real vector.</returns>
    53     public static RealVector Apply(IRandom random, int length, double min, double max) {
    54       if (length <= 0) throw new ArgumentException("UniformRandomRealVectorCreator: Length is smaller or equal to 0.", "length");
    55       if (min > max) throw new ArgumentException("UniformRandomRealVectorCreator: Minimum is greater than Maximum.", "min");
     52    public static RealVector Apply(IRandom random, int length, DoubleMatrix bounds) {
    5653      RealVector result = new RealVector(length);
    57       for (int i = 0; i < length; i++)
    58         result[i] = min + random.NextDouble() * (max - min);
     54      result.Randomize(random, bounds);
    5955      return result;
    6056    }
    6157
    6258    /// <summary>
    63     /// Forwards the call to <see cref="Apply(IRandom, int, double, double)"/>.
     59    /// Forwards the call to <see cref="Apply(IRandom, int, DoubleMatrix)"/>.
    6460    /// </summary>
    6561    /// <param name="random">The pseudo random number generator to use.</param>
    6662    /// <param name="length">The length of the real vector.</param>
    67     /// <param name="minimum">The minimum value of the sampling range for each vector element (inclusive).</param>
    68     /// <param name="maximum">The maximum value of the sampling range for each vector element (exclusive).</param>
     63    /// <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>
    6964    /// <returns>The newly created real vector.</returns>
    70     protected override RealVector Create(IRandom random, IntValue length, DoubleValue minimum, DoubleValue maximum) {
    71       return Apply(random, length.Value, minimum.Value, maximum.Value);
     65    protected override RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds) {
     66      return Apply(random, length.Value, bounds);
    7267    }
    7368  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Interfaces/IRealVectorCreator.cs

    r3060 r3123  
    3030  public interface IRealVectorCreator : IRealVectorOperator, ISolutionCreator {
    3131    IValueLookupParameter<IntValue> LengthParameter { get; }
    32     IValueLookupParameter<DoubleValue> MinimumParameter { get; }
    33     IValueLookupParameter<DoubleValue> MaximumParameter { get; }
     32    IValueLookupParameter<DoubleMatrix> BoundsParameter { get; }
    3433    ILookupParameter<RealVector> RealVectorParameter { get; }
    3534  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/BreederGeneticAlgorithmManipulator.cs

    r3060 r3123  
    3838  public class BreederGeneticAlgorithmManipulator : RealVectorManipulator {
    3939    private static readonly double[] powerOfTwo = new double[] { 1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 0.00006103515625, 0.000030517578125 };
    40     public ValueLookupParameter<DoubleValue> MinimumParameter {
    41       get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; }
    42     }
    43     public ValueLookupParameter<DoubleValue> MaximumParameter {
    44       get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; }
     40    public ValueLookupParameter<DoubleMatrix> BoundsParameter {
     41      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4542    }
    4643    public ValueLookupParameter<DoubleValue> SearchIntervalFactorParameter {
     
    4845    }
    4946    /// <summary>
    50     /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with three variable
    51     /// infos (<c>Minimum</c>, <c>Maximum</c> and <c>SearchIntervalFactor</c>).
     47    /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with two
     48    /// parameters (<c>Bounds</c> and <c>SearchIntervalFactor</c>).
    5249    /// </summary>
    5350    public BreederGeneticAlgorithmManipulator()
    5451      : base() {
    55       Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "The lower bound for each element in the vector."));
    56       Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "The upper bound for each element in the vector."));
     52      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each element in the vector."));
    5753      Parameters.Add(new ValueLookupParameter<DoubleValue>("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", new DoubleValue(0.1)));
    5854    }
     
    6359    /// <param name="random">A random number generator.</param>
    6460    /// <param name="vector">The real vector to manipulate.</param>
    65     /// <param name="min">The minimum number of the sampling range for the vector element (inclusive).</param>
    66     /// <param name="max">The maximum number of the sampling range for the vector element (exclusive).</param>
     61    /// <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>
    6762    /// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param>
    68     public static void Apply(IRandom random, RealVector vector, DoubleValue min, DoubleValue max, DoubleValue searchIntervalFactor) {
     63    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, DoubleValue searchIntervalFactor) {
    6964      int length = vector.Length;
    7065      double prob, value;
     
    7267        value = Sigma(random);
    7368      } while (value == 0);
    74       value *= searchIntervalFactor.Value * (max.Value - min.Value);
    7569
    7670      prob = 1.0 / (double)length;
     
    7973      for (int i = 0; i < length; i++) {
    8074        if (random.NextDouble() < prob) {
     75          double range = bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
    8176          if (random.NextDouble() < 0.5) {
    82             vector[i] = vector[i] + value;
     77            vector[i] = vector[i] + value * searchIntervalFactor.Value * range;
    8378          } else {
    84             vector[i] = vector[i] - value;
     79            vector[i] = vector[i] - value * searchIntervalFactor.Value * range;
    8580          }
    8681          wasMutated = true;
     
    9186      if (!wasMutated) {
    9287        int pos = random.Next(length);
     88        double range = bounds[pos % bounds.Rows, 1] - bounds[pos % bounds.Rows, 0];
    9389        if (random.NextDouble() < 0.5) {
    94           vector[pos] = vector[pos] + value;
     90          vector[pos] = vector[pos] + value * searchIntervalFactor.Value * range;
    9591        } else {
    96           vector[pos] = vector[pos] - value;
     92          vector[pos] = vector[pos] - value * searchIntervalFactor.Value * range;
    9793        }
    9894      }
     
    114110
    115111    /// <summary>
    116     /// Checks the parameters Minimum, Maximum, and SearchIntervalFactor and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue, DoubleValue)"/>.
     112    /// Checks the parameters Bounds, and SearchIntervalFactor and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue, DoubleValue)"/>.
    117113    /// </summary>
    118114    /// <param name="random">A random number generator.</param>
    119115    /// <param name="realVector">The real vector to manipulate.</param>
    120116    protected override void Manipulate(IRandom random, RealVector realVector) {
    121       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
    122       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + MaximumParameter.ActualName + " could not be found.");
     117      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    123118      if (SearchIntervalFactorParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + SearchIntervalFactorParameter.ActualName + " could not be found.");
    124       Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, SearchIntervalFactorParameter.ActualValue);
     119      Apply(random, realVector, BoundsParameter.ActualValue, SearchIntervalFactorParameter.ActualValue);
    125120    }
    126121  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs

    r3060 r3123  
    3838  public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {
    3939    /// <summary>
    40     /// The lower bound of the values in the real vector.
     40    /// 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.
    4141    /// </summary>
    42     public ValueLookupParameter<DoubleValue> MinimumParameter {
    43       get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; }
    44     }
    45     /// <summary>
    46     /// The upper bound of the values in the real vector.
    47     /// </summary>
    48     public ValueLookupParameter<DoubleValue> MaximumParameter {
    49       get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; }
     42    public ValueLookupParameter<DoubleMatrix> BoundsParameter {
     43      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5044    }
    5145    /// <summary>
     
    7064    /// <summary>
    7165    /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with
    72     /// five parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,
     66    /// four parameters (<c>Bounds</c>, <c>CurrentGeneration</c>,
    7367    /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>).
    7468    /// </summary>
    7569    public MichalewiczNonUniformAllPositionsManipulator()
    7670      : base() {
    77       Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)"));
    78       Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
     71      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("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."));
    7972      Parameters.Add(new LookupParameter<IntValue>("Generation", "Current generation of the algorithm"));
    8073      Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));
     
    8982    /// <param name="random">The random number generator.</param>
    9083    /// <param name="vector">The real vector to manipulate.</param>
    91     /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param>
    92     /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param>
     84    /// <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>
    9385    /// <param name="currentGeneration">The current generation of the algorithm.</param>
    9486    /// <param name="maximumGenerations">Maximum number of generations.</param>
    9587    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
    9688    /// <returns>The manipulated real vector.</returns>
    97     public static void Apply(IRandom random, RealVector vector, DoubleValue min, DoubleValue max, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
     89    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    9890      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    9991      int length = vector.Length;
     
    10294
    10395      for (int i = 0; i < length; i++) {
     96        double min = bounds[i % bounds.Rows, 0];
     97        double max = bounds[i % bounds.Rows, 1];
    10498        if (random.NextDouble() < 0.5) {
    105           vector[i] = vector[i] + (max.Value - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob));
     99          vector[i] = vector[i] + (max - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob));
    106100        } else {
    107           vector[i] = vector[i] - (vector[i] - min.Value) * (1 - Math.Pow(random.NextDouble(), prob));
     101          vector[i] = vector[i] - (vector[i] - min) * (1 - Math.Pow(random.NextDouble(), prob));
    108102        }
    109103      }
     
    116110    /// <param name="realVector">The real vector that should be manipulated.</param>
    117111    protected override void Manipulate(IRandom random, RealVector realVector) {
    118       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
    119       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
     112      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    120113      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
    121114      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
    122115      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
    123       Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
     116      Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
    124117    }
    125118  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs

    r3060 r3123  
    3838  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {
    3939    /// <summary>
    40     /// The lower bound of the values in the real vector.
     40    /// 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.
    4141    /// </summary>
    42     public ValueLookupParameter<DoubleValue> MinimumParameter {
    43       get { return (ValueLookupParameter<DoubleValue>)Parameters["Minimum"]; }
    44     }
    45     /// <summary>
    46     /// The upper bound of the values in the real vector.
    47     /// </summary>
    48     public ValueLookupParameter<DoubleValue> MaximumParameter {
    49       get { return (ValueLookupParameter<DoubleValue>)Parameters["Maximum"]; }
     42    public ValueLookupParameter<DoubleMatrix> BoundsParameter {
     43      get { return (ValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5044    }
    5145    /// <summary>
     
    6963
    7064    /// <summary>
    71     /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with five
    72     /// parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
     65    /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four
     66    /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
    7367    /// and <c>GenerationDependency</c>).
    7468    /// </summary>
    7569    public MichalewiczNonUniformOnePositionManipulator()
    7670      : base() {
    77       Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "Minimum of the sampling range for the vector element (included)"));
    78       Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
     71      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("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."));
    7972      Parameters.Add(new LookupParameter<IntValue>("Generation", "Current generation of the algorithm"));
    8073      Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));
     
    8982    /// <param name="random">The random number generator.</param>
    9083    /// <param name="vector">The real vector to manipulate.</param>
    91     /// <param name="min">The minimum value of the sampling range for the vector element (inclusive).</param>
    92     /// <param name="max">The maximum value of the sampling range for the vector element (exclusive).</param>
     84    /// <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>
    9385    /// <param name="currentGeneration">The current generation of the algorithm.</param>
    9486    /// <param name="maximumGenerations">Maximum number of generations.</param>
    9587    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
    9688    /// <returns>The manipulated real vector.</returns>
    97     public static void Apply(IRandom random, RealVector vector, DoubleValue min, DoubleValue max, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
     89    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    9890      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    9991      int length = vector.Length;
     
    10294      double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value)));
    10395
     96      double min = bounds[index % bounds.Rows, 0];
     97      double max = bounds[index % bounds.Rows, 1];
     98
    10499      if (random.NextDouble() < 0.5) {
    105         vector[index] = vector[index] + (max.Value - vector[index]) * prob;
     100        vector[index] = vector[index] + (max - vector[index]) * prob;
    106101      } else {
    107         vector[index] = vector[index] - (vector[index] - min.Value) * prob;
     102        vector[index] = vector[index] - (vector[index] - min) * prob;
    108103      }
    109104    }
     
    115110    /// <param name="realVector">The real vector that should be manipulated.</param>
    116111    protected override void Manipulate(IRandom random, RealVector realVector) {
    117       if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
    118       if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
     112      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    119113      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
    120114      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
    121115      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
    122       Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
     116      Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
    123117    }
    124118  }
  • 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  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVector.cs

    r3054 r3123  
    5656      }
    5757    }
     58
     59    public virtual void Randomize(IRandom random, int startIndex, int length, DoubleMatrix bounds) {
     60      if (length > 0) {
     61        for (int i = startIndex; i < startIndex + length; i++) {
     62          double min = bounds[i % bounds.Rows, 0];
     63          double max = bounds[i % bounds.Rows, 1];
     64          array[i] = min + (max - min) * random.NextDouble();
     65        }
     66        OnReset();
     67      }
     68    }
     69
    5870    public void Randomize(IRandom random, double min, double max) {
    5971      Randomize(random, 0, Length, min, max);
    6072    }
     73
     74    public void Randomize(IRandom random, DoubleMatrix bounds) {
     75      Randomize(random, 0, Length, bounds);
     76    }
     77
    6178  }
    6279}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorCreator.cs

    r3060 r3123  
    4747      get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; }
    4848    }
    49     public IValueLookupParameter<DoubleValue> MinimumParameter {
    50       get { return (IValueLookupParameter<DoubleValue>)Parameters["Minimum"]; }
    51     }
    52     public IValueLookupParameter<DoubleValue> MaximumParameter {
    53       get { return (IValueLookupParameter<DoubleValue>)Parameters["Maximum"]; }
     49    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
     50      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5451    }
    5552
     
    5956      Parameters.Add(new LookupParameter<RealVector>("RealVector", "The vector which should be manipulated."));
    6057      Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector."));
    61       Parameters.Add(new ValueLookupParameter<DoubleValue>("Minimum", "The lower bound for each element in the vector."));
    62       Parameters.Add(new ValueLookupParameter<DoubleValue>("Maximum", "The upper bound for each element in the vector."));
     58      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "A 2 column matrix specifying the lower and upper bound for each dimension. If there are less rows than dimension the bounds vector is cycled."));
    6359    }
    6460
    6561    public sealed override IOperation Apply() {
    66       RealVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, MinimumParameter.ActualValue, MaximumParameter.ActualValue);
     62      RealVectorParameter.ActualValue = Create(RandomParameter.ActualValue, LengthParameter.ActualValue, BoundsParameter.ActualValue);
    6763      return base.Apply();
    6864    }
    6965
    70     protected abstract RealVector Create(IRandom random, IntValue length, DoubleValue minimum, DoubleValue maximum);
     66    protected abstract RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds);
    7167  }
    7268}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/MichalewiczNonUniformAllPositionsManipulatorTest.cs

    r3061 r3123  
    8686      TestRandom random = new TestRandom();
    8787      RealVector parent, expected;
    88       DoubleValue min, max, generationsDependency;
     88      DoubleValue generationsDependency;
     89      DoubleMatrix bounds;
    8990      IntValue currentGeneration, maximumGenerations;
    9091      bool exceptionFired;
     
    9495      parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
    9596      expected = new RealVector(new double[] { 0.45, 0.22, 0.3, 0.6, 0.14 });
    96       min = new DoubleValue(0.3);
    97       max = new DoubleValue(0.7);
     97      bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
    9898      generationsDependency = new DoubleValue(0.1);
    9999      currentGeneration = new IntValue(1);
    100100      maximumGenerations = new IntValue(4);
    101       MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, min, max, currentGeneration, maximumGenerations, generationsDependency);
     101      MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
    102102      Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
    103103      // The following test is not based on published examples
     
    106106      random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 };
    107107      parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
    108       min = new DoubleValue(0.3);
    109       max = new DoubleValue(0.7);
     108      bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
    110109      generationsDependency = new DoubleValue(0.1);
    111110      currentGeneration = new IntValue(5); //current generation > max generation
    112111      maximumGenerations = new IntValue(4);
    113112      try {
    114         MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, min, max, currentGeneration, maximumGenerations, generationsDependency);
     113        MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
    115114      }
    116115      catch (System.ArgumentException) {
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/MichalewiczNonUniformOnePositionManipulatorTest.cs

    r3061 r3123  
    8686      TestRandom random = new TestRandom();
    8787      RealVector parent, expected;
    88       DoubleValue min, max, generationsDependency;
     88      DoubleValue generationsDependency;
     89      DoubleMatrix bounds;
    8990      IntValue currentGeneration, maximumGenerations;
    9091      bool exceptionFired;
     
    9596      parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
    9697      expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.34, 0.1 });
    97       min = new DoubleValue(0.3);
    98       max = new DoubleValue(0.7);
     98      bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
    9999      generationsDependency = new DoubleValue(0.1);
    100100      currentGeneration = new IntValue(1);
    101101      maximumGenerations = new IntValue(4);
    102       MichalewiczNonUniformOnePositionManipulator.Apply(random, parent, min, max, currentGeneration, maximumGenerations, generationsDependency);
     102      MichalewiczNonUniformOnePositionManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
    103103      Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
    104104      // The following test is not based on published examples
     
    108108      random.DoubleNumbers = new double[] { 0.2, 0.7 };
    109109      parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
    110       min = new DoubleValue(0.3);
    111       max = new DoubleValue(0.7);
     110      bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
    112111      generationsDependency = new DoubleValue(0.1);
    113112      currentGeneration = new IntValue(5); //current generation > max generation
    114113      maximumGenerations = new IntValue(4);
    115114      try {
    116         MichalewiczNonUniformOnePositionManipulator.Apply(random, parent, min, max, currentGeneration, maximumGenerations, generationsDependency);
     115        MichalewiczNonUniformOnePositionManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
    117116      }
    118117      catch (System.ArgumentException) {
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/UniformOnePositionManipulatorTest.cs

    r3061 r3123  
    8686      TestRandom random = new TestRandom();
    8787      RealVector parent, expected;
    88       DoubleValue min, max;
     88      DoubleMatrix bounds;
    8989      // The following test is not based on published examples
    9090      random.Reset();
     
    9393      parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
    9494      expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.3, 0.1 });
    95       min = new DoubleValue(0.2);
    96       max = new DoubleValue(0.7);
    97       UniformOnePositionManipulator.Apply(random, parent, min, max);
     95      bounds = new DoubleMatrix(new double[,] { { 0.2, 0.7 } });
     96      UniformOnePositionManipulator.Apply(random, parent, bounds);
    9897      Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
    9998    }
Note: See TracChangeset for help on using the changeset viewer.