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