#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Core; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Random; namespace HeuristicLab.Encodings.RealVectorEncoding { /// /// Manipulates each dimension in the real vector with the mutation strength given /// in the strategy parameter 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.
/// 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. ///
[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.")] [StorableClass] public class NormalAllPositionsManipulator : RealVectorManipulator, ISelfAdaptiveManipulator { public Type StrategyParameterType { get { return typeof(IRealVectorStdDevStrategyParameterOperator); } } /// /// Parameter for the strategy vector. /// public IValueLookupParameter StrategyParameterParameter { get { return (IValueLookupParameter)Parameters["StrategyParameter"]; } } IParameter ISelfAdaptiveManipulator.StrategyParameterParameter { get { return StrategyParameterParameter; } } /// /// Initializes a new instance of with one /// parameter (StrategyVector). /// public NormalAllPositionsManipulator() : base() { Parameters.Add(new ValueLookupParameter("StrategyParameter", "The vector containing the endogenous strategy parameters.")); } /// /// Performs an adaptive normally distributed all position manipulation on the given /// . /// /// Thrown when the strategy vector is not /// as long as the vector to get manipulated. /// The strategy vector determining the strength of the mutation. /// A random number generator. /// The real vector to manipulate. /// The manipulated real vector. public static void Apply(IRandom random, RealVector vector, RealVector strategyParameters) { NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0); if (strategyParameters != null && strategyParameters.Length > 0) { for (int i = 0; i < vector.Length; i++) { vector[i] = vector[i] + (N.NextDouble() * strategyParameters[i % strategyParameters.Length]); } } else { for (int i = 0; i < vector.Length; i++) { vector[i] = vector[i] + N.NextDouble(); } } } /// /// Checks that the strategy vector is not null and forwards the call to . /// /// The random number generator. /// The vector of real values that is manipulated. protected override void Manipulate(IRandom random, RealVector realVector) { Apply(random, realVector, StrategyParameterParameter.ActualValue); } } }