- Timestamp:
- 02/16/15 09:14:38 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.GrammaticalOptimization/Test
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/Test/RunDemo.cs
r11981 r12014 7 7 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 8 8 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 9 using HeuristicLab.Algorithms.Bandits.Models; 9 10 using HeuristicLab.Algorithms.GrammaticalOptimization; 11 using Microsoft.VisualStudio.TestTools.UnitTesting; 12 using RandomPolicy = HeuristicLab.Algorithms.Bandits.BanditPolicies.RandomPolicy; 10 13 11 14 namespace HeuristicLab.Problems.GrammaticalOptimization.Test { 12 class RunDemo { 13 private static void RunGridTest() { 14 int maxIterations = 200000; // for poly-10 with 50000 evaluations no successful try with hl yet 15 [TestClass] 16 public class RunDemo { 17 [TestMethod] 18 public void RunGridTest() { 19 int maxIterations = 20000; // for poly-10 with 50000 evaluations no successful try with hl yet 15 20 //var globalRandom = new Random(31415); 16 21 var localRandSeed = new Random().Next(); … … 19 24 var policyFactories = new Func<IBanditPolicy>[] 20 25 { 21 //() => new RandomPolicy(),22 //() => new ActiveLearningPolicy(),23 //() => new EpsGreedyPolicy(0.01, (aInfo)=> aInfo.MaxReward, "max"),24 //() => new EpsGreedyPolicy(0.05, (aInfo)=> aInfo.MaxReward, "max"),25 //() => new EpsGreedyPolicy(0.1, (aInfo)=> aInfo.MaxReward, "max"),26 //() => new EpsGreedyPolicy(0.2, (aInfo)=> aInfo.MaxReward, "max"),27 // //() => new GaussianThompsonSamplingPolicy(),28 //() => new GaussianThompsonSamplingPolicy(true),29 //() => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1)),30 //() => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1, 1)),31 // //() => new BernoulliThompsonSamplingPolicy(),32 //() => new GenericThompsonSamplingPolicy(new BernoulliModel(1, 1)),33 //() => new EpsGreedyPolicy(0.01),34 //() => new EpsGreedyPolicy(0.05),35 //() => new EpsGreedyPolicy(0.1),36 //() => new EpsGreedyPolicy(0.2),37 //() => new EpsGreedyPolicy(0.5),38 //() => new UCTPolicy(0.01),39 //() => new UCTPolicy(0.05),40 //() => new UCTPolicy(0.1),41 //() => new UCTPolicy(0.5),42 //() => new UCTPolicy(1),43 //() => new UCTPolicy(2),44 //() => new UCTPolicy( 5),45 //() => new UCTPolicy( 10),46 //() => new ModifiedUCTPolicy(0.01),47 //() => new ModifiedUCTPolicy(0.05),48 //() => new ModifiedUCTPolicy(0.1),49 //() => new ModifiedUCTPolicy(0.5),50 //() => new ModifiedUCTPolicy(1),51 //() => new ModifiedUCTPolicy(2),52 //() => new ModifiedUCTPolicy( 5),53 //() => new ModifiedUCTPolicy( 10),54 //() => new UCB1Policy(),55 //() => new UCB1TunedPolicy(),56 //() => new UCBNormalPolicy(),57 //() => new BoltzmannExplorationPolicy(1),58 //() => new BoltzmannExplorationPolicy(10),59 //() => new BoltzmannExplorationPolicy(20),60 //() => new BoltzmannExplorationPolicy(100),61 //() => new BoltzmannExplorationPolicy(200),62 //() => new BoltzmannExplorationPolicy(500),63 //() => new ChernoffIntervalEstimationPolicy( 0.01),64 //() => new ChernoffIntervalEstimationPolicy( 0.05),65 //() => new ChernoffIntervalEstimationPolicy( 0.1),66 //() => new ChernoffIntervalEstimationPolicy( 0.2),67 //() => new ThresholdAscentPolicy(5, 0.01),68 //() => new ThresholdAscentPolicy(5, 0.05),69 //() => new ThresholdAscentPolicy(5, 0.1),70 //() => new ThresholdAscentPolicy(5, 0.2),71 //() => new ThresholdAscentPolicy(10, 0.01),72 //() => new ThresholdAscentPolicy(10, 0.05),73 //() => new ThresholdAscentPolicy(10, 0.1),74 //() => new ThresholdAscentPolicy(10, 0.2),75 //() => new ThresholdAscentPolicy(50, 0.01),76 //() => new ThresholdAscentPolicy(50, 0.05),77 //() => new ThresholdAscentPolicy(50, 0.1),78 //() => new ThresholdAscentPolicy(50, 0.2),79 //() => new ThresholdAscentPolicy(100, 0.01),26 () => new RandomPolicy(), 27 () => new ActiveLearningPolicy(), 28 () => new EpsGreedyPolicy(0.01, (aInfo)=> aInfo.MaxReward, "max"), 29 () => new EpsGreedyPolicy(0.05, (aInfo)=> aInfo.MaxReward, "max"), 30 () => new EpsGreedyPolicy(0.1, (aInfo)=> aInfo.MaxReward, "max"), 31 () => new EpsGreedyPolicy(0.2, (aInfo)=> aInfo.MaxReward, "max"), 32 //() => new GaussianThompsonSamplingPolicy(), 33 () => new GaussianThompsonSamplingPolicy(true), 34 () => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1)), 35 () => new GenericThompsonSamplingPolicy(new GaussianModel(0.5, 10, 1, 1)), 36 //() => new BernoulliThompsonSamplingPolicy(), 37 () => new GenericThompsonSamplingPolicy(new BernoulliModel(1, 1)), 38 () => new EpsGreedyPolicy(0.01), 39 () => new EpsGreedyPolicy(0.05), 40 () => new EpsGreedyPolicy(0.1), 41 () => new EpsGreedyPolicy(0.2), 42 () => new EpsGreedyPolicy(0.5), 43 () => new UCTPolicy(0.01), 44 () => new UCTPolicy(0.05), 45 () => new UCTPolicy(0.1), 46 () => new UCTPolicy(0.5), 47 () => new UCTPolicy(1), 48 () => new UCTPolicy(2), 49 () => new UCTPolicy( 5), 50 () => new UCTPolicy( 10), 51 () => new ModifiedUCTPolicy(0.01), 52 () => new ModifiedUCTPolicy(0.05), 53 () => new ModifiedUCTPolicy(0.1), 54 () => new ModifiedUCTPolicy(0.5), 55 () => new ModifiedUCTPolicy(1), 56 () => new ModifiedUCTPolicy(2), 57 () => new ModifiedUCTPolicy( 5), 58 () => new ModifiedUCTPolicy( 10), 59 () => new UCB1Policy(), 60 () => new UCB1TunedPolicy(), 61 () => new UCBNormalPolicy(), 62 () => new BoltzmannExplorationPolicy(1), 63 () => new BoltzmannExplorationPolicy(10), 64 () => new BoltzmannExplorationPolicy(20), 65 () => new BoltzmannExplorationPolicy(100), 66 () => new BoltzmannExplorationPolicy(200), 67 () => new BoltzmannExplorationPolicy(500), 68 () => new ChernoffIntervalEstimationPolicy( 0.01), 69 () => new ChernoffIntervalEstimationPolicy( 0.05), 70 () => new ChernoffIntervalEstimationPolicy( 0.1), 71 () => new ChernoffIntervalEstimationPolicy( 0.2), 72 () => new ThresholdAscentPolicy(5, 0.01), 73 () => new ThresholdAscentPolicy(5, 0.05), 74 () => new ThresholdAscentPolicy(5, 0.1), 75 () => new ThresholdAscentPolicy(5, 0.2), 76 () => new ThresholdAscentPolicy(10, 0.01), 77 () => new ThresholdAscentPolicy(10, 0.05), 78 () => new ThresholdAscentPolicy(10, 0.1), 79 () => new ThresholdAscentPolicy(10, 0.2), 80 () => new ThresholdAscentPolicy(50, 0.01), 81 () => new ThresholdAscentPolicy(50, 0.05), 82 () => new ThresholdAscentPolicy(50, 0.1), 83 () => new ThresholdAscentPolicy(50, 0.2), 84 () => new ThresholdAscentPolicy(100, 0.01), 80 85 () => new ThresholdAscentPolicy(100, 0.05), 81 //() => new ThresholdAscentPolicy(100, 0.1),82 //() => new ThresholdAscentPolicy(100, 0.2),83 //() => new ThresholdAscentPolicy(500, 0.01),84 //() => new ThresholdAscentPolicy(500, 0.05),85 //() => new ThresholdAscentPolicy(500, 0.1),86 //() => new ThresholdAscentPolicy(500, 0.2),87 //() => new ThresholdAscentPolicy(5000, 0.01),88 //() => new ThresholdAscentPolicy(10000, 0.01),86 () => new ThresholdAscentPolicy(100, 0.1), 87 () => new ThresholdAscentPolicy(100, 0.2), 88 () => new ThresholdAscentPolicy(500, 0.01), 89 () => new ThresholdAscentPolicy(500, 0.05), 90 () => new ThresholdAscentPolicy(500, 0.1), 91 () => new ThresholdAscentPolicy(500, 0.2), 92 () => new ThresholdAscentPolicy(5000, 0.01), 93 () => new ThresholdAscentPolicy(10000, 0.01), 89 94 }; 90 95 … … 96 101 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:false), 15), 97 102 //(rand) => Tuple.Create((IProblem)new FindPhrasesProblem(rand, 10, numPhrases:5, phraseLen:3, numOptimalPhrases:5, numDecoyPhrases:200, correctReward:1, decoyReward:0.5, phrasesAsSets:true), 15), 98 (rand) => Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23) 103 //(rand) => Tuple.Create((IProblem)new SymbolicRegressionPoly10Problem(), 23) 104 (rand) => Tuple.Create((IProblem)new SantaFeAntProblem(), 17) 99 105 }; 100 106 101 107 foreach (var instanceFactory in instanceFactories) { 102 108 foreach (var useCanonical in new bool[] { true /*, false */ }) { 103 foreach (var randomTries in new int[] { 1/*, 1, 10 /*, /* 5, 100 /*, 500, 1000 */}) {109 foreach (var randomTries in new int[] { 0 /*, 1, 10 /*, /* 5, 100 /*, 500, 1000 */}) { 104 110 foreach (var policyFactory in policyFactories) { 105 111 var myRandomTries = randomTries; -
branches/HeuristicLab.Problems.GrammaticalOptimization/Test/Test.csproj
r11981 r12014 8 8 <AppDesignerFolder>Properties</AppDesignerFolder> 9 9 <RootNamespace>HeuristicLab.Problems.GrammaticalOptimization.Test</RootNamespace> 10 <AssemblyName> HeuristicLab.Problems.GrammaticalOptimization.Test</AssemblyName>10 <AssemblyName>Test</AssemblyName> 11 11 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> 12 12 <FileAlignment>512</FileAlignment> … … 68 68 <Compile Include="Properties\AssemblyInfo.cs" /> 69 69 <Compile Include="TestSolvers.cs" /> 70 <Compile Include="TestTunedSettings.cs" /> 70 71 </ItemGroup> 71 72 <ItemGroup> -
branches/HeuristicLab.Problems.GrammaticalOptimization/Test/TestCanonicalExpressions.cs
r11972 r12014 5 5 using System.Threading.Tasks; 6 6 using HeuristicLab.Algorithms.Bandits; 7 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 8 using HeuristicLab.Algorithms.GrammaticalOptimization; 9 using HeuristicLab.Problems.GrammaticalOptimization.SymbReg; 7 10 using Microsoft.VisualStudio.TestTools.UnitTesting; 8 11 … … 64 67 Assert.AreEqual("a*b+b*c", extender.CanonicalRepresentation("b*(c-a)")); 65 68 Assert.AreEqual("a*b+a*d+b*c+c*d", extender.CanonicalRepresentation("(b-d)*(c-a)")); 69 Assert.AreEqual("|/(a+b)", extender.CanonicalRepresentation("c%c%(a+b)")); 66 70 } 67 71 [TestMethod] 68 72 public void TestDivisionExpansion() { 69 73 var extender = new ExpressionExtender(); 70 Assert.AreEqual("a* 1/c+b*1/c", extender.CanonicalRepresentation("(b+a)%c"));71 Assert.AreEqual("a* 1/c*1/d+b*1/c*1/d", extender.CanonicalRepresentation("(b+a)%(d*c)"));72 Assert.AreEqual("a* 1/(c+d)+b*1/(c+d)", extender.CanonicalRepresentation("(b-a)%(d-c)"));73 Assert.AreEqual("a*b* 1/(c+d)", extender.CanonicalRepresentation("(b*a)%(d-c)"));74 Assert.AreEqual("a*|/c+b*|/c", extender.CanonicalRepresentation("(b+a)%c")); 75 Assert.AreEqual("a*|/c*|/d+b*|/c*|/d", extender.CanonicalRepresentation("(b+a)%(d*c)")); 76 Assert.AreEqual("a*|/(c+d)+b*|/(c+d)", extender.CanonicalRepresentation("(b-a)%(d-c)")); 77 Assert.AreEqual("a*b*|/(c+d)", extender.CanonicalRepresentation("(b*a)%(d-c)")); 74 78 75 Assert.AreEqual("a*b* 1/(a+b)*1/(c+d)", extender.CanonicalRepresentation("(b*a)%(d-c)%(a+b)"));76 Assert.AreEqual("a*b* 1/(a*1/e+b*1/e)*1/(c+d)", extender.CanonicalRepresentation("((b*a)%(d-c))%((a+b)%e)"));79 Assert.AreEqual("a*b*|/(a+b)*|/(c+d)", extender.CanonicalRepresentation("(b*a)%(d-c)%(a+b)")); 80 Assert.AreEqual("a*b*|/(c+d)*|/(a*|/e+b*|/e)", extender.CanonicalRepresentation("((b*a)%(d-c))%((a+b)%e)")); 77 81 // a*b*e%(c+d)%(a+b) 78 82 } … … 80 84 public void TestDivisionCancellation() { 81 85 var extender = new ExpressionExtender(); 82 Assert.AreEqual(" 1", extender.CanonicalRepresentation("a%a"));86 Assert.AreEqual("|", extender.CanonicalRepresentation("a%a")); 83 87 Assert.AreEqual("a", extender.CanonicalRepresentation("a*a%a")); 84 Assert.AreEqual(" 1/a", extender.CanonicalRepresentation("(a%a)%a"));85 Assert.AreEqual(" 1/a", extender.CanonicalRepresentation("a%a%a"));88 Assert.AreEqual("|/a", extender.CanonicalRepresentation("(a%a)%a")); 89 Assert.AreEqual("|/a", extender.CanonicalRepresentation("a%a%a")); 86 90 Assert.AreEqual("a", extender.CanonicalRepresentation("a%(a%a)")); 87 Assert.AreEqual("1", extender.CanonicalRepresentation("(a+b)%(b+a)")); 88 Assert.AreEqual("1/a+1/b", extender.CanonicalRepresentation("(a+b)%(a*b)")); 89 Assert.AreEqual("a*1/(a*c*1/b+e*1/d*1/f)+b*1/(a*c*1/b+e*1/d*1/f)", extender.CanonicalRepresentation("(a+b)%(a%b*c+e%f%d)")); 91 Assert.AreEqual("|", extender.CanonicalRepresentation("(a+b)%(b+a)")); 92 Assert.AreEqual("|/a+|/b", extender.CanonicalRepresentation("(a+b)%(a*b)")); 93 Assert.AreEqual("a*|/(a*c*|/b+e*|/d*|/f)+b*|/(a*c*|/b+e*|/d*|/f)", extender.CanonicalRepresentation("(a+b)%(a%b*c+e%f%d)")); 94 Assert.AreEqual("|", extender.CanonicalRepresentation("(a%a%a+b%b%b)%(a%a*a%a%a+b%b*b%b%b)")); 95 Assert.AreEqual("|", extender.CanonicalRepresentation("(a%(a%a)+b%(b%b))%(a+b)")); 96 } 97 98 [TestMethod] 99 public void TestRandomExpressions() { 100 // samples sentences for the Tower dataset with the random MCTS policy 101 // and evaluates the original and the extended expression 102 // the results must be the same 103 104 var problem = new SymbolicRegressionProblem(new Random(), "Tower"); 105 var random = new Random(31415); 106 var solver = new SequentialSearch(problem, 30, random, 0, new RandomPolicy(problem, true)); 107 108 var extender = new ExpressionExtender(); 109 110 solver.SolutionEvaluated += (sentence, quality) => { 111 var canonicalSentence = extender.CanonicalRepresentation(sentence); 112 113 Assert.AreEqual(problem.SimpleEvaluate(sentence), problem.SimpleEvaluate(canonicalSentence), 1E-4, string.Format("{0} <> {1}", sentence, canonicalSentence)); 114 }; 115 116 solver.Run(10000); 90 117 } 91 118 } -
branches/HeuristicLab.Problems.GrammaticalOptimization/Test/TestSymbRegInstances.cs
r11895 r12014 1 1 using System; 2 2 using System.Linq; 3 using HeuristicLab.Algorithms.Bandits.BanditPolicies; 4 using HeuristicLab.Algorithms.Bandits.GrammarPolicies; 3 5 using HeuristicLab.Algorithms.GeneticProgramming; 4 6 using HeuristicLab.Algorithms.GrammaticalOptimization; … … 12 14 [TestMethod] 13 15 public void TestGetDataDescriptors() { 16 var problem = new SymbolicRegressionProblem(new Random(), "Tower"); 17 Assert.IsNotNull(problem); 18 } 14 19 20 [TestMethod] 21 public void TestConstantOptimization() { 22 double r2; 15 23 var problem = new SymbolicRegressionProblem(new Random(), "Tower"); 16 double r2;17 24 Assert.AreEqual(problem.Evaluate("a*b"), problem.OptimizeConstantsAndEvaluate("a*b")); 18 25 Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("a*b"), problem.Evaluate("a*b")); … … 23 30 Assert.IsTrue(problem.OptimizeConstantsAndEvaluate("0*a+1*b") >= problem.Evaluate("a+b")); 24 31 } 32 33 [TestMethod] 34 public void TestSequentialSolverForTower() { 35 var problem = new SymbolicRegressionProblem(new Random(), "Tower"); 36 var random = new Random(31415); 37 var solver = new SequentialSearch(problem, 30, random, 0, new GenericGrammarPolicy(problem, new UCB1TunedPolicy(), true)); 38 solver.FoundNewBestSolution += (s, d) => { 39 Console.WriteLine("{0:F3} {1}", d, s); 40 }; 41 solver.Run(100); 42 } 43 25 44 } 26 45 }
Note: See TracChangeset
for help on using the changeset viewer.