- Timestamp:
- 02/11/15 13:06:02 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs
r11977 r11980 61 61 } 62 62 63 64 65 const double beta = 20;63 64 /* 65 const double beta = 10; 66 66 var w = from idx in Enumerable.Range(0, maxIdx) 67 67 let afterStateQ = activeAfterStates[idx] … … 71 71 selectedStateIdx = actionIndexMap[bestAction]; 72 72 Debug.Assert(selectedStateIdx >= 0); 73 74 75 /*76 if (random.NextDouble() < 0. 2) {73 */ 74 75 76 if (random.NextDouble() < 0.5) { 77 77 selectedStateIdx = actionIndexMap[random.Next(maxIdx)]; 78 78 } else { … … 91 91 selectedStateIdx = actionIndexMap[bestIdxs[random.Next(bestIdxs.Count)]]; 92 92 } 93 */93 94 94 return true; 95 95 } … … 140 140 double delta = reward - GetValue(state); 141 141 // delta /= problem.GetFeatures(state).Count(); 142 //const double alpha = 0.0 1;142 //const double alpha = 0.001; 143 143 foreach (var feature in problem.GetFeatures(state)) { 144 144 featureTries[feature.Id] = GetFeatureTries(feature.Id) + 1; -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs
r11851 r11980 184 184 Debug.Assert(maxLenOfReplacement > 0); 185 185 186 var alts = Get Alternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement);186 var alts = GetTerminalAlternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement); 187 187 Debug.Assert(alts.Any()); 188 188 -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs
r11977 r11980 123 123 124 124 public string CanonicalRepresentation(string phrase) { 125 phrase = phrase.Replace("A", ".");125 //phrase = phrase.Replace("A", "."); 126 126 var sb = new StringBuilder(phrase); 127 127 string canonicalPhrase = phrase; … … 133 133 canonicalPhrase = sb.ToString(); 134 134 } while (canonicalPhrase != oldPhrase); 135 return sb.ToString();135 return canonicalPhrase; 136 136 } 137 137 … … 141 141 142 142 143 //yield return new Feature("const", 0.0);143 yield return new Feature(isTerminal + ToString(), 1.0); 144 144 //if (phrase.Length > 0) { 145 145 // var ant = new Ant(recordTrail: true); … … 157 157 //} 158 158 // 159 ////yield return new Feature("$" + phrase[0], 1.0);160 //if (!isTerminal) {161 //for (int i = 4; i < phrase.Length; i++) {162 // if (grammar.IsNonTerminal(phrase[i])) {163 // yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 0.1);164 //break;165 //}166 //}167 //}159 yield return new Feature("$" + (phrase.Length > 0 ? phrase[0] : ' '), 1.0); 160 if (!isTerminal) { 161 for (int i = 4; i < phrase.Length; i++) { 162 if (!grammar.IsTerminal(phrase[i])) { 163 yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 1.0); 164 break; 165 } 166 } 167 } 168 168 // var d = 0; 169 169 // var ls = 0; -
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r11977 r11980 179 179 180 180 private static void RunDemo() { 181 // TODO: unify MCTS, TD and ContextMCTS Solvers (stateInfos) 182 // TODO: test with eps-greedy using max instead of average as value (seems to work well for symb-reg! explore further!) 183 // TODO: separate value function from policy 184 // TODO: warum funktioniert die alte Implementierung von GaussianThompson besser fÃŒr SantaFe als neue? Siehe Vergleich: alte vs. neue implementierung GaussianThompsonSampling 181 // TODO: cleanup nach EuroCAST 185 182 // TODO: why does GaussianThompsonSampling work so well with MCTS for the artificial ant problem? 186 183 // TODO: research thompson sampling for max bandit? … … 316 313 { 317 314 () => Tuple.Create(100000, 23, (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()), 318 () => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()),315 //() => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()), 319 316 //() => Tuple.Create(50000, 32,(ISymbolicExpressionTreeProblem)new RoyalSymbolProblem()), 320 317 //() => Tuple.Create(50000, 64, (ISymbolicExpressionTreeProblem)new RoyalPairProblem()), … … 345 342 int iterations = 0; 346 343 double bestQuality = double.NegativeInfinity; 347 var globalStatistics = new SentenceSetStatistics( prob.BestKnownQuality(maxSize));344 var globalStatistics = new SentenceSetStatistics(); 348 345 var algName = alg.GetType().Name; 349 346 var probName = prob.GetType().Name; … … 358 355 //} 359 356 //Console.WriteLine("{0:N5} {1}", quality, sentence); 360 if (iterations % 200 == 0) {357 if (iterations % 1000 == 0) { 361 358 Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics); 362 359 if (bestQuality.IsAlmost(1.0)) { … … 368 365 alg.Run(maxIters); 369 366 367 368 while (iterations < maxIters) { 369 iterations++; 370 globalStatistics.AddSentence("BEST", bestQuality); 371 if (iterations % 1000 == 0) { 372 Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics); 373 if (bestQuality.IsAlmost(1.0)) { 374 alg.StopRequested = true; 375 } 376 } 377 } 370 378 } 371 372 379 } 373 380 }
Note: See TracChangeset
for help on using the changeset viewer.