Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/10 16:48:24 (15 years ago)
Author:
abeham
Message:

checked and corrected (where necessary) BLX-a, BLX-a-b, as well the SinglePointCrossover
checked the UniformOnePositionManipulator
fixed a copy-paste oversight in RealVectorManipulator
#890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/BlendAlphaBetaCrossover.cs

    r2900 r2913  
    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.
     
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Parameters;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Blend alpha-beta crossover for real vectors. Creates a new offspring by selecting a
     30  /// Blend alpha-beta crossover for real vectors (BLX-a-b). Creates a new offspring by selecting a
    3131  /// random value from the interval between the two alleles of the parent solutions.
    3232  /// The interval is increased in both directions as follows: Into the direction of the 'better'
    3333  /// solution by the factor alpha, into the direction of the 'worse' solution by the factor beta.
    3434  /// </summary>
    35   [Item("BlendAlphaBetaCrossover", "FIXME: CHECK WITH LITERATURE AND VALIDATE IT.")]
     35  /// <remarks>
     36  /// It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.<br/>
     37  /// The default value for alpha is 0.75, the default value for beta is 0.25.
     38  /// </remarks>
     39  [Item("BlendAlphaBetaCrossover", "The blend alpha beta crossover (BLX-a-b) for real vectors is similar to the blend alpha crossover (BLX-a), but distinguishes between the better and worse of the parents. The interval from which to choose the new offspring can be extended more around the better parent by specifying a higher alpha value. It is implemented as described in Takahashi, M. and Kita, H. 2001. A crossover operator using independent component analysis for real-coded genetic algorithms Proceedings of the 2001 Congress on Evolutionary Computation, pp. 643-649.")]
    3640  [EmptyStorableClass]
    3741  public class BlendAlphaBetaCrossover : RealVectorCrossover {
     
    6064    }
    6165
     66    /// <summary>
     67    /// Performs the blend alpha beta crossover (BLX-a-b) on two parent vectors.
     68    /// </summary>
     69    /// <exception cref="ArgumentException">
     70    /// Thrown when either:<br/>
     71    /// <list type="bullet">
     72    /// <item><description>The length of <paramref name="betterParent"/> and <paramref name="worseParent"/> is not equal.</description></item>
     73    /// <item><description>The parameter <paramref name="alpha"/> is smaller than 0.</description></item>
     74    /// <item><description>The parameter <paramref name="beta"/> is smaller than 0.</description></item>
     75    /// </list>
     76    /// </exception>
     77    /// <param name="random">The random number generator to use.</param>
     78    /// <param name="betterParent">The better of the two parents with regard to their fitness.</param>
     79    /// <param name="worseParent">The worse of the two parents with regard to their fitness.</param>
     80    /// <param name="alpha">The parameter alpha.</param>
     81    /// <param name="beta">The parameter beta.</param>
     82    /// <returns>The real vector that results from the crossover.</returns>
    6283    public static DoubleArrayData Apply(IRandom random, DoubleArrayData betterParent, DoubleArrayData worseParent, DoubleData alpha, DoubleData beta) {
    6384      if (betterParent.Length != worseParent.Length) throw new ArgumentException("BlendAlphaBetaCrossover: The parents' vectors are of different length.", "betterParent");
     85      if (alpha.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter alpha must be greater or equal to 0.", "alpha");
     86      if (beta.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter beta must be greater or equal to 0.", "beta");
    6487      int length = betterParent.Length;
     88      double min, max, d;
    6589      DoubleArrayData result = new DoubleArrayData(length);
    6690
    6791      for (int i = 0; i < length; i++) {
    68         double interval = Math.Abs(betterParent[i] - worseParent[i]);
    69         result[i] = SelectFromInterval(random, interval, betterParent[i], worseParent[i], alpha.Value, beta.Value);
     92        d = Math.Abs(betterParent[i] - worseParent[i]);
     93        if (betterParent[i] <= worseParent[i]) {
     94          min = betterParent[i] - d * alpha.Value;
     95          max = worseParent[i] + d * beta.Value;
     96        } else {
     97          min = worseParent[i] - d * beta.Value;
     98          max = betterParent[i] + d * alpha.Value;
     99        }
     100        result[i] = min + random.NextDouble() * (max - min);
    70101      }
    71102      return result;
    72103    }
    73104
    74     private static double SelectFromInterval(IRandom random, double interval, double val1, double val2, double alpha, double beta) {
    75       double resMin = 0;
    76       double resMax = 0;
    77 
    78       if (val1 <= val2) {
    79         resMin = val1 - interval * alpha;
    80         resMax = val2 + interval * beta;
    81       } else {
    82         resMin = val2 - interval * beta;
    83         resMax = val1 + interval * alpha;
    84       }
    85 
    86       return SelectRandomFromInterval(random, resMin, resMax);
    87     }
    88 
    89     private static double SelectRandomFromInterval(IRandom random, double resMin, double resMax) {
    90       return resMin + random.NextDouble() * Math.Abs(resMax - resMin);
    91     }
    92 
     105    /// <summary>
     106    /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData, DoubleData, DoubleData)"/>.
     107    /// </summary>
     108    /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception>
     109    /// <exception cref="InvalidOperationException">
     110    /// Thrown when either:<br/>
     111    /// <list type="bullet">
     112    /// <item><description>Maximization parameter could not be found.</description></item>
     113    /// <item><description>Quality parameter could not be found or the number of quality values is not equal to the number of parents.</description></item>
     114    /// <item><description>Alpha parameter could not be found.</description></item>
     115    /// <item><description>Beta parameter could not be found.</description></item>
     116    /// </list>
     117    /// </exception>
     118    /// <param name="random">The random number generator to use.</param>
     119    /// <param name="parents">The collection of parents (must be of size 2).</param>
     120    /// <returns>The real vector that results from the crossover.</returns>
    93121    protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) {
    94       if (parents.Length != 2) throw new InvalidOperationException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.");
     122      if (parents.Length != 2) throw new ArgumentException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.", "parents");
    95123      if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
    96124      if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != parents.Length) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents.");
Note: See TracChangeset for help on using the changeset viewer.