Changeset 11977
- Timestamp:
- 02/11/15 03:01:59 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs
r11976 r11977 62 62 63 63 64 /*65 const double beta = 1;64 65 const double beta = 20; 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 73 74 75 /* 76 76 if (random.NextDouble() < 0.2) { 77 77 selectedStateIdx = actionIndexMap[random.Next(maxIdx)]; … … 91 91 selectedStateIdx = actionIndexMap[bestIdxs[random.Next(bestIdxs.Count)]]; 92 92 } 93 94 95 96 93 */ 97 94 return true; 98 95 } … … 132 129 133 130 public double GetValue(string state) { 134 return problem.GetFeatures(state). Average(feature => GetWeight(feature));131 return problem.GetFeatures(state).Sum(feature => GetWeight(feature)); 135 132 } 136 133 … … 142 139 private void UpdateWeights(string state, double reward) { 143 140 double delta = reward - GetValue(state); 144 delta /= problem.GetFeatures(state).Count();145 const double alpha = 0.001;141 // delta /= problem.GetFeatures(state).Count(); 142 //const double alpha = 0.01; 146 143 foreach (var feature in problem.GetFeatures(state)) { 147 144 featureTries[feature.Id] = GetFeatureTries(feature.Id) + 1; 148 145 Debug.Assert(GetFeatureTries(feature.Id) >= 1); 149 //double alpha = 1.0 / GetFeatureTries(feature.Id);150 //alpha = Math.Max(alpha, 0.01);146 double alpha = 1.0 / GetFeatureTries(feature.Id); 147 alpha = Math.Max(alpha, 0.001); 151 148 152 149 double w; -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/Solvers/SequentialSearch.cs
r11976 r11977 62 62 } 63 63 64 public bool StopRequested { 65 get; 66 set; 67 } 68 64 69 public override void Run(int maxIterations) { 65 70 Reset(); 66 71 67 for (int i = 0; /*!bestQuality.IsAlmost(1.0) && */!Done() && i < maxIterations; i++) {72 for (int i = 0; !StopRequested && !Done() && i < maxIterations; i++) { 68 73 var phrase = SampleSentence(problem.Grammar); 69 74 // can fail on the last sentence … … 171 176 172 177 private void Reset() { 178 StopRequested = false; 173 179 behaviourPolicy.Reset(); 174 180 greedyPolicy.Reset(); … … 238 244 } 239 245 #endregion 240 246 241 247 } 242 248 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs
r11976 r11977 129 129 do { 130 130 oldPhrase = canonicalPhrase; 131 sb.Replace("ll", "rr").Replace("rl", "").Replace("lr", "").Replace("lll", "r").Replace("rrr", "l") ;132 sb.Replace("?(m)(m)", "?()()m").Replace("?(l)(l)", "?()()l").Replace("?(r)(r)", "?()()r").Replace("?()()", "");131 sb.Replace("ll", "rr").Replace("rl", "").Replace("lr", "").Replace("lll", "r").Replace("rrr", "l").Replace("?()()", ""); 132 //sb.Replace("?(m)(m)", "?()()m").Replace("?(l)(l)", "?()()l").Replace("?(r)(r)", "?()()r"); 133 133 canonicalPhrase = sb.ToString(); 134 134 } while (canonicalPhrase != oldPhrase); -
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Main.csproj
r11849 r11977 56 56 <Name>HeuristicLab.Algorithms.GrammaticalOptimization</Name> 57 57 </ProjectReference> 58 <ProjectReference Include="..\HeuristicLab.Common\HeuristicLab.Common.csproj"> 59 <Project>{3A2FBBCB-F9DF-4970-87F3-F13337D941AD}</Project> 60 <Name>HeuristicLab.Common</Name> 61 </ProjectReference> 58 62 <ProjectReference Include="..\HeuristicLab.Distributions\HeuristicLab.Distributions.csproj"> 59 63 <Project>{31171165-E16F-4A1A-A8AB-25C6AB3A71B9}</Project> -
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r11976 r11977 13 13 using HeuristicLab.Algorithms.GeneticProgramming; 14 14 using HeuristicLab.Algorithms.GrammaticalOptimization; 15 using HeuristicLab.Common; 15 16 using HeuristicLab.Problems.GrammaticalOptimization; 16 17 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; … … 30 31 // RunGridTest(); 31 32 //RunGpGridTest(); 32 RunFunApproxTest();33 RunFunApproxTest(); 33 34 } 34 35 … … 308 309 309 310 private static void RunFunApproxTest() { 310 const int nReps = 20;311 const int nReps = 30; 311 312 const int seed = 31415; 312 313 //const int maxIters = 50000; … … 314 315 var problemFactories = new Func<Tuple<int, int, ISymbolicExpressionTreeProblem>>[] 315 316 { 316 //() => Tuple.Create(100000, 23, (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()),317 () => Tuple.Create(100000, 23, (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()), 317 318 () => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()), 318 319 //() => Tuple.Create(50000, 32,(ISymbolicExpressionTreeProblem)new RoyalSymbolProblem()), … … 330 331 331 332 // skip experiments that are already done 332 for each (var problemFactory in problemFactories) {333 for (int i = 0; i < nReps; i++) {333 for (int i = 0; i < nReps; i++) { 334 foreach (var problemFactory in problemFactories) { 334 335 { 335 336 var solverSeed = rand.Next(); … … 343 344 344 345 int iterations = 0; 346 double bestQuality = double.NegativeInfinity; 345 347 var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize)); 346 348 var algName = alg.GetType().Name; 347 349 var probName = prob.GetType().Name; 348 350 alg.SolutionEvaluated += (sentence, quality) => { 351 bestQuality = Math.Max(bestQuality, quality); 349 352 iterations++; 350 353 globalStatistics.AddSentence(sentence, quality); … … 357 360 if (iterations % 200 == 0) { 358 361 Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics); 362 if (bestQuality.IsAlmost(1.0)) { 363 alg.StopRequested = true; 364 } 359 365 } 360 366 };
Note: See TracChangeset
for help on using the changeset viewer.