- Timestamp:
- 02/05/15 07:03:15 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs
r11865 r11895 3 3 using System.Diagnostics; 4 4 using System.Globalization; 5 using System.Runtime.Remoting.Messaging; 5 6 using System.Text; 6 7 using System.Threading; … … 13 14 using HeuristicLab.Algorithms.GrammaticalOptimization; 14 15 using HeuristicLab.Problems.GrammaticalOptimization; 16 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; 15 17 using BoltzmannExplorationPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationPolicy; 16 18 using EpsGreedyPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.EpsGreedyPolicy; … … 25 27 26 28 //RunDemo(); 27 //RunGpDemo();29 RunGpDemo(); 28 30 // RunGridTest(); 29 RunGpGridTest();31 //RunGpGridTest(); 30 32 } 31 33 … … 297 299 const int maxIterations = 100000; 298 300 301 //var prob = new SymbolicRegressionProblem(new Random(31415), "Tower"); 302 var prob = new SymbolicRegressionPoly10Problem(); 303 var sgp = new OffspringSelectionGP(prob, new Random(seed), true); 304 RunGP(sgp, prob, 200000, 500, 0.15, 50); 299 305 } 300 306 … … 303 309 const int nReps = 20; 304 310 const int seed = 31415; 305 const int maxIters = 100000;311 const int maxIters = 200000; 306 312 var rand = new Random(seed); 307 313 var problemFactories = new Func<ISymbolicExpressionTreeProblem>[] 308 314 { 315 () => new SymbolicRegressionPoly10Problem(), 309 316 () => new SantaFeAntProblem(), 310 () => new SymbolicRegressionPoly10Problem(), 311 }; 312 foreach (var popSize in new int[] { 50, 100, 250, 500, 1000, 2500, 5000 }) { 313 foreach (var mutationRate in new double[] {/* 0.05, 0.10, */ 0.15, /* 0.25, 0.3 */ }) { 314 foreach (var maxSize in new int[] { 30, 50, 100 }) { 315 foreach (var problemFactory in problemFactories) 316 for (int i = 0; i < nReps; i++) { 317 var solverSeed = rand.Next(); 318 { 319 var prob = problemFactory(); 320 RunStandardGP(prob, solverSeed, maxIters, popSize, mutationRate, maxSize); 317 }; 318 foreach (var popSize in new int[] { 50, 100, 250, 500, 1000, 2500, 5000, 10000 }) { 319 foreach (var mutationRate in new double[] { /* 0.05, /* 0.10, */ 0.15, /* 0.25, 0.3 */}) { 320 foreach (var maxSize in new int[] { 30, 50, 100, 150, 250 }) { 321 // skip experiments that are already done 322 if (popSize == 10000 || maxSize == 150 || maxSize == 250) { 323 foreach (var problemFactory in problemFactories) 324 for (int i = 0; i < nReps; i++) { 325 var solverSeed = rand.Next(); 326 { 327 var prob = problemFactory(); 328 var sgp = new StandardGP(prob, new Random(solverSeed)); 329 RunGP(sgp, prob, maxIters, popSize, mutationRate, maxSize); 330 } 331 // { 332 // var prob = problemFactory(); 333 // var osgp = new OffspringSelectionGP(prob, new Random(solverSeed)); 334 // RunGP(osgp, prob, maxIters, popSize, mutationRate, maxSize); 335 // } 321 336 } 322 { 323 var prob = problemFactory(); 324 RunOSGP(prob, solverSeed, maxIters, popSize, mutationRate, maxSize); 325 } 326 } 337 } 327 338 } 328 339 } … … 330 341 } 331 342 332 private static void Run StandardGP(ISymbolicExpressionTreeProblem prob, int solverSeed, int maxIters, int popSize, double mutationRate, int maxSize) {343 private static void RunGP(IGPSolver gp, ISymbolicExpressionTreeProblem prob, int maxIters, int popSize, double mutationRate, int maxSize) { 333 344 int iterations = 0; 334 345 var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize)); 335 336 var gp = new StandardGP(prob, new Random(solverSeed));346 var gpName = gp.GetType().Name; 347 var probName = prob.GetType().Name; 337 348 gp.SolutionEvaluated += (sentence, quality) => { 338 349 iterations++; 339 350 globalStatistics.AddSentence(sentence, quality); 340 351 341 if (iterations % 1000 0== 0) {342 Console.WriteLine("\"{0,25}\" \"{1,25}\" {2}", gp, prob, globalStatistics);352 if (iterations % 1000 == 0) { 353 Console.WriteLine("\"{0,25}\" {1} {2:N2} {3} \"{4,25}\" {5}", gpName, popSize, mutationRate, maxSize, probName, globalStatistics); 343 354 } 344 355 }; … … 349 360 gp.MaxSolutionDepth = maxSize + 2; 350 361 351 var sw = new Stopwatch();352 353 sw.Start();354 362 gp.Run(maxIters); 355 sw.Stop();356 357 Console.WriteLine("\"{0,25}\" \"{1,25}\" {2}", gp, prob, globalStatistics);358 359 // Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",360 // sw.Elapsed.TotalSeconds,361 // maxIters / (double)sw.Elapsed.TotalSeconds,362 // (double)sw.ElapsedMilliseconds * 1000 / maxIters);363 }364 365 private static void RunOSGP(ISymbolicExpressionTreeProblem prob, int solverSeed, int maxIters, int popSize, double mutationRate, int maxSize) {366 int iterations = 0;367 var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize));368 369 var gp = new OffspringSelectionGP(prob, new Random(solverSeed));370 gp.SolutionEvaluated += (sentence, quality) => {371 iterations++;372 globalStatistics.AddSentence(sentence, quality);373 374 if (iterations % 10000 == 0) {375 Console.WriteLine("\"{0,25}\" \"{1,25}\" {2}", gp, prob, globalStatistics);376 }377 };378 379 gp.PopulationSize = popSize;380 gp.MutationRate = mutationRate;381 gp.MaxSolutionSize = maxSize + 2;382 gp.MaxSolutionDepth = maxSize + 2;383 384 var sw = new Stopwatch();385 386 sw.Start();387 gp.Run(maxIters);388 sw.Stop();389 390 Console.WriteLine("\"{0,25}\" \"{1,25}\" {2}", gp, prob, globalStatistics);391 392 // Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",393 // sw.Elapsed.TotalSeconds,394 // maxIters / (double)sw.Elapsed.TotalSeconds,395 // (double)sw.ElapsedMilliseconds * 1000 / maxIters);396 363 } 397 364 }
Note: See TracChangeset
for help on using the changeset viewer.