Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/09 10:19:30 (15 years ago)
Author:
abeham
Message:

Modified the ES interface in the trunk to provide controls for the more advanced sigmaSA-ES (ticket #84)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ES/ES.cs

    r896 r1091  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2009 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4848
    4949      CombinedOperator co = CreateES();
    50       co.Name = "ES";
     50      co.Name = "σSA-ES";
    5151      engine.OperatorGraph.AddOperator(co);
    5252      engine.OperatorGraph.InitialOperator = co;
     
    134134      vi.AddVariable(new Variable("Generations", new IntData()));
    135135      vi.AddVariable(new Variable("MaximumGenerations", new IntData(1000)));
     136      vi.AddVariable(new Variable("GeneralLearningRate", new DoubleData(0.1)));
    136137      vi.AddVariable(new Variable("LearningRate", new DoubleData(0.1)));
    137       vi.AddVariable(new Variable("DampeningFactor", new DoubleData(10.0)));
    138       vi.AddVariable(new Variable("ShakingFactor", new DoubleData(5.0)));
    139       vi.AddVariable(new Variable("TargetSuccessProbability", new DoubleData(0.2)));
    140       vi.AddVariable(new Variable("SuccessProbability", new DoubleData(0.2)));
    141       vi.AddVariable(new Variable("UseSuccessRule", new BoolData(true)));
    142138      op.OperatorGraph.AddOperator(vi);
    143139      sp.AddSubOperator(vi);
     
    180176      op.OperatorGraph.AddOperator(c);
    181177      sp2.AddSubOperator(c);
     178
     179      VariableInjector vi = new VariableInjector();
     180      vi.AddVariable(new Variable("ShakingFactors", new DoubleArrayData(new double[] { 5.0 })));
     181      op.OperatorGraph.AddOperator(vi);
     182      sp2.AddSubOperator(vi);
    182183
    183184      Sorter s = new Sorter();
     
    285286      op.OperatorGraph.InitialOperator = sp1;
    286287
    287       ConditionalBranch cb = new ConditionalBranch();
    288       cb.GetVariableInfo("Condition").ActualName = "UseSuccessRule";
    289       op.OperatorGraph.AddOperator(cb);
    290       sp1.AddSubOperator(cb);
    291 
    292       SequentialProcessor sp2 = new SequentialProcessor();
    293       op.OperatorGraph.AddOperator(sp2);
    294       cb.AddSubOperator(sp2);
    295 
    296       OffspringAnalyzer oa = new OffspringAnalyzer();
    297       oa.Name = "Offspring Analyzer";
    298       oa.GetVariable("ParentsCount").Value = new IntData(1);
    299       oa.GetVariable("ComparisonFactor").Value = new DoubleData(0.0);
    300       op.OperatorGraph.AddOperator(oa);
    301       sp2.AddSubOperator(oa);
    302 
    303       SequentialProcessor sp3 = new SequentialProcessor();
    304       op.OperatorGraph.AddOperator(sp3);
    305       oa.AddSubOperator(sp3);
    306       cb.AddSubOperator(sp3);
    307 
    308288      OperatorExtractor oe1 = new OperatorExtractor();
    309289      oe1.Name = "Recombinator";
    310290      oe1.GetVariableInfo("Operator").ActualName = "Recombinator";
    311291      op.OperatorGraph.AddOperator(oe1);
    312       sp3.AddSubOperator(oe1);
     292      sp1.AddSubOperator(oe1);
    313293
    314294      UniformSequentialSubScopesProcessor ussp = new UniformSequentialSubScopesProcessor();
    315295      op.OperatorGraph.AddOperator(ussp);
    316       sp3.AddSubOperator(ussp);
    317 
    318       SequentialProcessor sp4 = new SequentialProcessor();
    319       op.OperatorGraph.AddOperator(sp4);
    320       ussp.AddSubOperator(sp4);
     296      sp1.AddSubOperator(ussp);
     297
     298      SequentialProcessor sp2 = new SequentialProcessor();
     299      op.OperatorGraph.AddOperator(sp2);
     300      ussp.AddSubOperator(sp2);
    321301
    322302      OperatorExtractor oe2 = new OperatorExtractor();
     
    324304      oe2.GetVariableInfo("Operator").ActualName = "Mutator";
    325305      op.OperatorGraph.AddOperator(oe2);
    326       sp4.AddSubOperator(oe2);
     306      sp2.AddSubOperator(oe2);
    327307
    328308      OperatorExtractor oe3 = new OperatorExtractor();
     
    330310      oe3.GetVariableInfo("Operator").ActualName = "Evaluator";
    331311      op.OperatorGraph.AddOperator(oe3);
    332       sp4.AddSubOperator(oe3);
     312      sp2.AddSubOperator(oe3);
    333313
    334314      Counter c = new Counter();
    335315      c.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    336316      op.OperatorGraph.AddOperator(c);
    337       sp4.AddSubOperator(c);
    338 
    339       SuccessRuleMutationStrengthAdjuster srmsa = new SuccessRuleMutationStrengthAdjuster();
    340       srmsa.Name = "SuccessRuleMutationStrengthAdjuster";
    341       op.OperatorGraph.AddOperator(srmsa);
    342       sp2.AddSubOperator(srmsa);
     317      sp2.AddSubOperator(c);
    343318
    344319      Sorter s = new Sorter();
     
    411386    /// Gets or sets the µ value of the current instance.
    412387    /// </summary>
    413     /// <remarks>Sets also the lambda and the rho value. Calls <see cref="ItemBase.OnChanged"/> of
     388    /// <remarks>Sets also the λ and the ρ value if necessary. Using the comma notation it must hold that λ >= µ and generally µ >= ρ must hold as well. Calls <see cref="ItemBase.OnChanged"/> of
    414389    /// base class <see cref="ItemBase"/>.</remarks>
    415390    public int Mu {
     
    426401    private IntData myRho;
    427402    /// <summary>
    428     /// Gets or sets the rho value of the current instance.
    429     /// </summary>
    430     /// <remarks>Sets also the µ value. Calls <see cref="ItemBase.OnChanged"/> of
     403    /// Gets or sets the ρ value of the current instance.
     404    /// </summary>
     405    /// <remarks>Sets also the µ value to be as large as the new ρ value if it was smaller before. Calls <see cref="ItemBase.OnChanged"/> of
    431406    /// base class <see cref="ItemBase"/>.</remarks>
    432407    public int Rho {
     
    442417    private IntData myLambda;
    443418    /// <summary>
    444     /// Gets or sets the lambda value of the current instance.
    445     /// </summary>
    446     /// <remarks>May also change the µ value under certain circumstances.
     419    /// Gets or sets the λ value of the current instance.
     420    /// </summary>
     421    /// <remarks>If the comma notation is used, it also changes the µ value to be as large as the new λ value if it was larger before. Note that in general for good optimization results it needs to be fairly larger than mu.
    447422    /// Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>.</remarks>
    448423    public int Lambda {
     
    452427          if (PlusNotation) myLambda.Data = value;
    453428          else {
    454             if (value > 1 && value < Mu) {
     429            if (value >= 1 && value < Mu) {
    455430              myLambda.Data = value;
    456               myMu.Data = value - 1;
    457             } else if (value == 1) {
    458               myMu.Data = 1;
    459               myLambda.Data = 2;
     431              myMu.Data = value;
    460432            } else if (value > Mu) {
    461433              myLambda.Data = value;
     
    468440    private BoolData myPlusNotation;
    469441    /// <summary>
    470     /// Gets or sets the boolean flag whether it is a plus notation or not.
    471     /// </summary>
    472     /// <remarks>May also set the lambda value under certain circumstances.
     442    /// Gets or sets the boolean flag whether the plus notation is used (true) or the comma notation (false).
     443    /// </summary>
     444    /// <remarks>If set to false (comma notation) it sets λ to be as large as µ if is lower. Note that in general for good optimization results it needs to be fairly larger than µ.
    473445    /// Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>.</remarks>
    474446    public bool PlusNotation {
     
    476448      set {
    477449        if (!value && myPlusNotation.Data) { // from plus to point
    478           if (Lambda <= Mu) {
    479             myLambda.Data = Mu + 1;
     450          if (Lambda < Mu) {
     451            myLambda.Data = Mu;
    480452          }
    481453        }
     
    484456      }
    485457    }
    486     private DoubleData myShakingFactor;
    487     /// <summary>
    488     /// Gets or sets the shaking factor of the current instance.
    489     /// </summary>
    490     public double ShakingFactor {
    491       get { return myShakingFactor.Data; }
    492       set { myShakingFactor.Data = value; }
    493     }
    494     private DoubleData mySuccessProbability;
    495    
    496     private DoubleData myTargetSuccessProbability;
    497     /// <summary>
    498     /// Gets or sets the success probability.
    499     /// </summary>
    500     /// <remarks>Gets the target success probability and sets also the target success probability.</remarks>
    501     public double SuccessProbability {
    502       get { return myTargetSuccessProbability.Data; }
    503       set {
    504         myTargetSuccessProbability.Data = value;
    505         mySuccessProbability.Data = value;
     458    private DoubleArrayData myShakingFactors;
     459    /// <summary>
     460    /// Gets or sets the initial strategy vector s(0).
     461    /// </summary>
     462    /// <remarks>Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>
     463    /// in the setter.</remarks>
     464    public double[] ShakingFactors {
     465      get { return myShakingFactors.Data; }
     466      set { myShakingFactors.Data = value; }
     467    }
     468    private DoubleData myGeneralLearningRate;
     469    /// <summary>
     470    /// Gets or sets the general learning rate (tau0).
     471    /// </summary>
     472    /// <remarks>Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>
     473    /// in the setter.</remarks>
     474    public double GeneralLearningRate {
     475      get { return myGeneralLearningRate.Data; }
     476      set {
     477        if (value > 0.0 && value <= 1.0) {
     478          myGeneralLearningRate.Data = value;
     479          OnChanged();
     480        }
    506481      }
    507482    }
    508483    private DoubleData myLearningRate;
    509484    /// <summary>
    510     /// Gets or sets the learning rate.
     485    /// Gets or sets the learning rate (tau).
    511486    /// </summary>
    512487    /// <remarks>Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>
     
    521496      }
    522497    }
    523     private DoubleData myDampeningFactor;
    524     /// <summary>
    525     /// Gets or sets the dampening factor.
    526     /// </summary>
    527     /// <remarks>Calls <see cref="ItemBase.OnChanged"/> of base class <see cref="ItemBase"/>
    528     /// in the setter.</remarks>
    529     public double DampeningFactor {
    530       get { return myDampeningFactor.Data; }
    531       set {
    532         if (value >= 1.0) {
    533           myDampeningFactor.Data = value;
    534           OnChanged();
    535         }
    536       }
    537     }
    538498    private IntData myMaximumGenerations;
    539499    /// <summary>
     
    543503      get { return myMaximumGenerations.Data; }
    544504      set { myMaximumGenerations.Data = value; }
    545     }
    546     private BoolData myUseSuccessRule;
    547     /// <summary>
    548     /// Gets or sets the boolean flag whether to use the success rule or not.
    549     /// </summary>
    550     public bool UseSuccessRule {
    551       get { return myUseSuccessRule.Data; }
    552       set { myUseSuccessRule.Data = value; }
    553505    }
    554506    private CombinedOperator myES;
     
    681633      myMaximumGenerations = vi.GetVariable("MaximumGenerations").GetValue<IntData>();
    682634      myPlusNotation = vi.GetVariable("PlusNotation").GetValue<BoolData>();
    683       myShakingFactor = vi.GetVariable("ShakingFactor").GetValue<DoubleData>();
    684       myTargetSuccessProbability = vi.GetVariable("TargetSuccessProbability").GetValue<DoubleData>();
    685       mySuccessProbability = vi.GetVariable("SuccessProbability").GetValue<DoubleData>();
     635      myGeneralLearningRate = vi.GetVariable("GeneralLearningRate").GetValue<DoubleData>();
    686636      myLearningRate = vi.GetVariable("LearningRate").GetValue<DoubleData>();
    687       myDampeningFactor = vi.GetVariable("DampeningFactor").GetValue<DoubleData>();
    688       myUseSuccessRule = vi.GetVariable("UseSuccessRule").GetValue<BoolData>();
    689637      // Population Initialization
    690638      CombinedOperator co3 = (CombinedOperator)sp1.SubOperators[1];
    691639      myPopulationInitialization = co3;
     640      // Variable Injector
     641      VariableInjector vi2 = (VariableInjector)co3.OperatorGraph.InitialOperator.SubOperators[1].SubOperators[0].SubOperators[3];
     642      myShakingFactors = vi2.GetVariable("ShakingFactors").GetValue<DoubleArrayData>();
    692643      // ES Main
    693644      CombinedOperator co4 = (CombinedOperator)sp1.SubOperators[2];
Note: See TracChangeset for help on using the changeset viewer.