Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/07/15 14:31:06 (10 years ago)
Author:
gkronber
Message:

#2283 created a new branch to separate development from aballeit

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

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Main.csproj

    r12098 r12290  
    5656      <Name>HeuristicLab.Algorithms.MonteCarloTreeSearch</Name>
    5757    </ProjectReference>
     58    <ProjectReference Include="..\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\HeuristicLab.Problems.GrammaticalOptimization.SymbReg.csproj">
     59      <Project>{17A7A380-86CE-482D-8D22-CBD70CC97F0D}</Project>
     60      <Name>HeuristicLab.Problems.GrammaticalOptimization.SymbReg</Name>
     61    </ProjectReference>
    5862    <ProjectReference Include="..\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.csproj">
    5963      <Project>{cb9dccf6-667e-4a13-b82d-dbd6b45a045e}</Project>
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/Main/Program.cs

    r12098 r12290  
    33using System.Globalization;
    44using HeuristicLab.Algorithms.Bandits.BanditPolicies;
     5using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
    56using HeuristicLab.Algorithms.GrammaticalOptimization;
    67using HeuristicLab.Algorithms.MonteCarloTreeSearch;
     
    1819// TODO: reward discounting (fÌr verÀnderliche reward distributions Ìber zeit). speziellen unit-test dafÌr erstellen
    1920// TODO: constant optimization
     21using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
    2022
    2123
    22 namespace Main
    23 {
    24     class Program
    25     {
    26         static void Main(string[] args)
    27         {
    28             CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
     24namespace Main {
     25  class Program {
     26    static void Main(string[] args) {
     27      CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
    2928
    30             RunDemo();
    31         }
     29      RunDemo();
     30    }
    3231
    3332
    34         private static void RunDemo()
    35         {
     33    private static void RunDemo() {
     34
     35      for (int i = 0; i < 100; i++) {
     36        int maxIterations = 2000000;
     37        int iterations = 0;
     38
     39        var globalStatistics = new SentenceSetStatistics();
     40        var random = new Random();
     41
     42        var problem = new SymbolicRegressionPoly10Problem();
     43        //var problem = new SantaFeAntProblem();             
     44        //var problem = new RoyalPairProblem(25);
     45        //var problem = new FindPhrasesProblem(random, 10, 5, 3, 5, 5, 1.0, 0.9, true);
     46        //var problem = new PrimePolynomialProblem();
     47        //var problem = new SymbolicRegressionProblem(random,
     48        //  //@"C:\reps\HeuristicLab\branches\HeuristicLab.Problems.GrammaticalOptimization\HeuristicLab.Problems.GrammaticalOptimization.SymbReg\nht-train.csv",
     49        //  @"C:\reps\fhooe-new\research\Datasets\Benchmark\kommenda-1.csv",
     50        //  1.0,
     51        //  true);
     52        // //var problem = new PrimePolynomialProblem();
     53        // var alg = new SequentialSearch(problem, 25, random, 0,
     54        //   new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()));
     55        var alg = new SequentialSearch(problem, 25, random, 0,
     56          new GenericPolicy(problem, new HeuristicLab.Algorithms.Bandits.BanditPolicies.EpsGreedyPolicy(0.1)));
     57        //var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 30));
    3658
    3759
    38             int maxIterations = 100000;
    39             int iterations = 0;
     60        alg.FoundNewBestSolution += (sentence, quality) => {
     61          //Console.WriteLine("{0}", globalStatistics);
     62        };
    4063
    41             var globalStatistics = new SentenceSetStatistics();
    42             var random = new Random();
     64        alg.SolutionEvaluated += (sentence, quality) => {
     65          iterations++;
     66          globalStatistics.AddSentence(sentence, quality);
    4367
    44             //var problem = new SymbolicRegressionPoly10Problem();
    45             //var problem = new SantaFeAntProblem();             
    46             var problem = new RoyalPairProblem();
    47             //var problem = new EvenParityProblem();
    48             //var alg = new SequentialSearch(problem, 23, random, 0,
    49             // new HeuristicLab.Algorithms.Bandits.GrammarPolicies.GenericGrammarPolicy(problem, new UCB1TunedPolicy()));
    50             var alg = new MonteCarloTreeSearch(problem, 23, random, new UCB1Policy(), new RandomSimulation(problem, random, 23));
     68          // comment this if you don't want to see solver statistics
     69          if (iterations % 100 == 0) {
     70            if (iterations % 1000 == 0) Console.Clear();
     71            Console.SetCursorPosition(0, 0);
     72            alg.PrintStats();
     73          }
    5174
     75          // uncomment this if you want to collect statistics of the generated sentences
     76          //if (iterations % 100 == 0) {
     77          //  Console.WriteLine("{0}", globalStatistics);
     78          //}
     79        };
    5280
    53             alg.FoundNewBestSolution += (sentence, quality) =>
    54             {
    55                 //Console.WriteLine("{0}", globalStatistics);
    56             };
     81        var sw = new Stopwatch();
     82        sw.Start();
     83        alg.Run(maxIterations);
     84        sw.Stop();
    5785
    58             alg.SolutionEvaluated += (sentence, quality) =>
    59             {
    60                 iterations++;
    61                 globalStatistics.AddSentence(sentence, quality);
     86        Console.WriteLine(globalStatistics);
    6287
    63                 // comment this if you don't want to see solver statistics
    64                 if (iterations % 100 == 0)
    65                 {
    66                     if (iterations % 10000 == 0) Console.Clear();
    67                     Console.SetCursorPosition(0, 0);
    68                     alg.PrintStats();
    69                 }
    70 
    71                 // uncomment this if you want to collect statistics of the generated sentences
    72                 // if (iterations % 1000 == 0) {
    73                 //   Console.WriteLine("{0}", globalStatistics);
    74                 // }
    75             };
    76 
    77             var sw = new Stopwatch();
    78             sw.Start();
    79             alg.Run(maxIterations);
    80             sw.Stop();
    81 
    82             Console.Clear();
    83             alg.PrintStats();
    84             Console.WriteLine(globalStatistics);
    85             Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
    86               sw.Elapsed.TotalSeconds,
    87               maxIterations / (double)sw.Elapsed.TotalSeconds,
    88               (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
    89         }
     88        Console.WriteLine("{0:F2} sec {1,10:F1} sols/sec {2,10:F1} ns/sol",
     89          sw.Elapsed.TotalSeconds,
     90          maxIterations / (double)sw.Elapsed.TotalSeconds,
     91          (double)sw.ElapsedMilliseconds * 1000 / maxIterations);
     92      }
    9093    }
     94  }
    9195}
Note: See TracChangeset for help on using the changeset viewer.