Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/NormalAllPositionsManipulator.cs @ 4068

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

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.7 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.Optimization;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Random;
28
29namespace HeuristicLab.Encodings.RealVectorEncoding {
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("NormalAllPositionsManipulator", "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, if there are less elements in the strategy vector than positions, then the strategy vector is cycled. 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  [StorableClass]
40  public class NormalAllPositionsManipulator : RealVectorManipulator, ISelfAdaptiveManipulator {
41    public Type StrategyParameterType {
42      get { return typeof(IRealVectorStdDevStrategyParameterOperator); }
43    }
44    /// <summary>
45    /// Parameter for the strategy vector.
46    /// </summary>
47    public IValueLookupParameter<RealVector> StrategyParameterParameter {
48      get { return (IValueLookupParameter<RealVector>)Parameters["StrategyParameter"]; }
49    }
50
51    IParameter ISelfAdaptiveManipulator.StrategyParameterParameter {
52      get { return StrategyParameterParameter; }
53    }
54    /// <summary>
55    /// Initializes a new instance of <see cref="NormalAllPositionsManipulator"/> with one
56    /// parameter (<c>StrategyVector</c>).
57    /// </summary>
58    public NormalAllPositionsManipulator()
59      : base() {
60      Parameters.Add(new ValueLookupParameter<RealVector>("StrategyParameter", "The vector containing the endogenous strategy parameters."));
61    }
62
63    /// <summary>
64    /// Performs an adaptive normally distributed all position manipulation on the given
65    /// <paramref name="vector"/>.
66    /// </summary>
67    /// <exception cref="InvalidOperationException">Thrown when the strategy vector is not
68    /// as long as the vector to get manipulated.</exception>
69    /// <param name="strategyParameters">The strategy vector determining the strength of the mutation.</param>
70    /// <param name="random">A random number generator.</param>
71    /// <param name="vector">The real vector to manipulate.</param>
72    /// <returns>The manipulated real vector.</returns>
73    public static void Apply(IRandom random, RealVector vector, RealVector strategyParameters) {
74      NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
75      if (strategyParameters != null && strategyParameters.Length > 0) {
76        for (int i = 0; i < vector.Length; i++) {
77          vector[i] = vector[i] + (N.NextDouble() * strategyParameters[i % strategyParameters.Length]);
78        }
79      } else {
80        for (int i = 0; i < vector.Length; i++) {
81          vector[i] = vector[i] + N.NextDouble();
82        }
83      }
84    }
85
86    /// <summary>
87    /// Checks that the strategy vector is not null and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector)"/>.
88    /// </summary>
89    /// <param name="random">The random number generator.</param>
90    /// <param name="realVector">The vector of real values that is manipulated.</param>
91    protected override void Manipulate(IRandom random, RealVector realVector) {
92      Apply(random, realVector, StrategyParameterParameter.ActualValue);
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.