- Timestamp:
- 12/29/14 11:02:36 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Main.csproj
r11659 r11727 49 49 </ItemGroup> 50 50 <ItemGroup> 51 <ProjectReference Include="..\HeuristicLab.Algorithms.Bandits\HeuristicLab.Algorithms.Bandits.csproj"> 52 <Project>{24408F7D-EE0F-4886-A08B-EC324D662E47}</Project> 53 <Name>HeuristicLab.Algorithms.Bandits</Name> 54 </ProjectReference> 51 55 <ProjectReference Include="..\HeuristicLab.Algorithms.GrammaticalOptimization\HeuristicLab.Algorithms.GrammaticalOptimization.csproj"> 52 56 <Project>{eea07488-1a51-412a-a52c-53b754a628b3}</Project> -
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r11690 r11727 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Data; 3 4 using System.Diagnostics; 4 5 using System.Linq; 5 6 using System.Text; 7 using System.Threading.Tasks; 8 using HeuristicLab.Algorithms.Bandits; 6 9 using HeuristicLab.Algorithms.GrammaticalOptimization; 7 10 using HeuristicLab.Problems.GrammaticalOptimization; … … 10 13 class Program { 11 14 static void Main(string[] args) { 15 // RunDemo(); 16 RunGridTest(); 17 } 18 19 private static void RunGridTest() { 20 int maxIterations = 150000; 21 var globalRandom = new Random(31415); 22 var reps = 10; 23 Parallel.ForEach(new int[] { 1, 5, 10, 100, 500, 1000 }, (randomTries) => { 24 Random localRand; 25 lock (globalRandom) { 26 localRand = new Random(globalRandom.Next()); 27 } 28 var policyFactories = new Func<int, IPolicy>[] 29 { 30 (numActions) => new RandomPolicy(localRand, numActions), 31 (numActions) => new UCB1Policy(numActions), 32 (numActions) => new UCB1TunedPolicy(numActions), 33 (numActions) => new UCBNormalPolicy(numActions), 34 (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.01), 35 (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.05), 36 (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.1), 37 (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.2), 38 (numActions) => new EpsGreedyPolicy(localRand, numActions, 0.5), 39 (numActions) => new GaussianThompsonSamplingPolicy(localRand, numActions), 40 (numActions) => new BernoulliThompsonSamplingPolicy(localRand, numActions) 41 }; 42 43 foreach (var policyFactory in policyFactories) 44 for (int i = 0; i < reps; i++) { 45 int iterations = 0; 46 var sw = new Stopwatch(); 47 var globalStatistics = new SentenceSetStatistics(); 48 49 // var problem = new SymbolicRegressionPoly10Problem(); 50 var problem = new SantaFeAntProblem(); 51 //var problem = new PalindromeProblem(); 52 //var problem = new HardPalindromeProblem(); 53 //var problem = new RoyalPairProblem(); 54 //var problem = new EvenParityProblem(); 55 var alg = new MctsSampler(problem, 17, localRand, randomTries, policyFactory); 56 //var alg = new ExhaustiveBreadthFirstSearch(problem, 25); 57 //var alg = new AlternativesContextSampler(problem, 25); 58 59 alg.SolutionEvaluated += (sentence, quality) => { 60 iterations++; 61 globalStatistics.AddSentence(sentence, quality); 62 if (iterations % 10000 == 0) { 63 Console.WriteLine("{0} {1} {2}", randomTries, policyFactory(1), globalStatistics); 64 } 65 }; 66 67 sw.Start(); 68 69 alg.Run(maxIterations); 70 71 sw.Stop(); 72 } 73 }); 74 } 75 76 private static void RunDemo() { 77 // TODO: implement threshold ascent 78 // TODO: implement inspection for MCTS 79 12 80 int maxIterations = 10000000; 13 81 int iterations = 0; … … 15 83 double bestQuality = 0; 16 84 string bestSentence = ""; 85 var globalStatistics = new SentenceSetStatistics(); 86 var random = new Random(31415); 17 87 18 var rs = new ExhaustiveDepthFirstSearch(17); 88 // var problem = new SymbolicRegressionPoly10Problem(); 89 var problem = new SantaFeAntProblem(); 90 //var problem = new PalindromeProblem(); 91 //var problem = new HardPalindromeProblem(); 92 //var problem = new RoyalPairProblem(); 93 //var problem = new EvenParityProblem(); 94 var alg = new MctsSampler(problem, 17, random); 95 //var alg = new ExhaustiveBreadthFirstSearch(problem, 25); 96 //var alg = new AlternativesContextSampler(problem, 25); 19 97 20 rs.FoundNewBestSolution += (sentence, quality) => {98 alg.FoundNewBestSolution += (sentence, quality) => { 21 99 bestQuality = quality; 22 100 bestSentence = sentence; 23 101 Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence); 24 102 }; 25 rs.SolutionEvaluated += (sentence, quality) => {103 alg.SolutionEvaluated += (sentence, quality) => { 26 104 iterations++; 105 globalStatistics.AddSentence(sentence, quality); 27 106 if (iterations % 10000 == 0) { 28 Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence); 107 //Console.WriteLine("{0,10} {1,10:F5} {2,10:F5} {3}", iterations, bestQuality, quality, sentence); 108 Console.WriteLine(globalStatistics.ToString()); 29 109 } 30 110 }; … … 33 113 sw.Start(); 34 114 35 rs.Run(new SymbolicRegressionPoly10Problem(),maxIterations);115 alg.Run(maxIterations); 36 116 37 117 sw.Stop();
Note: See TracChangeset
for help on using the changeset viewer.