- Timestamp:
- 08/24/15 13:56:27 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Main.csproj
r12290 r12893 34 34 <WarningLevel>4</WarningLevel> 35 35 <Prefer32Bit>false</Prefer32Bit> 36 <UseVSHostingProcess>true</UseVSHostingProcess> 36 37 </PropertyGroup> 37 38 <ItemGroup> -
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs
r12876 r12893 4 4 using System.Globalization; 5 5 using System.Linq; 6 using System.Text.RegularExpressions;6 using HeuristicLab.Algorithms.Bandits; 7 7 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 8 8 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 9 9 using HeuristicLab.Algorithms.GrammaticalOptimization; 10 using HeuristicLab.Algorithms.MonteCarloTreeSearch;11 using HeuristicLab.Algorithms.MonteCarloTreeSearch.Simulation;12 10 using HeuristicLab.Problems.GrammaticalOptimization; 13 11 … … 23 21 // TODO: constant optimization 24 22 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; 23 using RandomPolicy = HeuristicLab.Algorithms.Bandits.GrammarPolicies.RandomPolicy; 25 24 26 25 … … 30 29 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 31 30 32 RunDemo(); 33 } 34 35 36 private static void RunDemo() { 31 foreach (var banditPolicy in new IBanditPolicy[] 32 { 33 //new HeuristicLab.Algorithms.Bandits.BanditPolicies.RandomPolicy(), 34 //new UCB1TunedPolicy(), 35 //new UCB1Policy(), 36 //new UCB1Policy(0.8), 37 //new UCB1Policy(1), 38 new UCB1Policy(0.5), 39 //new ExtremeHunterPolicy(), 40 //new ThresholdAscentPolicy(), 41 //new BoltzmannExplorationPolicy(1), 42 //new BoltzmannExplorationPolicy(0.5), 43 //new BoltzmannExplorationPolicy(5), 44 //new EpsGreedyPolicy(0.1), 45 //new EpsGreedyPolicy(0.05), 46 }) { 47 var problem = new SymbolicRegressionPoly10Problem(500); 48 var random = new Random(); 49 //var problem = new SymbolicRegressionProblem(random, "Vladislavleva-1", useConstantOpt: true); 50 //var problem = new PrimePolynomialProblem(); 51 //var problem = new SantaFeAntProblem(); 52 var policy = new GenericGrammarPolicy(problem, banditPolicy); 53 // var policy = new GenericGrammarPolicy(problem, new UCB1Policy(0.5)); 54 //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30)); 55 56 RunDemo(problem, random, policy, banditPolicy.ToString()); 57 } 58 } 59 60 61 private static void RunDemo(IProblem problem, Random random, GenericGrammarPolicy policy, string banditPolicyName) { 62 37 63 38 64 for (int i = 0; i < 100; i++) { 39 int maxIterations = 2000000;40 65 int iterations = 0; 41 42 66 var globalStatistics = new SentenceSetStatistics(); 43 ResetAlleleStatistics(); 44 var random = new Random(); 45 46 var problem = new SymbolicRegressionPoly10Problem(); 47 //var problem = new SantaFeAntProblem(); 48 //var problem = new RoyalPairProblem(25); 49 //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true); 50 //var problem = new PrimePolynomialProblem(); 51 //var problem = new SymbolicRegressionProblem(random, 52 // //@"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv", 53 // @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv", 54 // 1.0, 55 // true); 56 // //var problem = new PrimePolynomialProblem(); 57 // var alg = new SequentialSearch(problem, 25, random, 0, 58 // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy())); 59 //var policy = new GenericPolicy(problem); 60 //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy()); 61 //var policy = new GenericGrammarPolicy(problem, new UCB1Policy()); 62 //var policy = new GenericGrammarPolicy(problem, new ActiveLearningPolicy(0.1)); 63 var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy(1.0E-2, 1E-2, 1)); 64 var alg = new SequentialSearch(problem, 23, random, 0, 65 policy); 66 //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30)); 67 68 var alg = new SequentialSearch(problem, 23, random, 0, policy); 67 69 68 70 … … 74 76 iterations++; 75 77 globalStatistics.AddSentence(sentence, quality); 76 UpdateAlleleStatistics(sentence);78 //UpdateAlleleStatistics(sentence); 77 79 // comment this if you don't want to see solver statistics 78 80 if (iterations % 100 == 0) { … … 81 83 } 82 84 Console.SetCursorPosition(0, 0); 83 Console.WriteLine( iterations);85 Console.WriteLine("{0} {1}", iterations, string.Join(" ", policy.OptimalPulls.Take(15).Select(p => string.Format("{0:F3}", p)))); 84 86 //WriteAlleleStatistics(); 85 87 Console.WriteLine(globalStatistics.BestSentenceQuality); … … 90 92 //ResetAlleleStatistics(); 91 93 } 92 94 93 95 // uncomment this if you want to collect statistics of the generated sentences 94 //if (iterations % 100 == 0) {95 // Console.WriteLine("{0} ", globalStatistics);96 //if (iterations % 1000 == 0) { 97 // Console.WriteLine("{0} {1} {2}", banditPolicyName, string.Join(" ", policy.OptimalPulls.Take(15).Select(p => string.Format("{0:F3}", p))), globalStatistics); 96 98 //} 97 99 }; 100 int maxIterations = 300000; 101 102 // ResetAlleleStatistics(); 103 104 //var problem = new SantaFeAntProblem(); 105 //var problem = new RoyalPairProblem(10); 106 //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true); 107 //var problem = new PrimePolynomialProblem(); 108 //var problem = new SymbolicRegressionProblem(random, "Tower"); 109 // @"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv", 110 // @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv", 111 // 1.0, 112 // true); 113 // //var problem = new PrimePolynomialProblem(); 114 // var alg = new SequentialSearch(problem, 25, random, 0, 115 //var policy = new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()); 116 //var policy = new GenericPolicy(problem); 117 //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy()); 118 //var policy = new GenericGrammarPolicy(problem, new UCB1Policy(0.5)); 119 //var policy = new GenericGrammarPolicy(problem, new ActiveLearningPolicy(3)); 120 //var policy = new GenericGrammarPolicy(problem, new IntervalEstimationPolicy()); 121 //var policy = new GenericGrammarPolicy(problem, new ChernoffIntervalEstimationPolicy()); 122 123 //var policy = new GenericGrammarPolicy(problem, new EpsGreedyPolicy(0.1)); 124 //var policy = new GenericGrammarPolicy(problem, new ExtremeHunterPolicy(0.001, 0.001, 1, 100000, minPulls: 100)); 125 //var policy = new GenericGrammarPolicy(problem, new ThresholdAscentPolicy(s: 1000, delta: 1)); 126 //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.UCB1TunedPolicy()); 127 //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationPolicy(1)); 128 //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.ThresholdAscentPolicy(500, 0.01)); // santa fe ant 129 130 131 //var policy = new GenericGrammarPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationWithCoolingPolicy(0.01)); 132 133 134 98 135 99 136 var sw = new Stopwatch(); … … 102 139 sw.Stop(); 103 140 104 Console.WriteLine(globalStatistics);105 106 Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",107 sw.Elapsed.TotalSeconds,108 maxIterations / (double)sw.Elapsed.TotalSeconds,109 (double)sw.ElapsedMilliseconds * 1000 / maxIterations);141 //Console.WriteLine(globalStatistics); 142 // 143 //Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol", 144 // sw.Elapsed.TotalSeconds, 145 // maxIterations / (double)sw.Elapsed.TotalSeconds, 146 // (double)sw.ElapsedMilliseconds * 1000 / maxIterations); 110 147 } 111 148 } … … 116 153 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; 117 154 } 118 for (int i = 0; i < sentence.Length - 2; i +=2) {155 for (int i = 0; i < sentence.Length - 2; i += 2) { 119 156 var allele = sentence.Substring(i, 3); 120 157 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; 121 158 } 122 for (int i = 0; i < sentence.Length - 4; i +=2) {159 for (int i = 0; i < sentence.Length - 4; i += 2) { 123 160 var allele = sentence.Substring(i, 5); 124 161 if (alleleStatistics.ContainsKey(allele)) alleleStatistics[allele]++; … … 166 203 private static void WriteAlleleStatistics() { 167 204 double count = alleleStatistics.Sum(e => e.Value); 168 foreach (var entry in alleleStatistics.OrderByDescending(e =>e.Value)) {205 foreach (var entry in alleleStatistics.OrderByDescending(e => e.Value)) { 169 206 Console.WriteLine("{0,-10} {1,-10}", entry.Key, entry.Value); 170 207 }
Note: See TracChangeset
for help on using the changeset viewer.