Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Evolutionary/3.3/SuccessRuleMutationStrengthAdjuster.cs @ 2211

Last change on this file since 2211 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.Evolutionary {
29  /// <summary>
30  /// Adjusts the mutation strength based on the ratio of successful offsprings.
31  /// </summary>
32  public class SuccessRuleMutationStrengthAdjuster : OperatorBase {
33    /// <inheritdoc select="summary"/>
34    public override string Description {
35      get { return @"Adjusts the mutation strength based on the ratio of successful offsprings"; }
36    }
37
38    /// <summary>
39    /// Initializes a new instance of <see cref="SuccessRuleMutationStrengthAdjuster"/> with six variable
40    /// infos (<c>ShakingFactor</c>, <c>SuccessfulChild</c>, <c>TargetSuccessProbability</c>,
41    /// <c>SuccessProbability</c>, <c>LearningRate</c> and <c>DampeningFactor</c>).
42    /// </summary>
43    public SuccessRuleMutationStrengthAdjuster() {
44      AddVariableInfo(new VariableInfo("ShakingFactor", "The mutation strength to adjust", typeof(DoubleData), VariableKind.In | VariableKind.Out));
45      AddVariableInfo(new VariableInfo("SuccessfulChild", "Variable that tells if a child has become better than its parent", typeof(BoolData), VariableKind.In | VariableKind.Deleted));
46      AddVariableInfo(new VariableInfo("TargetSuccessProbability", "The targeted probability to create a successful offsrping", typeof(DoubleData), VariableKind.In));
47      AddVariableInfo(new VariableInfo("SuccessProbability", "The measured probability to create a successful offspring", typeof(DoubleData), VariableKind.New | VariableKind.In | VariableKind.Out));
48      AddVariableInfo(new VariableInfo("LearningRate", "The speed at which the success probability changes", typeof(DoubleData), VariableKind.In));
49      AddVariableInfo(new VariableInfo("DampeningFactor", "Influences the strength of the adjustment to the mutation strength", typeof(DoubleData), VariableKind.In));
50    }
51
52    /// <summary>
53    /// Adjusts the mutation strength based on the ratio of successful offsprings.
54    /// </summary>
55    /// <param name="scope">The current scope where to adjust the mutation strength.</param>
56    /// <returns><c>null</c>.</returns>
57    public override IOperation Apply(IScope scope) {
58      DoubleData shakingFactor = GetVariableValue<DoubleData>("ShakingFactor", scope, true);
59      DoubleData targetSuccessProb = GetVariableValue<DoubleData>("TargetSuccessProbability", scope, true);
60      DoubleData successProb = GetVariableValue<DoubleData>("SuccessProbability", scope, true);
61      if (successProb == null) {
62        IVariableInfo successProbInfo = GetVariableInfo("SuccessProbability");
63        IVariable successProbVar;
64        if (successProbInfo.Local) {
65          successProbVar = new Variable(successProbInfo.ActualName, new DoubleData(targetSuccessProb.Data));
66          AddVariable(successProbVar);
67        } else {
68          successProbVar = new Variable(scope.TranslateName(successProbInfo.FormalName), new DoubleData(targetSuccessProb.Data));
69          scope.AddVariable(successProbVar);
70        }
71        successProb = (DoubleData)successProbVar.Value;
72      }
73      DoubleData learningRate = GetVariableValue<DoubleData>("LearningRate", scope, true);
74      DoubleData dampeningFactor = GetVariableValue<DoubleData>("DampeningFactor", scope, true);
75
76      double success = 0.0;
77      for (int i = 0 ; i < scope.SubScopes.Count ; i++) {
78        if (scope.SubScopes[i].GetVariableValue<BoolData>("SuccessfulChild", false).Data) {
79          success++;
80        }
81        scope.SubScopes[i].RemoveVariable(scope.SubScopes[i].TranslateName("SuccessfulChild"));
82      }
83      if (scope.SubScopes.Count > 0) success /= scope.SubScopes.Count;
84
85      successProb.Data = (1.0 - learningRate.Data) * successProb.Data + success * learningRate.Data;
86      shakingFactor.Data *= Math.Exp((successProb.Data - ((targetSuccessProb.Data * (1.0 - successProb.Data)) / (1.0 - targetSuccessProb.Data))) / dampeningFactor.Data);
87      return null;
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.