1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Globalization;
|
---|
4 | using HeuristicLab.Algorithms.Bandits.BanditPolicies;
|
---|
5 | using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
|
---|
6 | using HeuristicLab.Algorithms.GrammaticalOptimization;
|
---|
7 | using HeuristicLab.Algorithms.MonteCarloTreeSearch;
|
---|
8 | using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
|
---|
9 | using HeuristicLab.Problems.GrammaticalOptimization;
|
---|
10 |
|
---|
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
|
---|
21 | using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
|
---|
22 |
|
---|
23 |
|
---|
24 | namespace Main {
|
---|
25 | class Program {
|
---|
26 | static void Main(string[] args) {
|
---|
27 | CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
|
---|
28 |
|
---|
29 | RunDemo();
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | private static void RunDemo() {
|
---|
34 |
|
---|
35 | for (int i = 0; i < 100; i++) {
|
---|
36 | int maxIterations = 2000000;
|
---|
37 | int iterations = 0;
|
---|
38 |
|
---|
39 | var globalStatistics = new SentenceSetStatistics();
|
---|
40 | var random = new Random();
|
---|
41 |
|
---|
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()));
|
---|
55 | var policy = new GenericPolicy(problem);
|
---|
56 | var alg = new SequentialSearch(problem, 23, random, 1,
|
---|
57 | policy);
|
---|
58 | //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
|
---|
59 |
|
---|
60 |
|
---|
61 | alg.FoundNewBestSolution += (sentence, quality) => {
|
---|
62 | //Console.WriteLine("{0}", globalStatistics);
|
---|
63 | };
|
---|
64 |
|
---|
65 | alg.SolutionEvaluated += (sentence, quality) => {
|
---|
66 | iterations++;
|
---|
67 | globalStatistics.AddSentence(sentence, quality);
|
---|
68 |
|
---|
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);
|
---|
73 | // alg.PrintStats();
|
---|
74 | policy.PrintStats();
|
---|
75 | }
|
---|
76 |
|
---|
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 | };
|
---|
82 |
|
---|
83 | var sw = new Stopwatch();
|
---|
84 | sw.Start();
|
---|
85 | alg.Run(maxIterations);
|
---|
86 | sw.Stop();
|
---|
87 |
|
---|
88 | Console.WriteLine(globalStatistics);
|
---|
89 |
|
---|
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 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|