Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 07:03:15 (10 years ago)
Author:
gkronber
Message:

#2283: constant opt, expressioncompiler, autodiff, fixes in GP solvers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs

    r11865 r11895  
    33using System.Diagnostics;
    44using System.Globalization;
     5using System.Runtime.Remoting.Messaging;
    56using System.Text;
    67using System.Threading;
     
    1314using HeuristicLab.Algorithms.GrammaticalOptimization;
    1415using HeuristicLab.Problems.GrammaticalOptimization;
     16using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
    1517using BoltzmannExplorationPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.BoltzmannExplorationPolicy;
    1618using EpsGreedyPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.EpsGreedyPolicy;
     
    2527
    2628      //RunDemo();
    27       //RunGpDemo();
     29      RunGpDemo();
    2830      // RunGridTest();
    29       RunGpGridTest();
     31      //RunGpGridTest();
    3032    }
    3133
     
    297299      const int maxIterations = 100000;
    298300
     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);
    299305    }
    300306
     
    303309      const int nReps = 20;
    304310      const int seed = 31415;
    305       const int maxIters = 100000;
     311      const int maxIters = 200000;
    306312      var rand = new Random(seed);
    307313      var problemFactories = new Func<ISymbolicExpressionTreeProblem>[]
    308314      {
     315        () => new SymbolicRegressionPoly10Problem(),
    309316        () => 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                  // }
    321336                }
    322                 {
    323                   var prob = problemFactory();
    324                   RunOSGP(prob, solverSeed, maxIters, popSize, mutationRate, maxSize);
    325                 }
    326               }
     337            }
    327338          }
    328339        }
     
    330341    }
    331342
    332     private static void RunStandardGP(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) {
    333344      int iterations = 0;
    334345      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;
    337348      gp.SolutionEvaluated += (sentence, quality) => {
    338349        iterations++;
    339350        globalStatistics.AddSentence(sentence, quality);
    340351
    341         if (iterations % 10000 == 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);
    343354        }
    344355      };
     
    349360      gp.MaxSolutionDepth = maxSize + 2;
    350361
    351       var sw = new Stopwatch();
    352 
    353       sw.Start();
    354362      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);
    396363    }
    397364  }
Note: See TracChangeset for help on using the changeset viewer.