Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/SelfAdaptiveNormalAllPositionsManipulator.cs @ 2969

Last change on this file since 2969 was 2969, checked in by abeham, 14 years ago

Updated operators for real vector encoding #890

File size: 4.4 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.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Random;
28
29namespace HeuristicLab.Encodings.RealVector {
30  /// <summary>
31  /// Manipulates each dimension in the real vector with the mutation strength given
32  /// in the strategy parameter vector.
33  /// </summary>
34  /// <remarks>
35  /// It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.<br/>
36  /// The strategy vector can be of smaller length than the solution vector, in which case values are taken from the beginning again once the end of the strategy vector is reached.
37  /// </remarks>
38  [Item("SelfAdaptiveNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N(0,1) to the current value in each position i. The values for sigma_i are taken from the strategy vector. It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.")]
39  [EmptyStorableClass]
40  public class SelfAdaptiveNormalAllPositionsManipulator : RealVectorManipulator {
41    /// <summary>
42    /// Parameter for the strategy vector.
43    /// </summary>
44    public LookupParameter<DoubleArrayData> StrategyVectorParameter {
45      get { return (LookupParameter<DoubleArrayData>)Parameters["StrategyVector"]; }
46    }
47    /// <summary>
48    /// Initializes a new instance of <see cref="SelfAdaptiveNormalAllPositionsManipulator"/> with one
49    /// parameter (<c>StrategyVector</c>).
50    /// </summary>
51    public SelfAdaptiveNormalAllPositionsManipulator()
52      : base() {
53      Parameters.Add(new LookupParameter<DoubleArrayData>("StrategyVector", "The vector containing the endogenous strategy parameters."));
54    }
55
56    /// <summary>
57    /// Performs an adaptive normally distributed all position manipulation on the given
58    /// <paramref name="vector"/>.
59    /// </summary>
60    /// <exception cref="InvalidOperationException">Thrown when the strategy vector is not
61    /// as long as the vector to get manipulated.</exception>
62    /// <param name="strategyParameters">The strategy vector determining the strength of the mutation.</param>
63    /// <param name="random">A random number generator.</param>
64    /// <param name="vector">The real vector to manipulate.</param>
65    /// <returns>The manipulated real vector.</returns>
66    public static void Apply(IRandom random, DoubleArrayData vector, DoubleArrayData strategyParameters) {
67      NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
68      for (int i = 0; i < vector.Length; i++) {
69        vector[i] = vector[i] + (N.NextDouble() * strategyParameters[i % strategyParameters.Length]);
70      }
71    }
72
73    /// <summary>
74    /// Checks that the strategy vector is not null and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData)"/>.
75    /// </summary>
76    /// <param name="random">The random number generator.</param>
77    /// <param name="realVector">The vector of real values that is manipulated.</param>
78    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
79      if (StrategyVectorParameter.ActualValue == null) throw new InvalidOperationException("SelfAdaptiveNormalAllPositionsManipulator: Parameter " + StrategyVectorParameter.ActualName + " could not be found.");
80      Apply(random, realVector, StrategyVectorParameter.ActualValue);
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.