Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/24/15 13:56:27 (9 years ago)
Author:
gkronber
Message:

#2283: experiments on grammatical optimization algorithms (maxreward instead of avg reward, ...)

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

Legend:

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

    r12290 r12893  
    3434    <WarningLevel>4</WarningLevel>
    3535    <Prefer32Bit>false</Prefer32Bit>
     36    <UseVSHostingProcess>true</UseVSHostingProcess>
    3637  </PropertyGroup>
    3738  <ItemGroup>
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs

    r12876 r12893  
    44using System.Globalization;
    55using System.Linq;
    6 using System.Text.RegularExpressions;
     6using HeuristicLab.Algorithms.Bandits;
    77using HeuristicLab.Algorithms.Bandits.BanditPolicies;
    88using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
    99using HeuristicLab.Algorithms.GrammaticalOptimization;
    10 using HeuristicLab.Algorithms.MonteCarloTreeSearch;
    11 using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
    1210using HeuristicLab.Problems.GrammaticalOptimization;
    1311
     
    2321// TODO: constant optimization
    2422using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
     23using RandomPolicy = HeuristicLab.Algorithms.Bandits.GrammarPolicies.RandomPolicy;
    2524
    2625
     
    3029      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
    3130
    32       RunDemo();
    33     }
    34 
    35 
    36     private static void RunDemo() {
     31      foreach (var banditPolicy in new IBanditPolicy[]
     32      {
     33        //new HeuristicLab.Algorithms.Bandits.BanditPolicies.RandomPolicy(),
     34        //new UCB1TunedPolicy(),
     35        //new UCB1Policy(),
     36        //new UCB1Policy(0.8),
     37        //new UCB1Policy(1),
     38        new UCB1Policy(0.5),
     39        //new ExtremeHunterPolicy(),
     40        //new ThresholdAscentPolicy(),
     41        //new BoltzmannExplorationPolicy(1),
     42        //new BoltzmannExplorationPolicy(0.5),
     43        //new BoltzmannExplorationPolicy(5),
     44        //new EpsGreedyPolicy(0.1),
     45        //new EpsGreedyPolicy(0.05),
     46      }) {
     47        var problem = new SymbolicRegressionPoly10Problem(500);
     48        var random = new Random();
     49        //var problem = new SymbolicRegressionProblem(random, "Vladislavleva-1", useConstantOpt: true);
     50        //var problem = new PrimePolynomialProblem();
     51        //var problem = new SantaFeAntProblem();
     52        var policy = new GenericGrammarPolicy(problem, banditPolicy);
     53        // var policy = new GenericGrammarPolicy(problem, new UCB1Policy(0.5));
     54        //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
     55
     56        RunDemo(problem, random, policy, banditPolicy.ToString());
     57      }
     58    }
     59
     60
     61    private static void RunDemo(IProblem problem, Random random, GenericGrammarPolicy policy, string banditPolicyName) {
     62
    3763
    3864      for (int i = 0; i < 100; i++) {
    39         int maxIterations = 2000000;
    4065        int iterations = 0;
    41 
    4266        var globalStatistics = new SentenceSetStatistics();
    43         ResetAlleleStatistics();
    44         var random = new Random();
    45 
    46         var problem = new SymbolicRegressionPoly10Problem();
    47         //var problem = new SantaFeAntProblem();             
    48         //var problem = new RoyalPairProblem(25);
    49         //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true);
    50         //var problem = new PrimePolynomialProblem();
    51         //var problem = new SymbolicRegressionProblem(random,
    52         //  //@"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv",
    53         //  @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv",
    54         //  1.0,
    55         //  true);
    56         // //var problem = new PrimePolynomialProblem();
    57         // var alg = new SequentialSearch(problem, 25, random, 0,
    58         //   new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()));
    59         //var policy = new GenericPolicy(problem);
    60         //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy());
    61         //var policy = new GenericGrammarPolicy(problem, new UCB1Policy());
    62         //var policy = new GenericGrammarPolicy(problem, new ActiveLearningPolicy(0.1));
    63         var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy(1.0E-2, 1E-2, 1));
    64         var alg = new SequentialSearch(problem, 23, random, 0,
    65           policy);
    66         //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
     67
     68        var alg = new SequentialSearch(problem, 23, random, 0, policy);
    6769
    6870
     
    7476          iterations++;
    7577          globalStatistics.AddSentence(sentence, quality);
    76           UpdateAlleleStatistics(sentence);
     78          //UpdateAlleleStatistics(sentence);
    7779          // comment this if you don't want to see solver statistics
    7880          if (iterations % 100 == 0) {
     
    8183            }
    8284            Console.SetCursorPosition(0, 0);
    83             Console.WriteLine(iterations);
     85            Console.WriteLine("{0} {1}", iterations, string.Join(" ", policy.OptimalPulls.Take(15).Select(p => string.Format("{0:F3}", p))));
    8486            //WriteAlleleStatistics();
    8587            Console.WriteLine(globalStatistics.BestSentenceQuality);
     
    9092            //ResetAlleleStatistics();
    9193          }
    92          
     94
    9395          // uncomment this if you want to collect statistics of the generated sentences
    94           //if (iterations % 100 == 0) {
    95           //  Console.WriteLine("{0}", globalStatistics);
     96          //if (iterations % 1000 == 0) {
     97          //  Console.WriteLine("{0} {1} {2}", banditPolicyName, string.Join(" ", policy.OptimalPulls.Take(15).Select(p => string.Format("{0:F3}", p))), globalStatistics);
    9698          //}
    9799        };
     100        int maxIterations = 300000;
     101
     102        // ResetAlleleStatistics();
     103
     104        //var problem = new SantaFeAntProblem();
     105        //var problem = new RoyalPairProblem(10);
     106        //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true);
     107        //var problem = new PrimePolynomialProblem();
     108        //var problem = new SymbolicRegressionProblem(random, "Tower");
     109        // @"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv",
     110        //  @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv",
     111        //  1.0,
     112        //  true);
     113        // //var problem = new PrimePolynomialProblem();
     114        // var alg = new SequentialSearch(problem, 25, random, 0,
     115        //var policy = new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy());
     116        //var policy = new GenericPolicy(problem);
     117        //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy());
     118        //var policy = new GenericGrammarPolicy(problem, new UCB1Policy(0.5));
     119        //var policy = new GenericGrammarPolicy(problem, new ActiveLearningPolicy(3));
     120        //var policy = new GenericGrammarPolicy(problem, new IntervalEstimationPolicy());
     121        //var policy = new GenericGrammarPolicy(problem, new ChernoffIntervalEstimationPolicy());
     122
     123        //var policy = new GenericGrammarPolicy(problem, new EpsGreedyPolicy(0.1));
     124        //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy(0.001, 0.001, 1, 100000, minPulls: 100));
     125        //var policy = new GenericGrammarPolicy(problem, new ThresholdAscentPolicy(s: 1000, delta: 1));
     126        //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.UCB1TunedPolicy());
     127        //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationPolicy(1));
     128        //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.ThresholdAscentPolicy(500, 0.01)); // santa fe ant
     129
     130
     131        //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationWithCoolingPolicy(0.01));
     132
     133
     134
    98135
    99136        var sw = new Stopwatch();
     
    102139        sw.Stop();
    103140
    104         Console.WriteLine(globalStatistics);
    105 
    106         Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
    107           sw.Elapsed.TotalSeconds,
    108           maxIterations / (double)sw.Elapsed.TotalSeconds,
    109           (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
     141        //Console.WriteLine(globalStatistics);
     142        //
     143        //Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
     144        //  sw.Elapsed.TotalSeconds,
     145        //  maxIterations / (double)sw.Elapsed.TotalSeconds,
     146        //  (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
    110147      }
    111148    }
     
    116153        if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++;
    117154      }
    118       for (int i = 0; i < sentence.Length - 2; i+=2) {
     155      for (int i = 0; i < sentence.Length - 2; i += 2) {
    119156        var allele = sentence.Substring(i, 3);
    120157        if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++;
    121158      }
    122       for (int i = 0; i < sentence.Length - 4; i+=2) {
     159      for (int i = 0; i < sentence.Length - 4; i += 2) {
    123160        var allele = sentence.Substring(i, 5);
    124161        if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++;
     
    166203    private static void WriteAlleleStatistics() {
    167204      double count = alleleStatistics.Sum(e => e.Value);
    168       foreach (var entry in alleleStatistics.OrderByDescending(e=>e.Value)) {
     205      foreach (var entry in alleleStatistics.OrderByDescending(e => e.Value)) {
    169206        Console.WriteLine("{0,-10} {1,-10}", entry.Key, entry.Value);
    170207      }
Note: See TracChangeset for help on using the changeset viewer.