Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs @ 12295

Last change on this file since 12295 was 12295, checked in by gkronber, 10 years ago

#2283: force selection of untried alternatives

File size: 4.0 KB
RevLine 
[11795]1using System;
[11659]2using System.Diagnostics;
[11730]3using System.Globalization;
[11742]4using HeuristicLab.Algorithms.Bandits.BanditPolicies;
[12290]5using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
[11659]6using HeuristicLab.Algorithms.GrammaticalOptimization;
[12098]7using HeuristicLab.Algorithms.MonteCarloTreeSearch;
8using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
[11659]9using HeuristicLab.Problems.GrammaticalOptimization;
10
[11981]11// NOTES: gkronber
12// TODO: feature extraction for full symbolic expressions and experiment for all benchmark problems
13// TODO: why does GaussianThompsonSampling work so well with MCTS for the artificial ant problem?
14// TODO: research thompson sampling for max bandit?
15// TODO: verify TA implementation using example from the original paper     
16// TODO: implement thompson sampling for gaussian mixture models
17// TODO: gleichzeitige modellierung von transformierter zielvariable (y, 1/y, log(y), exp(y), sqrt(y), ...)
18// TODO: vergleich bei complete-randomly möglichst kurze sÀtze generieren vs. einfach zufÀllig alternativen wÀhlen
19// TODO: reward discounting (fÌr verÀnderliche reward distributions Ìber zeit). speziellen unit-test dafÌr erstellen
20// TODO: constant optimization
[12290]21using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
[11981]22
23
[12290]24namespace Main {
25  class Program {
26    static void Main(string[] args) {
27      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
[11730]28
[12290]29      RunDemo();
30    }
[11727]31
[11730]32
[12290]33    private static void RunDemo() {
[11727]34
[12290]35      for (int i = 0; i < 100; i++) {
36        int maxIterations = 2000000;
37        int iterations = 0;
[11730]38
[12290]39        var globalStatistics = new SentenceSetStatistics();
40        var random = new Random();
[11770]41
[12290]42        var problem = new SymbolicRegressionPoly10Problem();
43        //var problem = new SantaFeAntProblem();             
44        //var problem = new RoyalPairProblem(25);
45        //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true);
46        //var problem = new PrimePolynomialProblem();
47        //var problem = new SymbolicRegressionProblem(random,
48        //  //@"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv",
49        //  @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv",
50        //  1.0,
51        //  true);
52        // //var problem = new PrimePolynomialProblem();
53        // var alg = new SequentialSearch(problem, 25, random, 0,
54        //   new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()));
[12294]55        var policy = new GenericPolicy(problem);
[12295]56        var alg = new SequentialSearch(problem, 23, random, 0,
[12294]57          policy);
[12290]58        //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
[11659]59
60
[12290]61        alg.FoundNewBestSolution += (sentence, quality) => {
62          //Console.WriteLine("{0}", globalStatistics);
63        };
[11981]64
[12290]65        alg.SolutionEvaluated += (sentence, quality) => {
66          iterations++;
67          globalStatistics.AddSentence(sentence, quality);
[11981]68
[12290]69          // comment this if you don't want to see solver statistics
70          if (iterations % 100 == 0) {
71            if (iterations % 1000 == 0) Console.Clear();
72            Console.SetCursorPosition(0, 0);
[12295]73             alg.PrintStats();
74            //policy.PrintStats();
[12290]75          }
[11832]76
[12290]77          // uncomment this if you want to collect statistics of the generated sentences
78          //if (iterations % 100 == 0) {
79          //  Console.WriteLine("{0}", globalStatistics);
80          //}
81        };
[11981]82
[12290]83        var sw = new Stopwatch();
84        sw.Start();
85        alg.Run(maxIterations);
86        sw.Stop();
[11659]87
[12290]88        Console.WriteLine(globalStatistics);
[11659]89
[12290]90        Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
91          sw.Elapsed.TotalSeconds,
92          maxIterations / (double)sw.Elapsed.TotalSeconds,
93          (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
94      }
[11659]95    }
[12290]96  }
[11659]97}
Note: See TracBrowser for help on using the repository browser.