Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/19/15 20:09:12 (10 years ago)
Author:
gkronber
Message:

#2283: performance tuning and reactivated random-roll-out policy in sequential search

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs

    r11795 r11799  
    2424      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
    2525
    26       //RunDemo();
    27       RunGridTest();
     26      RunDemo();
     27      //RunGridTest();
    2828    }
    2929
     
    3232      //var globalRandom = new Random(31415);
    3333      var localRandSeed = 31415;
    34       var reps = 5;
    35 
    36       var policies = new Func<IBanditPolicy>[]
     34      var reps = 10;
     35
     36      var policyFactories = new Func<IBanditPolicy>[]
    3737        {
    3838         () => new RandomPolicy(),
     
    7272         () => new ChernoffIntervalEstimationPolicy( 0.1),
    7373         () => new ChernoffIntervalEstimationPolicy( 0.2),
     74         () => new ThresholdAscentPolicy(5, 0.01),
     75         () => new ThresholdAscentPolicy(5, 0.05),
     76         () => new ThresholdAscentPolicy(5, 0.1),
     77         () => new ThresholdAscentPolicy(5, 0.2),
    7478         () => new ThresholdAscentPolicy(10, 0.01),
    7579         () => new ThresholdAscentPolicy(10, 0.05),
    7680         () => new ThresholdAscentPolicy(10, 0.1),
    7781         () => new ThresholdAscentPolicy(10, 0.2),
     82         () => new ThresholdAscentPolicy(50, 0.01),
     83         () => new ThresholdAscentPolicy(50, 0.05),
     84         () => new ThresholdAscentPolicy(50, 0.1),
     85         () => new ThresholdAscentPolicy(50, 0.2),
    7886         () => new ThresholdAscentPolicy(100, 0.01),
    7987         () => new ThresholdAscentPolicy(100, 0.05),
    8088         () => new ThresholdAscentPolicy(100, 0.1),
    8189         () => new ThresholdAscentPolicy(100, 0.2),
    82          () => new ThresholdAscentPolicy(100, 0.01),
    83          () => new ThresholdAscentPolicy(100, 0.05),
    84          () => new ThresholdAscentPolicy(100, 0.1),
    85          () => new ThresholdAscentPolicy(100, 0.2),
    86          //() => new ThresholdAscentPolicy(1000, 0.01),
    87          //() => new ThresholdAscentPolicy(1000, 0.05),
    88          //() => new ThresholdAscentPolicy(1000, 0.1),
    89          //() => new ThresholdAscentPolicy(1000, 0.2),
     90         () => new ThresholdAscentPolicy(500, 0.01),
     91         () => new ThresholdAscentPolicy(500, 0.05),
     92         () => new ThresholdAscentPolicy(500, 0.1),
     93         () => new ThresholdAscentPolicy(500, 0.2),
    9094         //() => new ThresholdAscentPolicy(5000, 0.01),
    9195         //() => new ThresholdAscentPolicy(10000, 0.01),
    9296        };
    9397
    94       foreach (var problem in new Tuple<IProblem, int>[]
    95         {
    96           Tuple.Create((IProblem)new SantaFeAntProblem(), 17),
    97           Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23),
    98         })
    99         foreach (var useCanonical in new bool[] { true, false })
    100           foreach (var randomTries in new int[] { 0, /*1, 10, /* 5, 100 /*, 500, 1000 */}) {
    101             foreach (var policy in policies) {
     98      var instanceFactories = new Func<Random, Tuple<IProblem, int>>[]
     99      {
     100        (rand) => Tuple.Create((IProblem)new SantaFeAntProblem(), 17),
     101        (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:false ), 15),
     102        (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:true ), 15),
     103        (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:false), 15),
     104        (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:true), 15),
     105        (rand) => Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23)
     106      };
     107
     108      foreach (var instanceFactory in instanceFactories) {
     109        foreach (var useCanonical in new bool[] { true, false }) {
     110          foreach (var randomTries in new int[] { 0, 1, 10, /* 5, 100 /*, 500, 1000 */}) {
     111            foreach (var policyFactory in policyFactories) {
    102112              var myRandomTries = randomTries;
    103113              var localRand = new Random(localRandSeed);
    104114              var options = new ParallelOptions();
    105               options.MaxDegreeOfParallelism = 1;
     115              options.MaxDegreeOfParallelism = 4;
    106116              Parallel.For(0, reps, options, (i) => {
    107                 //var t = Task.Run(() => {
    108117                Random myLocalRand;
    109118                lock (localRand)
    110119                  myLocalRand = new Random(localRand.Next());
    111 
    112                 //for (int i = 0; i < reps; i++) {
    113120
    114121                int iterations = 0;
     
    121128                //var problem = new RoyalPairProblem();
    122129                //var problem = new EvenParityProblem();
    123                 // var alg = new MctsSampler(problem.Item1, problem.Item2, myLocalRand, myRandomTries, policy()); // TODO: Make sure we generate the same random numbers for each
    124                 var alg = new SequentialSearch(problem.Item1, problem.Item2, myLocalRand, myRandomTries, new GenericGrammarPolicy(problem.Item1, policy(), useCanonical));
     130                // var alg = new MctsSampler(problem.Item1, problem.Item2, myLocalRand, myRandomTries, policy());
     131                var instance = instanceFactory(myLocalRand);
     132                var problem = instance.Item1;
     133                var maxLen = instance.Item2;
     134                var alg = new SequentialSearch(problem, maxLen, myLocalRand, myRandomTries,
     135                  new GenericGrammarPolicy(problem, policyFactory(), useCanonical));
    125136                //var alg = new ExhaustiveBreadthFirstSearch(problem, 25);
    126137                //var alg = new AlternativesContextSampler(problem, 25);
     
    129140                  iterations++;
    130141                  globalStatistics.AddSentence(sentence, quality);
    131                   if (iterations % 1000 == 0) {
    132                     Console.WriteLine("{0,5} {1,25} {2} {3}", myRandomTries, policy(), useCanonical, globalStatistics);
     142                  if (iterations % 10000 == 0) {
     143                    Console.WriteLine("{0,3} {1,5} \"{2,25}\" {3} {4}", i, myRandomTries, policyFactory(), useCanonical, globalStatistics);
    133144                  }
    134145                };
    135146                alg.FoundNewBestSolution += (sentence, quality) => {
    136                   Console.WriteLine("{0,5} {1,25} {2} {3}", myRandomTries, policy(), useCanonical, globalStatistics);
     147                  //Console.WriteLine("{0,5} {1,25} {2} {3}",
     148                  //  myRandomTries, policyFactory(), useCanonical,
     149                  //  globalStatistics);
    137150                };
    138151
    139 
    140152                alg.Run(maxIterations);
    141 
    142                 //Console.WriteLine("{0,5} {1} {2}", randomTries, policyFactory(1), globalStatistics);
    143                 //}
    144                 //});
    145                 //tasks.Add(t);
    146153              });
    147154            }
    148155          }
    149       //Task.WaitAll(tasks.ToArray());
     156        }
     157      }
    150158    }
    151159
    152160    private static void RunDemo() {
    153       // TODO: clone problem for parallel grid test
    154161      // TODO: move problem instances into a separate folder
    155       // TODO: improve performance of SequentialSearch (memory allocations related to sequences)
    156162      // TODO: implement bridge to HL-GP
    157163      // TODO: unify MCTS, TD and ContextMCTS Solvers (stateInfos)
     
    183189      var random = new Random();
    184190
     191
     192      var problem = new RoyalSequenceProblem(random, 10, 30, 2, 1, 0);
    185193      //var phraseLen = 3;
    186194      //var numPhrases = 5;
    187195      //var problem = new RoyalPhraseSequenceProblem(random, 15, numPhrases, phraseLen: phraseLen, numCorrectPhrases: 1, correctReward: 1, incorrectReward: 0.0, phrasesAsSets: true);
    188196
    189       // var phraseLen = 2;
     197      // var phraseLen = 3;
    190198      // var numPhrases = 5;
    191       // var problem = new FindPhrasesProblem(random, 15, numPhrases, phraseLen, numOptimalPhrases: numPhrases, numDecoyPhrases: 0, correctReward: 1.0, decoyReward: 0.0, phrasesAsSets: true);
     199      // var problem = new FindPhrasesProblem(random, 10, numPhrases, phraseLen, numOptimalPhrases: numPhrases, numDecoyPhrases: 200, correctReward: 1.0, decoyReward: 0.5, phrasesAsSets: true);
    192200
    193201      // good results for symb-reg
     
    197205      // - GenericThompsonSamplingPolicy("")
    198206      // - UCTPolicy(0.10) (5 of 5 runs, 35000 iters avg.)
    199      
     207
    200208      // good results for artificial ant:
    201209      // prev results:
     
    203211      // - GaussianModelWithUnknownVariance (and Q= 0.99-quantil) also works well for Ant
    204212      // 2015 01 19: grid test with canonical states (non-canonical slightly worse)
    205       // - Threshold Ascent (best 100, 0.01; all variants relatively good
    206 
    207       //var problem = new SymbolicRegressionPoly10Problem();   
    208      
    209       var problem = new SantaFeAntProblem();
     213      // - Threshold Ascent (best 100, 0.01; all variants relatively good)
     214      // - Policies where the variance has a large weight compared to the mean? (Gaussian(compatible), Gaussian with fixed variance, UCT with large c, alle TA)
     215
     216      //var problem = new SymbolicRegressionPoly10Problem();
     217
     218      //var problem = new SantaFeAntProblem();
    210219      //var problem = new SymbolicRegressionProblem("Tower");
    211220      //var problem = new PalindromeProblem();
     
    216225      //var alg = new MctsSampler(problem, 23, random, 0, new BoltzmannExplorationPolicy(100));
    217226      //var alg = new MctsSampler(problem, 23, random, 0, new EpsGreedyPolicy(0.1));
    218       var alg = new SequentialSearch(problem, 17, random, 0,
    219         new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new BoltzmannExplorationPolicy(10), true));
     227      var alg = new SequentialSearch(problem, 30, random, 0,
     228        new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new EpsGreedyPolicy(0.1), true));
    220229      //var alg = new MctsQLearningSampler(problem, sentenceLen, random, 0, null);
    221230      //var alg = new MctsQLearningSampler(problem, 30, random, 0, new EpsGreedyPolicy(0.2));
     
    236245        iterations++;
    237246        globalStatistics.AddSentence(sentence, quality);
    238         if (iterations % 100 == 0) {
     247        if (iterations % 1000 == 0) {
    239248          if (iterations % 1000 == 0) Console.Clear();
    240249          Console.SetCursorPosition(0, 0);
Note: See TracChangeset for help on using the changeset viewer.