- Timestamp:
- 04/07/15 14:31:06 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization-gkr
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Main.csproj
r12098 r12290 56 56 <Name>HeuristicLab.Algorithms.MonteCarloTreeSearch</Name> 57 57 </ProjectReference> 58 <ProjectReference Include="..\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\HeuristicLab.Problems.GrammaticalOptimization.SymbReg.csproj"> 59 <Project>{17A7A380-86CE-482D-8D22-CBD70CC97F0D}</Project> 60 <Name>HeuristicLab.Problems.GrammaticalOptimization.SymbReg</Name> 61 </ProjectReference> 58 62 <ProjectReference Include="..\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.csproj"> 59 63 <Project>{cb9dccf6-667e-4a13-b82d-dbd6b45a045e}</Project> -
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs
r12098 r12290 3 3 using System.Globalization; 4 4 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 5 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 5 6 using HeuristicLab.Algorithms.GrammaticalOptimization; 6 7 using HeuristicLab.Algorithms.MonteCarloTreeSearch; … … 18 19 // TODO: reward discounting (fÃŒr verÀnderliche reward distributions ÃŒber zeit). speziellen unit-test dafÃŒr erstellen 19 20 // TODO: constant optimization 21 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; 20 22 21 23 22 namespace Main 23 { 24 class Program 25 { 26 static void Main(string[] args) 27 { 28 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 24 namespace Main { 25 class Program { 26 static void Main(string[] args) { 27 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 29 28 30 31 29 RunDemo(); 30 } 32 31 33 32 34 private static void RunDemo() 35 { 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)); 36 58 37 59 38 int maxIterations = 100000; 39 int iterations = 0; 60 alg.FoundNewBestSolution += (sentence, quality) => { 61 //Console.WriteLine("{0}", globalStatistics); 62 }; 40 63 41 var globalStatistics = new SentenceSetStatistics(); 42 var random = new Random(); 64 alg.SolutionEvaluated += (sentence, quality) => { 65 iterations++; 66 globalStatistics.AddSentence(sentence, quality); 43 67 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)); 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 } 51 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 }; 52 80 53 alg.FoundNewBestSolution += (sentence, quality) =>54 {55 //Console.WriteLine("{0}", globalStatistics);56 };81 var sw = new Stopwatch(); 82 sw.Start(); 83 alg.Run(maxIterations); 84 sw.Stop(); 57 85 58 alg.SolutionEvaluated += (sentence, quality) => 59 { 60 iterations++; 61 globalStatistics.AddSentence(sentence, quality); 86 Console.WriteLine(globalStatistics); 62 87 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 } 70 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 }; 76 77 var sw = new Stopwatch(); 78 sw.Start(); 79 alg.Run(maxIterations); 80 sw.Stop(); 81 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 } 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 } 90 93 } 94 } 91 95 }
Note: See TracChangeset
for help on using the changeset viewer.