Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs @ 12290

Last change on this file since 12290 was 12290, checked in by gkronber, 9 years ago

#2283 created a new branch to separate development from aballeit

File size: 4.0 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Globalization;
4using HeuristicLab.Algorithms.Bandits.BanditPolicies;
5using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
6using HeuristicLab.Algorithms.GrammaticalOptimization;
7using HeuristicLab.Algorithms.MonteCarloTreeSearch;
8using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;
9using 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
21using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
22
23
24namespace 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 alg = new SequentialSearch(problem, 25, random, 0,
56          new GenericPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.EpsGreedyPolicy(0.1)));
57        //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
58
59
60        alg.FoundNewBestSolution += (sentence, quality) => {
61          //Console.WriteLine("{0}", globalStatistics);
62        };
63
64        alg.SolutionEvaluated += (sentence, quality) => {
65          iterations++;
66          globalStatistics.AddSentence(sentence, quality);
67
68          // comment this if you don't want to see solver statistics
69          if (iterations % 100 == 0) {
70            if (iterations % 1000 == 0) Console.Clear();
71            Console.SetCursorPosition(0, 0);
72            alg.PrintStats();
73          }
74
75          // uncomment this if you want to collect statistics of the generated sentences
76          //if (iterations % 100 == 0) {
77          //  Console.WriteLine("{0}", globalStatistics);
78          //}
79        };
80
81        var sw = new Stopwatch();
82        sw.Start();
83        alg.Run(maxIterations);
84        sw.Stop();
85
86        Console.WriteLine(globalStatistics);
87
88        Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
89          sw.Elapsed.TotalSeconds,
90          maxIterations / (double)sw.Elapsed.TotalSeconds,
91          (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
92      }
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.