Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/29/14 11:02:36 (10 years ago)
Author:
gkronber
Message:

#2283: worked on grammatical optimization problem solvers (simple MCTS done)

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Main.csproj

    r11659 r11727  
    4949  </ItemGroup>
    5050  <ItemGroup>
     51    <ProjectReference Include="..\HeuristicLab.Algorithms.Bandits\HeuristicLab.Algorithms.Bandits.csproj">
     52      <Project>{24408F7D-EE0F-4886-A08B-EC324D662E47}</Project>
     53      <Name>HeuristicLab.Algorithms.Bandits</Name>
     54    </ProjectReference>
    5155    <ProjectReference Include="..\HeuristicLab.Algorithms.GrammaticalOptimization\HeuristicLab.Algorithms.GrammaticalOptimization.csproj">
    5256      <Project>{eea07488-1a51-412a-a52c-53b754a628b3}</Project>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs

    r11690 r11727  
    11using System;
    22using System.Collections.Generic;
     3using System.Data;
    34using System.Diagnostics;
    45using System.Linq;
    56using System.Text;
     7using System.Threading.Tasks;
     8using HeuristicLab.Algorithms.Bandits;
    69using HeuristicLab.Algorithms.GrammaticalOptimization;
    710using HeuristicLab.Problems.GrammaticalOptimization;
     
    1013  class Program {
    1114    static void Main(string[] args) {
     15      // RunDemo();
     16      RunGridTest();
     17    }
     18
     19    private static void RunGridTest() {
     20      int maxIterations = 150000;
     21      var globalRandom = new Random(31415);
     22      var reps = 10;
     23      Parallel.ForEach(new int[] { 1, 5, 10, 100, 500, 1000 }, (randomTries) => {
     24        Random localRand;
     25        lock (globalRandom) {
     26          localRand = new Random(globalRandom.Next());
     27        }
     28        var policyFactories = new Func<int, IPolicy>[]
     29        {
     30          (numActions) => new RandomPolicy(localRand, numActions),
     31          (numActions) => new UCB1Policy(numActions),
     32          (numActions) => new UCB1TunedPolicy(numActions),
     33          (numActions) => new UCBNormalPolicy(numActions),
     34          (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.01),
     35          (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.05),
     36          (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.1),
     37          (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.2),
     38          (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.5),
     39          (numActions) => new GaussianThompsonSamplingPolicy(localRand, numActions),
     40          (numActions) => new BernoulliThompsonSamplingPolicy(localRand, numActions)
     41        };
     42
     43        foreach (var policyFactory in policyFactories)
     44          for (int i = 0; i < reps; i++) {
     45            int iterations = 0;
     46            var sw = new Stopwatch();
     47            var globalStatistics = new SentenceSetStatistics();
     48
     49            // var problem = new SymbolicRegressionPoly10Problem();
     50            var problem = new SantaFeAntProblem();
     51            //var problem = new PalindromeProblem();
     52            //var problem = new HardPalindromeProblem();
     53            //var problem = new RoyalPairProblem();
     54            //var problem = new EvenParityProblem();
     55            var alg = new MctsSampler(problem, 17, localRand, randomTries, policyFactory);
     56            //var alg = new ExhaustiveBreadthFirstSearch(problem, 25);
     57            //var alg = new AlternativesContextSampler(problem, 25);
     58
     59            alg.SolutionEvaluated += (sentence, quality) => {
     60              iterations++;
     61              globalStatistics.AddSentence(sentence, quality);
     62              if (iterations % 10000 == 0) {
     63                Console.WriteLine("{0} {1} {2}", randomTries, policyFactory(1), globalStatistics);
     64              }
     65            };
     66
     67            sw.Start();
     68
     69            alg.Run(maxIterations);
     70
     71            sw.Stop();
     72          }
     73      });
     74    }
     75
     76    private static void RunDemo() {
     77      // TODO: implement threshold ascent
     78      // TODO: implement inspection for MCTS
     79
    1280      int maxIterations = 10000000;
    1381      int iterations = 0;
     
    1583      double bestQuality = 0;
    1684      string bestSentence = "";
     85      var globalStatistics = new SentenceSetStatistics();
     86      var random = new Random(31415);
    1787
    18       var rs = new ExhaustiveDepthFirstSearch(17);
     88      // var problem = new SymbolicRegressionPoly10Problem();
     89      var problem = new SantaFeAntProblem();
     90      //var problem = new PalindromeProblem();
     91      //var problem = new HardPalindromeProblem();
     92      //var problem = new RoyalPairProblem();
     93      //var problem = new EvenParityProblem();
     94      var alg = new MctsSampler(problem, 17, random);
     95      //var alg = new ExhaustiveBreadthFirstSearch(problem, 25);
     96      //var alg = new AlternativesContextSampler(problem, 25);
    1997
    20       rs.FoundNewBestSolution += (sentence, quality) => {
     98      alg.FoundNewBestSolution += (sentence, quality) => {
    2199        bestQuality = quality;
    22100        bestSentence = sentence;
    23101        Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence);
    24102      };
    25       rs.SolutionEvaluated += (sentence, quality) => {
     103      alg.SolutionEvaluated += (sentence, quality) => {
    26104        iterations++;
     105        globalStatistics.AddSentence(sentence, quality);
    27106        if (iterations % 10000 == 0) {
    28           Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence);
     107          //Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence);
     108          Console.WriteLine(globalStatistics.ToString());
    29109        }
    30110      };
     
    33113      sw.Start();
    34114
    35       rs.Run(new SymbolicRegressionPoly10Problem(), maxIterations);
     115      alg.Run(maxIterations);
    36116
    37117      sw.Stop();
Note: See TracChangeset for help on using the changeset viewer.