Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/StochasticPolynomialMultiMoveGenerator.cs @ 3757

Last change on this file since 3757 was 3376, checked in by swagner, 15 years ago

Moved interfaces and classes for deep cloning from HeuristicLab.Core to HeuristicLab.Common (#975).

File size: 4.0 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 System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Optimization;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Data;
30
31namespace HeuristicLab.Encodings.RealVectorEncoding {
32  [Item("StochasticPolynomialMultiMoveGenerator", "Generates polynomial moves from a given real vector.")]
33  [StorableClass]
34  public class StochasticPolynomialMultiMoveGenerator : AdditiveMoveGenerator, IMultiMoveGenerator {
35    /// <summary>
36    /// 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.
37    /// </summary>
38    public ValueLookupParameter<DoubleValue> MaximumManipulationParameter {
39      get { return (ValueLookupParameter<DoubleValue>)Parameters["MaximumManipulation"]; }
40    }
41    /// <summary>
42    /// 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"/>.
43    /// 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).
44    /// </summary>
45    public IValueLookupParameter<DoubleValue> ContiguityParameter {
46      get { return (IValueLookupParameter<DoubleValue>)Parameters["Contiguity"]; }
47    }
48    public IValueLookupParameter<IntValue> SampleSizeParameter {
49      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
50    }
51
52    public StochasticPolynomialMultiMoveGenerator()
53      : base() {
54      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)));
55      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves that should be generated."));
56      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)));
57    }
58
59    public static AdditiveMove[] Apply(IRandom random, RealVector realVector, double contiguity, int sampleSize, double maxManipulation) {
60      AdditiveMove[] moves = new AdditiveMove[sampleSize];
61      for (int i = 0; i < sampleSize; i++) {
62        int index = random.Next(realVector.Length);
63        moves[i] = new AdditiveMove(index, PolynomialOnePositionManipulator.Apply(random, contiguity) * maxManipulation);
64      }
65      return moves;
66    }
67
68    protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector) {
69      return Apply(random, realVector, ContiguityParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, MaximumManipulationParameter.ActualValue.Value);
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.