using System; using System.Diagnostics; using System.Globalization; using HeuristicLab.Algorithms.Bandits.BanditPolicies; using HeuristicLab.Algorithms.GrammaticalOptimization; using HeuristicLab.Algorithms.MonteCarloTreeSearch; using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation; using HeuristicLab.Problems.GrammaticalOptimization; // NOTES: gkronber // TODO: feature extraction for full symbolic expressions and experiment for all benchmark problems // TODO: why does GaussianThompsonSampling work so well with MCTS for the artificial ant problem? // TODO: research thompson sampling for max bandit? // TODO: verify TA implementation using example from the original paper // TODO: implement thompson sampling for gaussian mixture models // TODO: gleichzeitige modellierung von transformierter zielvariable (y, 1/y, log(y), exp(y), sqrt(y), ...) // TODO: vergleich bei complete-randomly möglichst kurze sätze generieren vs. einfach zufällig alternativen wählen // TODO: reward discounting (für veränderliche reward distributions über zeit). speziellen unit-test dafür erstellen // TODO: constant optimization namespace Main { class Program { static void Main(string[] args) { CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; RunDemo(); } private static void RunDemo() { int maxIterations = 100000; int iterations = 0; var globalStatistics = new SentenceSetStatistics(); var random = new Random(); //var problem = new SymbolicRegressionPoly10Problem(); //var problem = new SantaFeAntProblem(); var problem = new RoyalPairProblem(); //var problem = new EvenParityProblem(); //var alg = new SequentialSearch(problem, 23, random, 0, // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy())); var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 23)); alg.FoundNewBestSolution += (sentence, quality) => { //Console.WriteLine("{0}", globalStatistics); }; alg.SolutionEvaluated += (sentence, quality) => { iterations++; globalStatistics.AddSentence(sentence, quality); // comment this if you don't want to see solver statistics if (iterations % 100 == 0) { if (iterations % 10000 == 0) Console.Clear(); Console.SetCursorPosition(0, 0); alg.PrintStats(); } // uncomment this if you want to collect statistics of the generated sentences // if (iterations % 1000 == 0) { // Console.WriteLine("{0}", globalStatistics); // } }; var sw = new Stopwatch(); sw.Start(); alg.Run(maxIterations); sw.Stop(); Console.Clear(); alg.PrintStats(); Console.WriteLine(globalStatistics); Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol", sw.Elapsed.TotalSeconds, maxIterations / (double)sw.Elapsed.TotalSeconds, (double)sw.ElapsedMilliseconds * 1000 / maxIterations); } } }