Changeset 12354 for branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Test/RunMctsExperiments.cs
- Timestamp:
- 04/28/15 18:17:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Test/RunMctsExperiments.cs
r12289 r12354 2 2 using System.Collections; 3 3 using System.Collections.Generic; 4 using System.Globalization; 5 using HeuristicLab.Algorithms.Bandits; 4 6 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 5 7 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 8 using HeuristicLab.Algorithms.Bandits.Models; 6 9 using HeuristicLab.Algorithms.GeneticProgramming; 7 10 using HeuristicLab.Algorithms.GrammaticalOptimization; … … 9 12 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; 10 13 using Microsoft.VisualStudio.TestTools.UnitTesting; 14 using RandomPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.RandomPolicy; 11 15 12 16 namespace HeuristicLab.Problems.GrammaticalOptimization.Test { … … 18 22 internal class Configuration { 19 23 public ISymbolicExpressionTreeProblem Problem; 24 public IBanditPolicy Policy; 20 25 public int MaxSize; 21 26 public int RandSeed; 22 27 23 28 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 }; 28 98 29 99 #region artificial ant 30 100 [TestMethod] 101 [Timeout(1000 * 60 * 60 * 72)] // 72 hours 31 102 public void RunSeqSolvFuncApproxArtificialAntProblem() { 103 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 104 32 105 var instanceFactories = new Func<int, ISymbolicExpressionTreeProblem>[] 33 106 { … … 39 112 int maxIterations = 100000; // randomsearch finds the optimum almost always for 100000 evals 40 113 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 } 43 118 } 44 119 } … … 49 124 #region symb-reg-poly-10 50 125 [TestMethod] 126 [Timeout(1000 * 60 * 60 * 72)] // 72 hours 51 127 public void RunSeqSolvFuncApproxPoly10Problem() { 128 CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 129 52 130 var instanceFactories = new Func<int, ISymbolicExpressionTreeProblem>[] 53 131 { … … 57 135 var maxSizes = new int[] { 23 }; // size of sequential representation is 23 58 136 int nReps = 30; 59 int maxIterations = 200000; // sequentialsearch should find the optimum within 100000 evals137 int maxIterations = 100000; // sequentialsearch should find the optimum within 100000 evals 60 138 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 } 63 143 } 64 144 } … … 68 148 69 149 #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, 71 153 int nReps, 72 154 IEnumerable<int> maxSizes … … 85 167 MaxSize = maxSize, 86 168 Problem = problemFactory(problemSeed), 169 Policy = policyFactory(), 87 170 RandSeed = solverSeed 88 171 }; … … 94 177 int randSeed, 95 178 IProblem problem, 179 IBanditPolicy policy, 96 180 int maxIters, 97 181 int maxSize 98 182 ) { 99 183 var solver = new SequentialSearch(problem, maxSize, new Random(randSeed), 0, 100 new GenericGrammarPolicy(problem, new UCB1Policy(), false));184 new GenericGrammarPolicy(problem, policy, false)); 101 185 var problemName = problem.GetType().Name; 102 186 var bestKnownQuality = problem.BestKnownQuality(maxSize);
Note: See TracChangeset
for help on using the changeset viewer.