Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12354


Ignore:
Timestamp:
04/28/15 18:17:20 (9 years ago)
Author:
gkronber
Message:

prepared unit test to produce results for artificial ant and symbolic regression and all possible different bandit policies

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Test/RunMctsExperiments.cs

    r12289 r12354  
    22using System.Collections;
    33using System.Collections.Generic;
     4using System.Globalization;
     5using HeuristicLab.Algorithms.Bandits;
    46using HeuristicLab.Algorithms.Bandits.BanditPolicies;
    57using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
     8using HeuristicLab.Algorithms.Bandits.Models;
    69using HeuristicLab.Algorithms.GeneticProgramming;
    710using HeuristicLab.Algorithms.GrammaticalOptimization;
     
    912using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
    1013using Microsoft.VisualStudio.TestTools.UnitTesting;
     14using RandomPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.RandomPolicy;
    1115
    1216namespace HeuristicLab.Problems.GrammaticalOptimization.Test {
     
    1822    internal class Configuration {
    1923      public ISymbolicExpressionTreeProblem Problem;
     24      public IBanditPolicy Policy;
    2025      public int MaxSize;
    2126      public int RandSeed;
    2227
    2328      public override string ToString() {
    24         return string.Format("{0} {1} {2}", RandSeed, Problem, MaxSize);
    25       }
    26     }
    27 
     29        return string.Format("{0} {1} {2} {3}", RandSeed, Problem, Policy, MaxSize);
     30      }
     31    }
     32
     33    private Func<IBanditPolicy>[] policyFactories = new Func<IBanditPolicy>[]
     34    {
     35          () => new RandomPolicy(),
     36          () => new ActiveLearningPolicy(), 
     37         () => new GaussianThompsonSamplingPolicy(true),
     38         () => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1)),
     39         () => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1, 1)),
     40         () => new GenericThompsonSamplingPolicy(new BernoulliModel(1, 1)),
     41         () => new EpsGreedyPolicy(0.01),
     42         () => new EpsGreedyPolicy(0.05),
     43         () => new EpsGreedyPolicy(0.1),
     44         () => new EpsGreedyPolicy(0.2),
     45         () => new EpsGreedyPolicy(0.5),
     46         () => new UCTPolicy(0.01),
     47         () => new UCTPolicy(0.05),
     48         () => new UCTPolicy(0.1),
     49         () => new UCTPolicy(0.5),
     50         () => new UCTPolicy(1),
     51         () => new UCTPolicy(2),
     52         () => new UCTPolicy( 5),
     53         () => new UCTPolicy( 10),
     54         () => new ModifiedUCTPolicy(0.01),
     55         () => new ModifiedUCTPolicy(0.05),
     56         () => new ModifiedUCTPolicy(0.1),
     57         () => new ModifiedUCTPolicy(0.5),
     58         () => new ModifiedUCTPolicy(1),
     59         () => new ModifiedUCTPolicy(2),
     60         () => new ModifiedUCTPolicy( 5),
     61         () => new ModifiedUCTPolicy( 10),
     62         () => new UCB1Policy(),
     63         () => new UCB1TunedPolicy(),
     64         () => new UCBNormalPolicy(),
     65         () => new BoltzmannExplorationPolicy(1),
     66         () => new BoltzmannExplorationPolicy(10),
     67         () => new BoltzmannExplorationPolicy(20),
     68         () => new BoltzmannExplorationPolicy(100),
     69         () => new BoltzmannExplorationPolicy(200),
     70         () => new BoltzmannExplorationPolicy(500),
     71          () => new ChernoffIntervalEstimationPolicy( 0.01),
     72          () => new ChernoffIntervalEstimationPolicy( 0.05),
     73          () => new ChernoffIntervalEstimationPolicy( 0.1),
     74          () => new ChernoffIntervalEstimationPolicy( 0.2),
     75         () => new ThresholdAscentPolicy(5, 0.01),
     76         () => new ThresholdAscentPolicy(5, 0.05),
     77         () => new ThresholdAscentPolicy(5, 0.1),
     78         () => new ThresholdAscentPolicy(5, 0.2),
     79         () => new ThresholdAscentPolicy(10, 0.01),
     80         () => new ThresholdAscentPolicy(10, 0.05),
     81         () => new ThresholdAscentPolicy(10, 0.1),
     82         () => new ThresholdAscentPolicy(10, 0.2),
     83         () => new ThresholdAscentPolicy(50, 0.01),
     84         () => new ThresholdAscentPolicy(50, 0.05),
     85         () => new ThresholdAscentPolicy(50, 0.1),
     86         () => new ThresholdAscentPolicy(50, 0.2),
     87         () => new ThresholdAscentPolicy(100, 0.01),
     88         () => new ThresholdAscentPolicy(100, 0.05),
     89         () => new ThresholdAscentPolicy(100, 0.1),
     90         () => new ThresholdAscentPolicy(100, 0.2),
     91         () => new ThresholdAscentPolicy(500, 0.01),
     92         () => new ThresholdAscentPolicy(500, 0.05),
     93         () => new ThresholdAscentPolicy(500, 0.1),
     94         () => new ThresholdAscentPolicy(500, 0.2),
     95         () => new ThresholdAscentPolicy(5000, 0.01),
     96         () => new ThresholdAscentPolicy(10000, 0.01), 
     97    };
    2898
    2999    #region artificial ant
    30100    [TestMethod]
     101    [Timeout(1000 * 60 * 60 * 72)] // 72 hours
    31102    public void RunSeqSolvFuncApproxArtificialAntProblem() {
     103      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
     104
    32105      var instanceFactories = new Func<int, ISymbolicExpressionTreeProblem>[]
    33106      {
     
    39112      int maxIterations = 100000; // randomsearch finds the optimum almost always for 100000 evals
    40113      foreach (var instanceFactory in instanceFactories) {
    41         foreach (var conf in GenerateConfigurations(instanceFactory, nReps, maxSizes)) {
    42           RunMctsForProblem(conf.RandSeed, conf.Problem, maxIterations, conf.MaxSize);
     114        foreach (var policyFactory in policyFactories) {
     115          foreach (var conf in GenerateConfigurations(instanceFactory, policyFactory, nReps, maxSizes)) {
     116            RunMctsForProblem(conf.RandSeed, conf.Problem, conf.Policy, maxIterations, conf.MaxSize);
     117          }
    43118        }
    44119      }
     
    49124    #region symb-reg-poly-10
    50125    [TestMethod]
     126    [Timeout(1000 * 60 * 60 * 72)] // 72 hours
    51127    public void RunSeqSolvFuncApproxPoly10Problem() {
     128      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
     129
    52130      var instanceFactories = new Func<int, ISymbolicExpressionTreeProblem>[]
    53131      {
     
    57135      var maxSizes = new int[] { 23 }; // size of sequential representation is 23
    58136      int nReps = 30;
    59       int maxIterations = 200000; // sequentialsearch should find the optimum within 100000 evals
     137      int maxIterations = 100000; // sequentialsearch should find the optimum within 100000 evals
    60138      foreach (var instanceFactory in instanceFactories) {
    61         foreach (var conf in GenerateConfigurations(instanceFactory, nReps, maxSizes)) {
    62           RunMctsForProblem(conf.RandSeed, conf.Problem, maxIterations, conf.MaxSize);
     139        foreach (var policyFactory in policyFactories) {
     140          foreach (var conf in GenerateConfigurations(instanceFactory, policyFactory, nReps, maxSizes)) {
     141            RunMctsForProblem(conf.RandSeed, conf.Problem, conf.Policy, maxIterations, conf.MaxSize);
     142          }
    63143        }
    64144      }
     
    68148
    69149    #region helpers
    70     private IEnumerable<Configuration> GenerateConfigurations(Func<int, ISymbolicExpressionTreeProblem> problemFactory,
     150    private IEnumerable<Configuration> GenerateConfigurations(
     151      Func<int, ISymbolicExpressionTreeProblem> problemFactory,
     152      Func<IBanditPolicy> policyFactory,
    71153      int nReps,
    72154      IEnumerable<int> maxSizes
     
    85167            MaxSize = maxSize,
    86168            Problem = problemFactory(problemSeed),
     169            Policy = policyFactory(),
    87170            RandSeed = solverSeed
    88171          };
     
    94177      int randSeed,
    95178      IProblem problem,
     179      IBanditPolicy policy,
    96180      int maxIters,
    97181      int maxSize
    98182      ) {
    99183      var solver = new SequentialSearch(problem, maxSize, new Random(randSeed), 0,
    100         new GenericGrammarPolicy(problem, new UCB1Policy(), false));
     184        new GenericGrammarPolicy(problem, policy, false));
    101185      var problemName = problem.GetType().Name;
    102186      var bestKnownQuality = problem.BestKnownQuality(maxSize);
Note: See TracChangeset for help on using the changeset viewer.