Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/StochasticPolynomialMultiMoveGenerator.cs @ 4745

Last change on this file since 4745 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

File size: 4.3 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Encodings.RealVectorEncoding {
30  [Item("StochasticPolynomialMultiMoveGenerator", "Generates polynomial moves from a given real vector.")]
31  [StorableClass]
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
50    [StorableConstructor]
51    protected StochasticPolynomialMultiMoveGenerator(bool deserializing) : base(deserializing) { }
52    protected StochasticPolynomialMultiMoveGenerator(StochasticPolynomialMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
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
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new StochasticPolynomialMultiMoveGenerator(this, cloner);
62    }
63
64    public static AdditiveMove[] Apply(IRandom random, RealVector realVector, double contiguity, int sampleSize, double maxManipulation) {
65      AdditiveMove[] moves = new AdditiveMove[sampleSize];
66      for (int i = 0; i < sampleSize; i++) {
67        int index = random.Next(realVector.Length);
68        moves[i] = new AdditiveMove(index, PolynomialOnePositionManipulator.Apply(random, contiguity) * maxManipulation);
69      }
70      return moves;
71    }
72
73    protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector) {
74      return Apply(random, realVector, ContiguityParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, MaximumManipulationParameter.ActualValue.Value);
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.