Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs @ 12391

Last change on this file since 12391 was 12098, checked in by aballeit, 10 years ago

#2283: implemented MCTS

File size: 3.5 KB
RevLine 
[11795]1using System;
[11659]2using System.Diagnostics;
[11730]3using System.Globalization;
[11742]4using HeuristicLab.Algorithms.Bandits.BanditPolicies;
[11659]5using HeuristicLab.Algorithms.GrammaticalOptimization;
[12098]6using HeuristicLab.Algorithms.MonteCarloTreeSearch;
7using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
[11659]8using 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]22namespace 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        {
[11727]36
[11730]37
[12098]38            int maxIterations = 100000;
39            int iterations = 0;
[11770]40
[12098]41            var globalStatistics = new SentenceSetStatistics();
42            var random = new Random();
[11659]43
[12098]44            //var problem = new SymbolicRegressionPoly10Problem();
45            //var problem = new SantaFeAntProblem();             
46            var problem = new RoyalPairProblem();
47            //var problem = new EvenParityProblem();
48            //var alg = new SequentialSearch(problem, 23, random, 0,
49            // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()));
50            var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 23));
[11659]51
[11981]52
[12098]53            alg.FoundNewBestSolution += (sentence, quality) =>
54            {
55                //Console.WriteLine("{0}", globalStatistics);
56            };
[11981]57
[12098]58            alg.SolutionEvaluated += (sentence, quality) =>
59            {
60                iterations++;
61                globalStatistics.AddSentence(sentence, quality);
[11832]62
[12098]63                // comment this if you don't want to see solver statistics
64                if (iterations % 100 == 0)
65                {
66                    if (iterations % 10000 == 0) Console.Clear();
67                    Console.SetCursorPosition(0, 0);
68                    alg.PrintStats();
69                }
[11981]70
[12098]71                // uncomment this if you want to collect statistics of the generated sentences
72                // if (iterations % 1000 == 0) {
73                //   Console.WriteLine("{0}", globalStatistics);
74                // }
75            };
[11659]76
[12098]77            var sw = new Stopwatch();
78            sw.Start();
79            alg.Run(maxIterations);
80            sw.Stop();
[11659]81
[12098]82            Console.Clear();
83            alg.PrintStats();
84            Console.WriteLine(globalStatistics);
85            Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
86              sw.Elapsed.TotalSeconds,
87              maxIterations / (double)sw.Elapsed.TotalSeconds,
88              (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
89        }
[11659]90    }
91}
Note: See TracBrowser for help on using the repository browser.