Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11977


Ignore:
Timestamp:
02/11/15 03:01:59 (10 years ago)
Author:
gkronber
Message:

#2283 commit for 'realistic' (same settings for ant and symbreg) experiment

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/SequentialDecisionPolicies/GenericFunctionApproximationGrammarPolicy.cs

    r11976 r11977  
    6262
    6363
    64       /*
    65       const double beta = 1;
     64     
     65      const double beta = 20;
    6666      var w = from idx in Enumerable.Range(0, maxIdx)
    6767              let afterStateQ = activeAfterStates[idx]
     
    7171      selectedStateIdx = actionIndexMap[bestAction];
    7272      Debug.Assert(selectedStateIdx >= 0);
    73       */
    74 
    75 
     73     
     74
     75      /*
    7676      if (random.NextDouble() < 0.2) {
    7777        selectedStateIdx = actionIndexMap[random.Next(maxIdx)];
     
    9191        selectedStateIdx = actionIndexMap[bestIdxs[random.Next(bestIdxs.Count)]];
    9292      }
    93 
    94 
    95 
    96 
     93      */
    9794      return true;
    9895    }
     
    132129
    133130    public double GetValue(string state) {
    134       return problem.GetFeatures(state).Average(feature => GetWeight(feature));
     131      return problem.GetFeatures(state).Sum(feature => GetWeight(feature));
    135132    }
    136133
     
    142139    private void UpdateWeights(string state, double reward) {
    143140      double delta = reward - GetValue(state);
    144       delta /= problem.GetFeatures(state).Count();
    145       const double alpha = 0.001;
     141      // delta /= problem.GetFeatures(state).Count();
     142      //const double alpha = 0.01;
    146143      foreach (var feature in problem.GetFeatures(state)) {
    147144        featureTries[feature.Id] = GetFeatureTries(feature.Id) + 1;
    148145        Debug.Assert(GetFeatureTries(feature.Id) >= 1);
    149         //double alpha = 1.0 / GetFeatureTries(feature.Id);
    150         //alpha = Math.Max(alpha, 0.01);
     146        double alpha = 1.0 / GetFeatureTries(feature.Id);
     147        alpha = Math.Max(alpha, 0.001);
    151148
    152149        double w;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.GrammaticalOptimization/Solvers/SequentialSearch.cs

    r11976 r11977  
    6262    }
    6363
     64    public bool StopRequested {
     65      get;
     66      set;
     67    }
     68
    6469    public override void Run(int maxIterations) {
    6570      Reset();
    6671
    67       for (int i = 0; /*!bestQuality.IsAlmost(1.0) && */!Done() && i < maxIterations; i++) {
     72      for (int i = 0; !StopRequested && !Done() && i < maxIterations; i++) {
    6873        var phrase = SampleSentence(problem.Grammar);
    6974        // can fail on the last sentence
     
    171176
    172177    private void Reset() {
     178      StopRequested = false;
    173179      behaviourPolicy.Reset();
    174180      greedyPolicy.Reset();
     
    238244    }
    239245    #endregion
    240  
     246
    241247  }
    242248}
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs

    r11976 r11977  
    129129      do {
    130130        oldPhrase = canonicalPhrase;
    131         sb.Replace("ll", "rr").Replace("rl", "").Replace("lr", "").Replace("lll", "r").Replace("rrr", "l");
    132         sb.Replace("?(m)(m)", "?()()m").Replace("?(l)(l)", "?()()l").Replace("?(r)(r)", "?()()r").Replace("?()()", "");
     131        sb.Replace("ll", "rr").Replace("rl", "").Replace("lr", "").Replace("lll", "r").Replace("rrr", "l").Replace("?()()", "");
     132        //sb.Replace("?(m)(m)", "?()()m").Replace("?(l)(l)", "?()()l").Replace("?(r)(r)", "?()()r");
    133133        canonicalPhrase = sb.ToString();
    134134      } while (canonicalPhrase != oldPhrase);
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Main.csproj

    r11849 r11977  
    5656      <Name>HeuristicLab.Algorithms.GrammaticalOptimization</Name>
    5757    </ProjectReference>
     58    <ProjectReference Include="..\HeuristicLab.Common\HeuristicLab.Common.csproj">
     59      <Project>{3A2FBBCB-F9DF-4970-87F3-F13337D941AD}</Project>
     60      <Name>HeuristicLab.Common</Name>
     61    </ProjectReference>
    5862    <ProjectReference Include="..\HeuristicLab.Distributions\HeuristicLab.Distributions.csproj">
    5963      <Project>{31171165-E16F-4A1A-A8AB-25C6AB3A71B9}</Project>
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs

    r11976 r11977  
    1313using HeuristicLab.Algorithms.GeneticProgramming;
    1414using HeuristicLab.Algorithms.GrammaticalOptimization;
     15using HeuristicLab.Common;
    1516using HeuristicLab.Problems.GrammaticalOptimization;
    1617using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
     
    3031      // RunGridTest();
    3132      //RunGpGridTest();
    32      RunFunApproxTest();
     33      RunFunApproxTest();
    3334    }
    3435
     
    308309
    309310    private static void RunFunApproxTest() {
    310       const int nReps = 20;
     311      const int nReps = 30;
    311312      const int seed = 31415;
    312313      //const int maxIters = 50000;
     
    314315      var problemFactories = new Func<Tuple<int, int, ISymbolicExpressionTreeProblem>>[]
    315316      {
    316         //() => Tuple.Create(100000, 23,  (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()),
     317        () => Tuple.Create(100000, 23,  (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()),
    317318        () => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()),
    318319        //() => Tuple.Create(50000, 32,(ISymbolicExpressionTreeProblem)new RoyalSymbolProblem()),
     
    330331
    331332      // skip experiments that are already done
    332       foreach (var problemFactory in problemFactories) {
    333         for (int i = 0; i < nReps; i++) {
     333      for (int i = 0; i < nReps; i++) {
     334        foreach (var problemFactory in problemFactories) {
    334335          {
    335336            var solverSeed = rand.Next();
     
    343344
    344345            int iterations = 0;
     346            double bestQuality = double.NegativeInfinity;
    345347            var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize));
    346348            var algName = alg.GetType().Name;
    347349            var probName = prob.GetType().Name;
    348350            alg.SolutionEvaluated += (sentence, quality) => {
     351              bestQuality = Math.Max(bestQuality, quality);
    349352              iterations++;
    350353              globalStatistics.AddSentence(sentence, quality);
     
    357360              if (iterations % 200 == 0) {
    358361                Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics);
     362                if (bestQuality.IsAlmost(1.0)) {
     363                  alg.StopRequested = true;
     364                }
    359365              }
    360366            };
Note: See TracChangeset for help on using the changeset viewer.