[2920] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Parameters;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.RealVector.Manipulators {
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// Performs the polynomial manipulation on a randomly chosen single position in the real vector.
|
---|
| 31 | /// </summary>
|
---|
| 32 | /// <remarks>
|
---|
| 33 | /// 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.
|
---|
| 34 | /// </remarks>
|
---|
| 35 | [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.")]
|
---|
| 36 | [EmptyStorableClass]
|
---|
| 37 | public class PolynomialOnePositionManipulator : RealVectorManipulator {
|
---|
| 38 | /// <summary>
|
---|
| 39 | /// 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"/>.
|
---|
| 40 | /// 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).
|
---|
| 41 | /// </summary>
|
---|
| 42 | public ValueLookupParameter<DoubleData> ContiguityParameter {
|
---|
| 43 | get { return (ValueLookupParameter<DoubleData>)Parameters["Contiguity"]; }
|
---|
| 44 | }
|
---|
| 45 | /// <summary>
|
---|
| 46 | /// 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.
|
---|
| 47 | /// </summary>
|
---|
| 48 | /// <remarks>
|
---|
| 49 | /// The manipulated value is not restricted by the (possibly) specified lower and upper bounds. Use the <see cref="BoundsChecker"/> to correct the values after performing the mutation.
|
---|
| 50 | /// </remarks>
|
---|
| 51 | public ValueLookupParameter<DoubleData> MaximumManipulationParameter {
|
---|
| 52 | get { return (ValueLookupParameter<DoubleData>)Parameters["MaximumManipulation"]; }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /// <summary>
|
---|
| 56 | /// Initializes a new instance of <see cref="PolynomialOnePositionManipulator"/> with two parameters
|
---|
| 57 | /// (<c>Contiguity</c> and <c>MaximumManipulation</c>).
|
---|
| 58 | /// </summary>
|
---|
| 59 | public PolynomialOnePositionManipulator()
|
---|
| 60 | : base() {
|
---|
| 61 | Parameters.Add(new ValueLookupParameter<DoubleData>("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 DoubleData(2)));
|
---|
| 62 | Parameters.Add(new ValueLookupParameter<DoubleData>("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 DoubleData(1)));
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /// <summary>
|
---|
| 66 | /// Performs the polynomial mutation on a single position in the real vector.
|
---|
| 67 | /// </summary>
|
---|
| 68 | /// <param name="random">The random number generator to use.</param>
|
---|
| 69 | /// <param name="vector">The vector that should be manipulated.</param>
|
---|
| 70 | /// <param name="contiguity">A parameter describing the shape of the probability density function which influences the strength of the manipulation.</param>
|
---|
| 71 | /// <param name="maxManipulation">The maximum strength of the manipulation.</param>
|
---|
| 72 | public static void Apply(IRandom random, DoubleArrayData vector, DoubleData contiguity, DoubleData maxManipulation) {
|
---|
| 73 | if (contiguity.Value < 0) throw new ArgumentException("PolynomialOnePositionManipulator: Contiguity value is smaller than 0", "contiguity");
|
---|
| 74 | int index = random.Next(vector.Length);
|
---|
| 75 | double u = random.NextDouble(), delta = 0;
|
---|
| 76 |
|
---|
| 77 | if (u < 0.5) {
|
---|
| 78 | delta = Math.Pow(2 * u, 1.0 / (contiguity.Value + 1)) - 1.0;
|
---|
| 79 | } else if (u > 0.5) {
|
---|
| 80 | delta = 1.0 - Math.Pow(2.0 - 2.0 * u, 1.0 / contiguity.Value + 1);
|
---|
| 81 | } else if (u == 0.5) delta = 0;
|
---|
| 82 |
|
---|
| 83 | vector[index] += delta * maxManipulation.Value;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /// <summary>
|
---|
| 87 | /// Checks the availability of the parameters and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData)"/>.
|
---|
| 88 | /// </summary>
|
---|
| 89 | /// <param name="random">The random number generator to use.</param>
|
---|
| 90 | /// <param name="realVector">The vector of real values to manipulate.</param>
|
---|
| 91 | protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
|
---|
| 92 | if (ContiguityParameter.ActualValue == null) throw new InvalidOperationException("PolynomialOnePositionManipulator: Parameter " + ContiguityParameter.ActualName + " could not be found.");
|
---|
| 93 | if (MaximumManipulationParameter.ActualValue == null) throw new InvalidOperationException("PolynomialOnePositionManipulator: Parameter " + MaximumManipulationParameter.ActualName + " could not be found.");
|
---|
| 94 | Apply(random, realVector, ContiguityParameter.ActualValue, MaximumManipulationParameter.ActualValue);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|