#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 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 System.Collections.Generic;
using System.Text;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Random;
namespace HeuristicLab.ES {
///
/// Mutates the endogenous strategy parameters.
///
public class SelfAdaptiveMutationStrengthAdjuster : OperatorBase {
///
public override string Description {
get { return @"Mutates the endogenous strategy parameters"; }
}
///
/// Initializes a new instance of with four
/// variable infos (Random, StrategyVector, GeneralLearningRate and
/// LearningRate).
///
public SelfAdaptiveMutationStrengthAdjuster()
: base() {
AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
AddVariableInfo(new VariableInfo("StrategyVector", "Vector containing the endogenous strategy parameters", typeof(DoubleArrayData), VariableKind.In));
AddVariableInfo(new VariableInfo("GeneralLearningRate", "The general learning rate will scale all mutations. It's influence is calculated as: e^(GeneralLearningRate*N(0,1))", typeof(DoubleData), VariableKind.In));
AddVariableInfo(new VariableInfo("LearningRate", "Learning parameter defines the strength of the adaption of each component in the object parameter vector", typeof(DoubleData), VariableKind.In));
}
///
/// Mutates the endogenous strategy parameters.
///
/// Calls of base class .
/// The current scope to mutate.
///
public override IOperation Apply(IScope scope) {
IRandom random = GetVariableValue("Random", scope, true);
double[] strategyParams = GetVariableValue("StrategyVector", scope, false).Data;
double tau = GetVariableValue("LearningRate", scope, true).Data;
double tau0 = GetVariableValue("GeneralLearningRate", scope, true).Data;
NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
double generalMultiplier = Math.Exp(tau0 * N.NextDouble());
for (int i = 0; i < strategyParams.Length; i++) {
strategyParams[i] *= generalMultiplier * Math.Exp(tau * N.NextDouble());
}
return base.Apply(scope);
}
}
}