Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Evolutionary/SuccessRuleMutationStrengthAdjuster.cs @ 2

Last change on this file since 2 was 2, checked in by swagner, 16 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.9 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  public class SuccessRuleMutationStrengthAdjuster : OperatorBase {
30    public override string Description {
31      get { return @"Adjusts the mutation strength based on the ratio of successful offsprings"; }
32    }
33
34    public SuccessRuleMutationStrengthAdjuster() {
35      AddVariableInfo(new VariableInfo("ShakingFactor", "The mutation strength to adjust", typeof(DoubleData), VariableKind.In | VariableKind.Out));
36      AddVariableInfo(new VariableInfo("SuccessfulChild", "Variable that tells if a child has become better than its parent", typeof(BoolData), VariableKind.In | VariableKind.Deleted));
37      AddVariableInfo(new VariableInfo("TargetSuccessProbability", "The targeted probability to create a successful offsrping", typeof(DoubleData), VariableKind.In));
38      AddVariableInfo(new VariableInfo("SuccessProbability", "The measured probability to create a successful offspring", typeof(DoubleData), VariableKind.New | VariableKind.In | VariableKind.Out));
39      AddVariableInfo(new VariableInfo("LearningRate", "The speed at which the success probability changes", typeof(DoubleData), VariableKind.In));
40      AddVariableInfo(new VariableInfo("DampeningFactor", "Influences the strength of the adjustment to the mutation strength", typeof(DoubleData), VariableKind.In));
41    }
42
43    public override IOperation Apply(IScope scope) {
44      DoubleData shakingFactor = GetVariableValue<DoubleData>("ShakingFactor", scope, true);
45      DoubleData targetSuccessProb = GetVariableValue<DoubleData>("TargetSuccessProbability", scope, true);
46      DoubleData successProb = GetVariableValue<DoubleData>("SuccessProbability", scope, true);
47      if (successProb == null) {
48        IVariableInfo successProbInfo = GetVariableInfo("SuccessProbability");
49        Variable successProbVar = new Variable(successProbInfo.ActualName, new DoubleData(targetSuccessProb.Data));
50        if (successProbInfo.Local)
51          AddVariable(successProbVar);
52        else
53          scope.AddVariable(successProbVar);
54        successProb = (DoubleData)successProbVar.Value;
55      }
56      DoubleData learningRate = GetVariableValue<DoubleData>("LearningRate", scope, true);
57      DoubleData dampeningFactor = GetVariableValue<DoubleData>("DampeningFactor", scope, true);
58
59      double success = 0.0;
60      for (int i = 0 ; i < scope.SubScopes.Count ; i++) {
61        if (scope.SubScopes[i].GetVariableValue<BoolData>(GetVariableInfo("SuccessfulChild").ActualName, false).Data) {
62          success++;
63        }
64        scope.SubScopes[i].RemoveVariable(GetVariableInfo("SuccessfulChild").ActualName);
65      }
66      if (scope.SubScopes.Count > 0) success /= scope.SubScopes.Count;
67
68      successProb.Data = (1.0 - learningRate.Data) * successProb.Data + success * learningRate.Data;
69      shakingFactor.Data *= Math.Exp((successProb.Data - ((targetSuccessProb.Data * (1.0 - successProb.Data)) / (1.0 - targetSuccessProb.Data))) / dampeningFactor.Data);
70      return null;
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.