Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2915


Ignore:
Timestamp:
03/02/10 19:05:10 (14 years ago)
Author:
abeham
Message:

Converted Michalewicz's non-uniform mutation operators #890

Location:
trunk/sources/HeuristicLab.Encodings.RealVector/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/HeuristicLab.Encodings.RealVector-3.3.csproj

    r2914 r2915  
    9696    </Compile>
    9797    <Compile Include="HeuristicLabEncodingsRealVectorPlugin.cs" />
     98    <Compile Include="Manipulators\MichalewiczNonUniformAllPositionsManipulator.cs">
     99      <SubType>Code</SubType>
     100    </Compile>
     101    <Compile Include="Manipulators\MichalewiczNonUniformOnePositionManipulator.cs" />
    98102    <Compile Include="Manipulators\UniformOnePositionManipulator.cs" />
    99103    <None Include="HeuristicLab.snk" />
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs

    r2900 r2915  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs <br/>
    31   /// Non-uniformly distributed change of all positions of a real vector.
     30  /// The solution is manipulated with diminishing strength over time. In addition the mutated values are not sampled over the entire domain, but additive.<br/>
     31  /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new numbers closer to the current value.
    3232  /// </summary>
    33   public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return
    37 @"Non-uniformly distributed change of all positions of a real vector (Michalewicz 1992)
    38 Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to its successor instead of a random number.
    39 
    40 Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs. Springer Verlag.";
    41       }
     33  /// <remarks>
     34  /// 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  /// </remarks>
     36  [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.")]
     37  [EmptyStorableClass]
     38  public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {
     39    public ValueLookupParameter<DoubleData> MinimumParameter {
     40      get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; }
     41    }
     42    public ValueLookupParameter<DoubleData> MaximumParameter {
     43      get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; }
     44    }
     45    public LookupParameter<IntData> GenerationParameter {
     46      get { return (LookupParameter<IntData>)Parameters["Generation"]; }
     47    }
     48    public LookupParameter<IntData> MaximumGenerationsParameter {
     49      get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; }
     50    }
     51    public ValueLookupParameter<DoubleData> GenerationDependencyParameter {
     52      get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; }
    4253    }
    4354
    4455    /// <summary>
    4556    /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with
    46     /// five variable infos (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,
    47     /// <c>MaximumGenerations</c> and <c>GenerationsDependency</c>).
     57    /// five parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,
     58    /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>).
    4859    /// </summary>
    4960    public MichalewiczNonUniformAllPositionsManipulator()
    5061      : base() {
    51       AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
    52       AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
    53       AddVariableInfo(new VariableInfo("CurrentGeneration", "Current Generation of the algorithm", typeof(IntData), VariableKind.In));
    54       AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of Generations", typeof(IntData), VariableKind.In));
    55       VariableInfo genDepInfo = new VariableInfo("GenerationsDependency", "Specifies the degree of dependency on the number of generations", typeof(IntData), VariableKind.In);
    56       genDepInfo.Local = true;
    57       AddVariableInfo(genDepInfo);
    58       AddVariable(new Variable("GenerationsDependency", new IntData(5)));
     62      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)"));
     63      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
     64      Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm"));
     65      Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations"));
     66      Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5)));
    5967    }
    6068
    6169    /// <summary>
    62     /// Performs a non uniformly distributed all position manipulation on the given
    63     /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
     70    /// Performs a non uniformly distributed all position manipulation on the given 
     71    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
    6472    /// </summary>
    65     /// <remarks>Calls <see cref="Apply"/>.</remarks>
    66     /// <param name="scope">The current scope.</param>
    67     /// <param name="random">The random number generator.</param>
    68     /// <param name="vector">The real vector to manipulate.</param>
    69     /// <returns>The manipulated real vector.</returns>
    70     protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
    71       double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
    72       double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
    73       int currentGeneration = GetVariableValue<IntData>("CurrentGeneration", scope, true).Data;
    74       int maximumGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true).Data;
    75       int generationsDependency = GetVariableValue<IntData>("GenerationsDependency", scope, true).Data;
    76       return Apply(random, vector, min, max, currentGeneration, maximumGenerations, generationsDependency);
    77     }
    78 
    79     /// <summary>
    80     /// Performs a non uniformly distributed all position manipulation on the given
    81     /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
    82     /// </summary>
     73    /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
    8374    /// <param name="random">The random number generator.</param>
    8475    /// <param name="vector">The real vector to manipulate.</param>
     
    8980    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
    9081    /// <returns>The manipulated real vector.</returns>
    91     public static double[] Apply(IRandom random, double[] vector, double min, double max, int currentGeneration, int maximumGenerations, int generationsDependency) {
     82    public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) {
     83      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    9284      int length = vector.Length;
    93       double[] result = new double[length];
     85
     86      double prob = Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value);
    9487
    9588      for (int i = 0; i < length; i++) {
    9689        if (random.NextDouble() < 0.5) {
    97           vector[i] = vector[i] + Delta(random, currentGeneration, max - vector[i], maximumGenerations, generationsDependency);
     90          vector[i] = vector[i] + (max.Value - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob));
    9891        } else {
    99           vector[i] = vector[i] - Delta(random, currentGeneration, vector[i] - min, maximumGenerations, generationsDependency);
     92          vector[i] = vector[i] - (vector[i] - min.Value) * (1 - Math.Pow(random.NextDouble(), prob));
    10093        }
    10194      }
    102       return vector;
    10395    }
    10496
    105     // returns a value between 0 and y (both included)
    106     private static double Delta(IRandom random, int currentGeneration, double y, int maximumGenerations, int generationsDependency) {
    107       return y * (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration / maximumGenerations, generationsDependency)));
     97    /// <summary>
     98    /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>.
     99    /// </summary>
     100    /// <param name="random">The random number generator.</param>
     101    /// <param name="realVector">The real vector that should be manipulated.</param>
     102    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
     103      if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
     104      if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
     105      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
     106      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
     107      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
     108      Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
    108109    }
    109110  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs

    r2900 r2915  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs<br/>
    31   /// Non-uniformly distributed change of one position of a real vector.
     30  /// The solution is manipulated with diminishing strength over time. In addition the mutated value is not sampled over the entire domain, but additive at the selected position.<br/>
     31  /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to the current value.
    3232  /// </summary>
    33   public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return
    37 @"Non-uniformly distributed change of one position of a real vector (Michalewicz 1992)
    38 Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to its successor instead of a random number.
    39 
    40 Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs. Springer Verlag.";
    41       }
     33  /// <remarks>
     34  /// 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  /// </remarks>
     36  [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.")]
     37  [EmptyStorableClass]
     38  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {
     39    public ValueLookupParameter<DoubleData> MinimumParameter {
     40      get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; }
     41    }
     42    public ValueLookupParameter<DoubleData> MaximumParameter {
     43      get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; }
     44    }
     45    public LookupParameter<IntData> GenerationParameter {
     46      get { return (LookupParameter<IntData>)Parameters["Generation"]; }
     47    }
     48    public LookupParameter<IntData> MaximumGenerationsParameter {
     49      get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; }
     50    }
     51    public ValueLookupParameter<DoubleData> GenerationDependencyParameter {
     52      get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; }
    4253    }
    4354
    4455    /// <summary>
    4556    /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with five
    46     /// variable infos (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
    47     /// and <c>GenerationsDependency</c>).
     57    /// parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>
     58    /// and <c>GenerationDependency</c>).
    4859    /// </summary>
    4960    public MichalewiczNonUniformOnePositionManipulator()
    5061      : base() {
    51       AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
    52       AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
    53       AddVariableInfo(new VariableInfo("CurrentGeneration", "Current Generation of the algorithm", typeof(IntData), VariableKind.In));
    54       AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of Generations", typeof(IntData), VariableKind.In));
    55       VariableInfo genDepInfo = new VariableInfo("GenerationsDependency", "Specifies the degree of dependency on the number of generations", typeof(IntData), VariableKind.In);
    56       genDepInfo.Local = true;
    57       AddVariableInfo(genDepInfo);
    58       AddVariable(new Variable("GenerationsDependency", new IntData(5)));
     62      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)"));
     63      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)"));
     64      Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm"));
     65      Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations"));
     66      Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5)));
    5967    }
    6068
    6169    /// <summary>
    6270    /// Performs a non uniformly distributed one position manipulation on the given
    63     /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
     71    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
    6472    /// </summary>
    65     /// <remarks>Calls <see cref="Apply"/>.</remarks>
    66     /// <param name="scope">The current scope.</param>
    67     /// <param name="random">The random number generator.</param>
    68     /// <param name="vector">The real vector to manipulate.</param>
    69     /// <returns>The manipulated real vector.</returns>
    70     protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
    71       double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
    72       double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
    73       int currentGeneration = GetVariableValue<IntData>("CurrentGeneration", scope, true).Data;
    74       int maximumGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true).Data;
    75       int generationsDependency = GetVariableValue<IntData>("GenerationsDependency", scope, true).Data;
    76       return Apply(random, vector, min, max, currentGeneration, maximumGenerations, generationsDependency);
    77     }
    78 
    79     /// <summary>
    80     /// Performs a non uniformly distributed one position manipulation on the given
    81     /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992.
    82     /// </summary>
     73    /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
    8374    /// <param name="random">The random number generator.</param>
    8475    /// <param name="vector">The real vector to manipulate.</param>
     
    8980    /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param>
    9081    /// <returns>The manipulated real vector.</returns>
    91     public static double[] Apply(IRandom random, double[] vector, double min, double max, int currentGeneration, int maximumGenerations, int generationsDependency) {
     82    public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) {
     83      if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");
    9284      int length = vector.Length;
    93       double[] result = new double[length];
    94       int pos = random.Next(length);
     85      int index = random.Next(length);
     86
     87      double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value)));
    9588
    9689      if (random.NextDouble() < 0.5) {
    97         vector[pos] = vector[pos] + Delta(random, currentGeneration, max - vector[pos], maximumGenerations, generationsDependency);
     90        vector[index] = vector[index] + (max.Value - vector[index]) * prob;
    9891      } else {
    99         vector[pos] = vector[pos] - Delta(random, currentGeneration, vector[pos] - min, maximumGenerations, generationsDependency);
     92        vector[index] = vector[index] - (vector[index] - min.Value) * prob;
    10093      }
    101       return vector;
    10294    }
    10395
    104     // returns a value between 0 and y (both included)
    105     private static double Delta(IRandom random, int currentGeneration, double y, int maximumGenerations, int generationsDependency) {
    106       return y * (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration / maximumGenerations, generationsDependency)));
     96    /// <summary>
     97    /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>.
     98    /// </summary>
     99    /// <param name="random">The random number generator.</param>
     100    /// <param name="realVector">The real vector that should be manipulated.</param>
     101    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
     102      if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
     103      if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found.");
     104      if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");
     105      if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");
     106      if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");
     107      Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);
    107108    }
    108109  }
Note: See TracChangeset for help on using the changeset viewer.