- Timestamp:
- 01/27/15 16:34:34 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r11806 r11832 24 24 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 25 25 26 RunDemo();27 //RunGridTest();26 //RunDemo(); 27 RunGridTest(); 28 28 } 29 29 30 30 private static void RunGridTest() { 31 int maxIterations = 50000; // for poly-10 with 50000 evaluations no successful try with hl yet31 int maxIterations = 70000; // for poly-10 with 50000 evaluations no successful try with hl yet 32 32 //var globalRandom = new Random(31415); 33 33 var localRandSeed = 31415; 34 var reps = 10;34 var reps = 30; 35 35 36 36 var policyFactories = new Func<IBanditPolicy>[] … … 109 109 { 110 110 //(rand) => Tuple.Create((IProblem)new SantaFeAntProblem(), 17), 111 (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:false ), 15),112 (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:true ), 15),113 (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:false), 15),114 (rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:true), 15),115 //(rand) => Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23)111 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:false ), 15), 112 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:0, correctReward:1, decoyReward:0, phrasesAsSets:true ), 15), 113 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:false), 15), 114 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:true), 15), 115 (rand) => Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23) 116 116 }; 117 117 118 118 foreach (var instanceFactory in instanceFactories) { 119 foreach (var useCanonical in new bool[] { true /*, false */ 120 foreach (var randomTries in new int[] { 0 , /* 1, 10, /* 5, 100 /*, 500, 1000 */}) {119 foreach (var useCanonical in new bool[] { true /*, false */}) { 120 foreach (var randomTries in new int[] { 0 /*, 1, 10 /*, /* 5, 100 /*, 500, 1000 */}) { 121 121 foreach (var policyFactory in policyFactories) { 122 122 var myRandomTries = randomTries; … … 142 142 var problem = instance.Item1; 143 143 var maxLen = instance.Item2; 144 var alg = new SequentialSearch(problem, maxLen, myLocalRand, myRandomTries, 145 new GenericGrammarPolicy(problem, policyFactory(), useCanonical)); 144 //var alg = new SequentialSearch(problem, maxLen, myLocalRand, myRandomTries, 145 // new GenericGrammarPolicy(problem, policyFactory(), useCanonical)); 146 var alg = new SequentialSearch(problem, maxLen, myLocalRand, 147 myRandomTries, 148 new GenericFunctionApproximationGrammarPolicy(problem, 149 useCanonical)); 146 150 //var alg = new ExhaustiveBreadthFirstSearch(problem, 25); 147 151 //var alg = new AlternativesContextSampler(problem, 25); … … 150 154 iterations++; 151 155 globalStatistics.AddSentence(sentence, quality); 152 if (iterations % 1000 0== 0) {153 Console.WriteLine("{0,3} {1,5} \"{2,25}\" {3} {4} ", i, myRandomTries, policyFactory(), useCanonical, globalStatistics);156 if (iterations % 1000 == 0) { 157 Console.WriteLine("{0,3} {1,5} \"{2,25}\" {3} {4} {5}", i, myRandomTries, policyFactory(), useCanonical, problem.ToString(), globalStatistics); 154 158 } 155 159 }; … … 190 194 191 195 192 int maxIterations = 100000 ;196 int maxIterations = 1000000; 193 197 int iterations = 0; 194 198 var sw = new Stopwatch(); … … 199 203 200 204 //var problem = new RoyalSequenceProblem(random, 10, 30, 2, 1, 0); 205 // var phraseLen = 3; 206 // var numPhrases = 5; 207 // var problem = new RoyalPhraseSequenceProblem(random, 10, numPhrases, phraseLen: phraseLen, numCorrectPhrases: 1, correctReward: 1, incorrectReward: 0.0, phrasesAsSets: false); 208 201 209 //var phraseLen = 3; 202 210 //var numPhrases = 5; 203 //var problem = new RoyalPhraseSequenceProblem(random, 15, numPhrases, phraseLen: phraseLen, numCorrectPhrases: 1, correctReward: 1, incorrectReward: 0.0, phrasesAsSets: true); 204 205 // var phraseLen = 3; 206 // var numPhrases = 5; 207 // var problem = new FindPhrasesProblem(random, 10, numPhrases, phraseLen, numOptimalPhrases: numPhrases, numDecoyPhrases: 200, correctReward: 1.0, decoyReward: 0.5, phrasesAsSets: true); 211 //var problem = new FindPhrasesProblem(random, 10, numPhrases, phraseLen, numOptimalPhrases: numPhrases, numDecoyPhrases: 0, correctReward: 1.0, decoyReward: 0, phrasesAsSets: false); 208 212 209 213 // good results for symb-reg … … 213 217 // - GenericThompsonSamplingPolicy("") 214 218 // - UCTPolicy(0.10) (5 of 5 runs, 35000 iters avg.), 10 successful runs of 10 with rand-tries 0, bei 40000 iters 9 / 10, bei 30000 1 / 10 219 // 2015 01 22: symb-reg: grid test on find-phrases problem showed good results for UCB1TunedPolicy and SequentialSearch with canonical states 220 // - symb-reg: consistent results with UCB1Tuned. finds optimal solution in ~50k iters (new GenericGrammarPolicy(problem, new UCB1TunedPolicy(), true)); 221 // 2015 01 23: grid test with canonical states: 222 // - UCTPolicy(0.10) und UCBNormalPolicy 10/10 optimale Lösungen bei max. 50k iters, etwas schlechter: generic-thompson with variable sigma und bolzmannexploration (100) 223 215 224 216 225 // good results for artificial ant: … … 219 228 // - GaussianModelWithUnknownVariance (and Q= 0.99-quantil) also works well for Ant 220 229 // 2015 01 19: grid test with canonical states (non-canonical slightly worse) 221 // - Threshold Ascent (best 100, 0.01; all variants relatively good)222 // - Policies where the variance has a large weight compared to the mean? (Gaussian(compatible), Gaussian with fixed variance, UCT with large c, alle TA)223 224 //var problem = new SymbolicRegressionPoly10Problem(); 225 226 var problem = new SantaFeAntProblem();227 //var problem = new SymbolicRegressionProblem( "Tower");230 // - ant: Threshold Ascent (best 100, 0.01; all variants relatively good) 231 // - ant: Policies where the variance has a large weight compared to the mean? (Gaussian(compatible), Gaussian with fixed variance, UCT with large c, alle TA) 232 // - ant: UCB1Tuned with canonical states also works very well for the artificial ant! constistent solutions in less than 10k iters 233 234 var problem = new SymbolicRegressionPoly10Problem(); 235 //var problem = new SantaFeAntProblem(); 236 //var problem = new SymbolicRegressionProblem(random, "Tower"); 228 237 //var problem = new PalindromeProblem(); 229 238 //var problem = new HardPalindromeProblem(); … … 234 243 //var alg = new MctsSampler(problem, 23, random, 0, new EpsGreedyPolicy(0.1)); 235 244 //var alg = new SequentialSearch(problem, 23, random, 0, 236 // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new ModifiedUCTPolicy(0.1), true)); 237 var alg = new SequentialSearch(problem, 17, random, 0, 238 new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericTDPolicy(problem, true)); 245 // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.QLearningGrammarPolicy(problem, new BoltzmannExplorationPolicy(10), 246 // 1, 1, true)); 247 //var alg = new SequentialSearch(problem, 23, random, 0, 248 // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericContextualGrammarPolicy(problem, new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1, 1)), true)); 249 var alg = new SequentialSearch(problem, 23, random, 0, 250 new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericFunctionApproximationGrammarPolicy(problem, true)); 239 251 //var alg = new MctsQLearningSampler(problem, sentenceLen, random, 0, null); 240 252 //var alg = new MctsQLearningSampler(problem, 30, random, 0, new EpsGreedyPolicy(0.2)); … … 249 261 250 262 alg.FoundNewBestSolution += (sentence, quality) => { 251 //Console.WriteLine("{0 ,4} {1,7} {2}", alg.treeDepth, alg.treeSize, globalStatistics);263 //Console.WriteLine("{0}", globalStatistics); 252 264 //Console.ReadLine(); 253 265 }; … … 255 267 iterations++; 256 268 globalStatistics.AddSentence(sentence, quality); 269 257 270 if (iterations % 1000 == 0) { 258 271 if (iterations % 10000 == 0) Console.Clear(); … … 260 273 alg.PrintStats(); 261 274 } 275 262 276 //Console.WriteLine(sentence); 263 277 264 if (iterations % 10000 == 0) {265 //Console.WriteLine("{0,4} {1,7} {2}", alg.treeDepth, alg.treeSize, globalStatistics);266 }278 //if (iterations % 10000 == 0) { 279 // Console.WriteLine("{0}", globalStatistics); 280 //} 267 281 }; 268 282
Note: See TracChangeset
for help on using the changeset viewer.