[13368] | 1 | #region License Information
|
---|
[3187] | 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3187] | 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 |
|
---|
[4722] | 22 | using HeuristicLab.Common;
|
---|
[3187] | 23 | using HeuristicLab.Core;
|
---|
[4068] | 24 | using HeuristicLab.Data;
|
---|
[3187] | 25 | using HeuristicLab.Optimization;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[4068] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3187] | 28 |
|
---|
| 29 | namespace HeuristicLab.Encodings.RealVectorEncoding {
|
---|
| 30 | [Item("StochasticPolynomialMultiMoveGenerator", "Generates polynomial moves from a given real vector.")]
|
---|
[13368] | 31 | [StorableClass("E3794FEB-061E-4031-AB82-7AC9B675BCAB")]
|
---|
[3187] | 32 | public class StochasticPolynomialMultiMoveGenerator : AdditiveMoveGenerator, IMultiMoveGenerator {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// 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.
|
---|
| 35 | /// </summary>
|
---|
| 36 | public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
|
---|
| 37 | get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumManipulation"]; }
|
---|
| 38 | }
|
---|
| 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>
|
---|
| 43 | public IValueLookupParameter<DoubleValue> ContiguityParameter {
|
---|
| 44 | get { return (IValueLookupParameter<DoubleValue>)Parameters["Contiguity"]; }
|
---|
| 45 | }
|
---|
| 46 | public IValueLookupParameter<IntValue> SampleSizeParameter {
|
---|
| 47 | get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[4722] | 50 | [StorableConstructor]
|
---|
| 51 | protected StochasticPolynomialMultiMoveGenerator(bool deserializing) : base(deserializing) { }
|
---|
| 52 | protected StochasticPolynomialMultiMoveGenerator(StochasticPolynomialMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
|
---|
[3187] | 53 | public StochasticPolynomialMultiMoveGenerator()
|
---|
| 54 | : base() {
|
---|
| 55 | 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)));
|
---|
| 56 | Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves that should be generated."));
|
---|
| 57 | 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)));
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[4722] | 60 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 61 | return new StochasticPolynomialMultiMoveGenerator(this, cloner);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[5381] | 64 | public static AdditiveMove[] Apply(IRandom random, RealVector vector, double contiguity, int sampleSize, double maxManipulation, DoubleMatrix bounds) {
|
---|
[3187] | 65 | AdditiveMove[] moves = new AdditiveMove[sampleSize];
|
---|
| 66 | for (int i = 0; i < sampleSize; i++) {
|
---|
[5381] | 67 | int index = random.Next(vector.Length);
|
---|
| 68 | double strength = 0, min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1];
|
---|
| 69 | do {
|
---|
| 70 | strength = PolynomialOnePositionManipulator.Apply(random, contiguity) * maxManipulation;
|
---|
| 71 | } while (vector[index] + strength < min || vector[index] + strength > max);
|
---|
| 72 | moves[i] = new AdditiveMove(index, strength);
|
---|
[3187] | 73 | }
|
---|
| 74 | return moves;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[5381] | 77 | protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector, DoubleMatrix bounds) {
|
---|
| 78 | return Apply(random, realVector, ContiguityParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, MaximumManipulationParameter.ActualValue.Value, bounds);
|
---|
[3187] | 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|