Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/10 23:41:33 (14 years ago)
Author:
cneumuel
Message:

#1215

  • improved exchangeability of crossover and mutation operators for parameter values
Location:
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test

    • Property svn:ignore
      •  

        old new  
        11bin
        22obj
         3HeuristicLab.MetaOptimization.Test.csproj.user
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5110 r5111  
    2222namespace HeuristicLab.MetaOptimization.Test {
    2323  class Program {
    24     private static int metaAlgorithmPopulationSize = 3;
     24    private static int metaAlgorithmPopulationSize = 50;
    2525    private static int metaAlgorithmMaxGenerations = 30;
    26     private static int metaProblemRepetitions = 3;
    27 
    28     private static int baseAlgorithmMaxGenerations = 3;
     26    private static int metaProblemRepetitions = 6;
     27
     28    private static int baseAlgorithmMaxGenerations = 250;
    2929
    3030    static void Main(string[] args) {
     
    3434      //TestDoubleSampling();
    3535      //TestTypeDiscovery();
     36      //TestOperators();
    3637     
    3738      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    5354
    5455      //TestMemoryLeak(metaLevelAlgorithm);
     56
     57      Console.ReadLine();
     58    }
     59
     60    private static void TestOperators() {
     61      IRandom random = new MersenneTwister();
     62      ParameterConfigurationManipulator manip = new ParameterConfigurationManipulator();
     63
     64      manip.IntValueManipulatorParameter.ActualValue = new UniformIntValueManipulator();
     65      manip.DoubleValueManipulatorParameter.ActualValue = new NormalDoubleValueManipulator();
     66     
     67      var doubleRange = new DoubleValueRange(new DoubleValue(0), new DoubleValue(100), new DoubleValue(0.1));
     68      using (var sw = new StreamWriter("out-DoubleValue.txt")) {
     69        for (int i = 0; i < 10000; i++) {
     70          var val = new DoubleValue(50);
     71          NormalDoubleValueManipulator.ApplyStatic(random, val, doubleRange);
     72         
     73          sw.WriteLine(val);
     74        }
     75      }
     76
     77      var percentRange = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));
     78      using (var sw = new StreamWriter("out-PercentValue.txt")) {
     79        for (int i = 0; i < 10000; i++) {
     80          var val = new PercentValue(0.5);
     81          NormalDoubleValueManipulator.ApplyStatic(random, val, percentRange.AsDoubleValueRange());
     82          sw.WriteLine(val);
     83        }
     84      }
     85
     86      var intRange = new IntValueRange(new IntValue(0), new IntValue(100), new IntValue(1));
     87      using (var sw = new StreamWriter("out-IntValue.txt")) {
     88        for (int i = 0; i < 10000; i++) {
     89          var val = new IntValue(50);
     90          UniformIntValueManipulator.ApplyStatic(random, val, intRange);
     91          sw.WriteLine(val);
     92        }
     93      }
    5594
    5695      Console.ReadLine();
     
    145184      for (int i = 0; i < 10; i++) {
    146185        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
     186        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    147187        clonedVc.Randomize(rand);
    148         clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    149         GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
     188        clonedVc.Parameterize(newAlg);
    150189        Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    151190        Console.WriteLine(string.Format("MutRate: original: {0}, randomized: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
    152191        Console.WriteLine(string.Format("MutOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    153192        Console.WriteLine(string.Format("SelOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Selector, newAlg.Selector));
    154         Console.WriteLine(string.Format("GrSi: original: {0}, randomized: {1}", "?", ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
     193        //Console.WriteLine(string.Format("GrSi: original: {0}, randomized: {1}", "?", ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
    155194        Console.WriteLine("---");
    156195      }
     
    162201      for (int i = 0; i < 10; i++) {
    163202        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
    164         clonedVc.Mutate(rand);
    165         clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    166         GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
     203        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
     204        //clonedVc.Mutate(rand);
     205       
     206        //.Apply(rand, clonedVc); todo
     207        clonedVc.Parameterize(newAlg);
    167208        Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    168209        Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
    169210        Console.WriteLine(string.Format("MutOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    170211        Console.WriteLine(string.Format("SelOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Selector, newAlg.Selector));
    171         Console.WriteLine(string.Format("GrSi: original: {0}, mutated: {1}", ((TournamentSelector)baseLevelAlgorithm.Selector).GroupSizeParameter.Value, ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
     212        //Console.WriteLine(string.Format("GrSi: original: {0}, mutated: {1}", ((TournamentSelector)baseLevelAlgorithm.Selector).GroupSizeParameter.Value, ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
    172213        Console.WriteLine("---");
    173214      }
     
    179220        IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone();
    180221
    181         GeneticAlgorithm first = (GeneticAlgorithm)clonedVc1.ActualValue.Value.Clone();
    182         GeneticAlgorithm second = (GeneticAlgorithm)clonedVc2.ActualValue.Value.Clone();
     222        GeneticAlgorithm first = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
     223        GeneticAlgorithm second = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    183224
    184225        clonedVc1.Randomize(rand);
     
    192233        var mutOpBefore = first.Mutator;
    193234        var selOpBefore = first.Selector;
    194         var groupSizeBefore = ((TournamentSelector)first.Selector).GroupSizeParameter.Value.Value;
    195 
    196         clonedVc1.Cross(clonedVc2, rand);
     235        //var groupSizeBefore = ((TournamentSelector)first.Selector).GroupSizeParameter.Value.Value;
     236
     237        //clonedVc1.Cross(clonedVc2, rand); todo
    197238        clonedVc1.Parameterize(first);
    198239
     
    201242        Console.WriteLine(string.Format("MutOp: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator));
    202243        Console.WriteLine(string.Format("SelOp: first: {0}, second: {1}, crossed: {2}", selOpBefore, second.Selector, first.Selector));
    203         Console.WriteLine(string.Format("GrSi: first: {0}, second: {1}, crossed: {2}", groupSizeBefore, ((TournamentSelector)second.Selector).GroupSizeParameter.Value, ((TournamentSelector)first.Selector).GroupSizeParameter.Value));
     244        //Console.WriteLine(string.Format("GrSi: first: {0}, second: {1}, crossed: {2}", groupSizeBefore, ((TournamentSelector)second.Selector).GroupSizeParameter.Value, ((TournamentSelector)first.Selector).GroupSizeParameter.Value));
    204245        Console.WriteLine("---");
    205246      }
     
    306347            sb.AppendLine("=================================");
    307348
     349            sb.AppendLine(metaLevelAlgorithm.ExecutionState.ToString());
    308350            foreach (var result in metaLevelAlgorithm.Results) {
    309351              sb.AppendLine(result.ToString());
Note: See TracChangeset for help on using the changeset viewer.