#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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.Common; using HeuristicLab.Core; 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("FixedNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N_i(0,1) to the current value in each position i given the values for sigma_i in the parameter. If there are less elements in Sigma than positions, then Sigma 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 FixedNormalAllPositionsManipulator : RealVectorManipulator { public IValueParameter SigmaParameter { get { return (IValueParameter)Parameters["Sigma"]; } } [StorableConstructor] protected FixedNormalAllPositionsManipulator(bool deserializing) : base(deserializing) { } protected FixedNormalAllPositionsManipulator(FixedNormalAllPositionsManipulator original, Cloner cloner) : base(original, cloner) { } /// /// Initializes a new instance of with one /// parameter (StrategyVector). /// public FixedNormalAllPositionsManipulator() : base() { Parameters.Add(new ValueParameter("Sigma", "The vector containing the standard deviations used for manipulating each dimension. If it is only of length one the same sigma will be used for every dimension.", new RealVector(new double[] { 1 }))); } public override IDeepCloneable Clone(Cloner cloner) { return new FixedNormalAllPositionsManipulator(this, cloner); } /// /// 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 sigma) { if (sigma == null || sigma.Length == 0) throw new ArgumentException("ERROR: Vector containing the standard deviations is not defined.", "sigma"); NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0); for (int i = 0; i < vector.Length; i++) { vector[i] = vector[i] + (N.NextDouble() * sigma[i % sigma.Length]); } } /// /// 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, SigmaParameter.Value); } } }