Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.Evolutionary/SuccessRuleMutationStrengthAdjuster.cs @ 4384

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

Fixed ticket #67

  • adapted accessing of variables in operators due to changes of variable lookup and the new name aliasing mechanism (actual/formal name translations should not be done directly anymore; instead the new method Scope.TranslateName should be used)
File size: 4.1 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        IVariable successProbVar;
50        if (successProbInfo.Local) {
51          successProbVar = new Variable(successProbInfo.ActualName, new DoubleData(targetSuccessProb.Data));
52          AddVariable(successProbVar);
53        } else {
54          successProbVar = new Variable(scope.TranslateName(successProbInfo.FormalName), new DoubleData(targetSuccessProb.Data));
55          scope.AddVariable(successProbVar);
56        }
57        successProb = (DoubleData)successProbVar.Value;
58      }
59      DoubleData learningRate = GetVariableValue<DoubleData>("LearningRate", scope, true);
60      DoubleData dampeningFactor = GetVariableValue<DoubleData>("DampeningFactor", scope, true);
61
62      double success = 0.0;
63      for (int i = 0 ; i < scope.SubScopes.Count ; i++) {
64        if (scope.SubScopes[i].GetVariableValue<BoolData>("SuccessfulChild", false).Data) {
65          success++;
66        }
67        scope.SubScopes[i].RemoveVariable(scope.SubScopes[i].TranslateName("SuccessfulChild"));
68      }
69      if (scope.SubScopes.Count > 0) success /= scope.SubScopes.Count;
70
71      successProb.Data = (1.0 - learningRate.Data) * successProb.Data + success * learningRate.Data;
72      shakingFactor.Data *= Math.Exp((successProb.Data - ((targetSuccessProb.Data * (1.0 - successProb.Data)) / (1.0 - targetSuccessProb.Data))) / dampeningFactor.Data);
73      return null;
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.