Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/PolynomialOnePositionManipulator.cs @ 15785

Last change on this file since 15785 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 6.4 KB
RevLine 
[2920]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2920]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
[4722]23using HeuristicLab.Common;
[2920]24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
[3053]29namespace HeuristicLab.Encodings.RealVectorEncoding {
[2920]30  /// <summary>
31  /// Performs the polynomial manipulation on a randomly chosen single position in the real vector.
32  /// </summary>
33  /// <remarks>
34  /// It is implemented as described in Deb, K. & Goyal, M. A. 1996. Combined Genetic Adaptive Search (GeneAS) for Engineering Design Computer Science and Informatics, 26, pp. 30-45.
35  /// </remarks>
36  [Item("PolynomialOnePositionManipulator", "The polynomial manipulation is implemented as described in Deb, K. & Goyal, M. A. 1996. Combined Genetic Adaptive Search (GeneAS) for Engineering Design Computer Science and Informatics, 26, pp. 30-45. In this operator it is performed on a single randomly chosen position of the real vector.")]
[3017]37  [StorableClass]
[2920]38  public class PolynomialOnePositionManipulator : RealVectorManipulator {
39    /// <summary>
40    /// The contiguity parameter specifies the shape of the probability density function that controls the mutation. Setting it to 0 is similar to a uniform distribution over the entire manipulation range (specified by <see cref="MaximumManipulationParameter"/>.
41    /// A higher value will shape the density function such that values closer to 0 (little manipulation) are more likely than values closer to 1 or -1 (maximum manipulation).
42    /// </summary>
[3048]43    public ValueLookupParameter<DoubleValue> ContiguityParameter {
44      get { return (ValueLookupParameter<DoubleValue>)Parameters["Contiguity"]; }
[2920]45    }
46    /// <summary>
47    /// The maximum manipulation parameter specifies the range of the manipulation. The value specified here is the highest value the mutation will ever add to the current value.
48    /// </summary>
49    /// <remarks>
[3187]50    /// If there are bounds specified the manipulated value is restricted by the given lower and upper bounds.
[2920]51    /// </remarks>
[3048]52    public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
53      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumManipulation"]; }
[2920]54    }
55
[4722]56    [StorableConstructor]
57    protected PolynomialOnePositionManipulator(bool deserializing) : base(deserializing) { }
58    protected PolynomialOnePositionManipulator(PolynomialOnePositionManipulator original, Cloner cloner) : base(original, cloner) { }
[2920]59    /// <summary>
60    /// Initializes a new instance of <see cref="PolynomialOnePositionManipulator"/> with two parameters
61    /// (<c>Contiguity</c> and <c>MaximumManipulation</c>).
62    /// </summary>
63    public PolynomialOnePositionManipulator()
64      : base() {
[3048]65      Parameters.Add(new ValueLookupParameter<DoubleValue>("Contiguity", "Specifies whether the manipulation should produce far stretching (small value) or close (large value) manipulations with higher probability. Valid values must be greater or equal to 0.", new DoubleValue(2)));
66      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumManipulation", "Specifies the maximum value that should be added or subtracted by the manipulation. If this value is set to 0 no mutation will be performed.", new DoubleValue(1)));
[2920]67    }
68
[4722]69    public override IDeepCloneable Clone(Cloner cloner) {
70      return new PolynomialOnePositionManipulator(this, cloner);
71    }
72
[2920]73    /// <summary>
74    /// Performs the polynomial mutation on a single position in the real vector.
75    /// </summary>
76    /// <param name="random">The random number generator to use.</param>
77    /// <param name="vector">The vector that should be manipulated.</param>
78    /// <param name="contiguity">A parameter describing the shape of the probability density function which influences the strength of the manipulation.</param>
79    /// <param name="maxManipulation">The maximum strength of the manipulation.</param>
[3060]80    public static void Apply(IRandom random, RealVector vector, DoubleValue contiguity, DoubleValue maxManipulation) {
[2920]81      if (contiguity.Value < 0) throw new ArgumentException("PolynomialOnePositionManipulator: Contiguity value is smaller than 0", "contiguity");
82      int index = random.Next(vector.Length);
[3187]83      vector[index] += Apply(random, contiguity.Value) * maxManipulation.Value;
84    }
85
86    public static double Apply(IRandom random, double contiguity) {
[2920]87      double u = random.NextDouble(), delta = 0;
88
89      if (u < 0.5) {
[3187]90        delta = Math.Pow(2 * u, 1.0 / (contiguity + 1)) - 1.0;
[6506]91      } else if (u >= 0.5) {
92        delta = 1.0 - Math.Pow(2.0 - 2.0 * u, 1.0 / (contiguity + 1));
93      }
[2920]94
[3187]95      return delta;
[2920]96    }
97
98    /// <summary>
[3060]99    /// Checks the availability of the parameters and forwards the call to <see cref="Apply(IRandom, RealVector, DoubleValue, DoubleValue)"/>.
[2920]100    /// </summary>
101    /// <param name="random">The random number generator to use.</param>
102    /// <param name="realVector">The vector of real values to manipulate.</param>
[3060]103    protected override void Manipulate(IRandom random, RealVector realVector) {
[2920]104      if (ContiguityParameter.ActualValue == null) throw new InvalidOperationException("PolynomialOnePositionManipulator: Parameter " + ContiguityParameter.ActualName + " could not be found.");
105      if (MaximumManipulationParameter.ActualValue == null) throw new InvalidOperationException("PolynomialOnePositionManipulator: Parameter " + MaximumManipulationParameter.ActualName + " could not be found.");
106      Apply(random, realVector, ContiguityParameter.ActualValue, MaximumManipulationParameter.ActualValue);
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.