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