Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/10 15:59:37 (14 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/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  }
Note: See TracChangeset for help on using the changeset viewer.