Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/10/10 17:19:34 (15 years ago)
Author:
abeham
Message:

#893

  • Fixed wiring of iteration based operators like the michalewicz manipulators for real vector encoding
Location:
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators
Files:
2 edited

Legend:

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

    r3677 r3750  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3738  [Item("MichalewiczNonUniformAllPositionsManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
    3839  [StorableClass]
    39   public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {
     40  public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator, IIterationBasedOperator {
    4041    /// <summary>
    41     /// The current generation.
     42    /// The current iteration.
    4243    /// </summary>
    43     public LookupParameter<IntValue> GenerationParameter {
    44       get { return (LookupParameter<IntValue>)Parameters["Generations"]; }
     44    public ILookupParameter<IntValue> IterationsParameter {
     45      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
    4546    }
    4647    /// <summary>
    47     /// The maximum generation.
     48    /// The maximum iteration.
    4849    /// </summary>
    49     public LookupParameter<IntValue> MaximumGenerationsParameter {
    50       get { return (LookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
     50    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     51      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    5152    }
    5253    /// <summary>
    53     /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.
     54    /// The parameter describing how much the mutation should depend on the progress towards the maximum iteration.
    5455    /// </summary>
    55     public ValueLookupParameter<DoubleValue> GenerationDependencyParameter {
    56       get { return (ValueLookupParameter<DoubleValue>)Parameters["GenerationDependency"]; }
     56    public ValueLookupParameter<DoubleValue> IterationDependencyParameter {
     57      get { return (ValueLookupParameter<DoubleValue>)Parameters["IterationDependency"]; }
    5758    }
    5859
    5960    /// <summary>
    60     /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with
    61     /// four parameters (<c>Bounds</c>, <c>CurrentGeneration</c>,
    62     /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>).
     61    /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with three
     62    /// parameters (<c>Iterations</c>, <c>MaximumIterations</c> and <c>IterationDependency</c>).
    6363    /// </summary>
    6464    public MichalewiczNonUniformAllPositionsManipulator()
    6565      : base() {
    66       Parameters.Add(new LookupParameter<IntValue>("Generations", "Current generation of the algorithm"));
    67       Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));
    68       Parameters.Add(new ValueLookupParameter<DoubleValue>("GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));
     66      Parameters.Add(new LookupParameter<IntValue>("Iterations", "Current iteration of the algorithm"));
     67      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Maximum number of iterations"));
     68      Parameters.Add(new ValueLookupParameter<DoubleValue>("IterationDependency", "Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));
    6969    }
    7070
    7171    /// <summary>
    72     /// Performs a non uniformly distributed all position manipulation on the given
    73     /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
     72    /// Performs a non uniformly distributed all positions manipulation on the given
     73    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>.
    7474    /// </summary>
    75     /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
     75    /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception>
    7676    /// <param name="random">The random number generator.</param>
    7777    /// <param name="vector">The real vector to manipulate.</param>
    7878    /// <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>
    79     /// <param name="currentGeneration">The current generation of the algorithm.</param>
    80     /// <param name="maximumGenerations">Maximum number of generations.</param>
    81     /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>
     79    /// <param name="currentIteration">The current iteration of the algorithm.</param>
     80    /// <param name="maximumIterations">Maximum number of iterations.</param>
     81    /// <param name="iterationDependency">Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>
    8282    /// <returns>The manipulated real vector.</returns>
    83     public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    84       if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    85       if (generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0.");
     83    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentIteration, IntValue maximumIterations, DoubleValue iterationDependency) {
     84      if (currentIteration.Value > maximumIterations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionsManipulator: CurrentIteration must be smaller or equal than MaximumIterations", "currentIteration");
     85      if (iterationDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformAllPositionsManipulator: iterationDependency must be >= 0.", "iterationDependency");
    8686      int length = vector.Length;
    8787
    88       double prob = Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value);
     88      double prob = Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value);
    8989
    9090      for (int i = 0; i < length; i++) {
     
    106106    protected override void Manipulate(IRandom random, RealVector realVector) {
    107107      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    108       if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
    109       if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
    110       if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
    111       Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
     108      if (IterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + IterationsParameter.ActualName + " could not be found.");
     109      if (MaximumIterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumIterationsParameter.ActualName + " could not be found.");
     110      if (IterationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + IterationDependencyParameter.ActualName + " could not be found.");
     111      Apply(random, realVector, BoundsParameter.ActualValue, IterationsParameter.ActualValue, MaximumIterationsParameter.ActualValue, IterationDependencyParameter.ActualValue);
    112112    }
    113113  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs

    r3677 r3750  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3738  [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")]
    3839  [StorableClass]
    39   public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {
     40  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator, IIterationBasedOperator {
    4041    /// <summary>
    41     /// The current generation.
     42    /// The current iteration.
    4243    /// </summary>
    43     public LookupParameter<IntValue> GenerationParameter {
    44       get { return (LookupParameter<IntValue>)Parameters["Generations"]; }
     44    public ILookupParameter<IntValue> IterationsParameter {
     45      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
    4546    }
    4647    /// <summary>
    47     /// The maximum generation.
     48    /// The maximum iteration.
    4849    /// </summary>
    49     public LookupParameter<IntValue> MaximumGenerationsParameter {
    50       get { return (LookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
     50    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     51      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    5152    }
    5253    /// <summary>
    53     /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.
     54    /// The parameter describing how much the mutation should depend on the progress towards the maximum iterations.
    5455    /// </summary>
    55     public ValueLookupParameter<DoubleValue> GenerationDependencyParameter {
    56       get { return (ValueLookupParameter<DoubleValue>)Parameters["GenerationDependency"]; }
     56    public ValueLookupParameter<DoubleValue> IterationDependencyParameter {
     57      get { return (ValueLookupParameter<DoubleValue>)Parameters["IterationDependency"]; }
    5758    }
    5859
    5960    /// <summary>
    60     /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four
    61     /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
    62     /// and <c>GenerationDependency</c>).
     61    /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with three
     62    /// parameters (<c>Iterations</c>, <c>MaximumIterations</c> and <c>IterationDependency</c>).
    6363    /// </summary>
    6464    public MichalewiczNonUniformOnePositionManipulator()
    6565      : base() {
    66       Parameters.Add(new LookupParameter<IntValue>("Generations", "Current generation of the algorithm"));
    67       Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));
    68       Parameters.Add(new ValueLookupParameter<DoubleValue>("GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));
     66      Parameters.Add(new LookupParameter<IntValue>("Iterations", "Current iteration of the algorithm."));
     67      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Maximum number of iterations."));
     68      Parameters.Add(new ValueLookupParameter<DoubleValue>("IterationDependency", "Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));
    6969    }
    7070
    7171    /// <summary>
    7272    /// Performs a non uniformly distributed one position manipulation on the given
    73     /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
     73    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>.
    7474    /// </summary>
    75     /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
     75    /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception>
    7676    /// <param name="random">The random number generator.</param>
    7777    /// <param name="vector">The real vector to manipulate.</param>
    7878    /// <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>
    79     /// <param name="currentGeneration">The current generation of the algorithm.</param>
    80     /// <param name="maximumGenerations">Maximum number of generations.</param>
    81     /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>
     79    /// <param name="currentIteration">The current iteration of the algorithm.</param>
     80    /// <param name="maximumIterations">Maximum number of iterations.</param>
     81    /// <param name="iterationDependency">Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>
    8282    /// <returns>The manipulated real vector.</returns>
    83     public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    84       if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    85       if (generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0.");
     83    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentIteration, IntValue maximumIterations, DoubleValue iterationDependency) {
     84      if (currentIteration.Value > maximumIterations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentIteration must be smaller or equal than MaximumIterations", "currentIteration");
     85      if (iterationDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: iterationDependency must be >= 0.", "iterationDependency");
    8686      int length = vector.Length;
    8787      int index = random.Next(length);
    8888
    89       double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value)));
     89      double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value)));
    9090
    9191      double min = bounds[index % bounds.Rows, 0];
     
    106106    protected override void Manipulate(IRandom random, RealVector realVector) {
    107107      if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found.");
    108       if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
    109       if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
    110       if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
    111       Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
     108      if (IterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationsParameter.ActualName + " could not be found.");
     109      if (MaximumIterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumIterationsParameter.ActualName + " could not be found.");
     110      if (IterationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationDependencyParameter.ActualName + " could not be found.");
     111      Apply(random, realVector, BoundsParameter.ActualValue, IterationsParameter.ActualValue, MaximumIterationsParameter.ActualValue, IterationDependencyParameter.ActualValue);
    112112    }
    113113  }
Note: See TracChangeset for help on using the changeset viewer.