Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/11/15 13:06:02 (10 years ago)
Author:
gkronber
Message:

#2283: commit before cleanup after EuroCAST

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

Legend:

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

    r11977 r11980  
    6161      }
    6262
    63 
    64      
    65       const double beta = 20;
     63     
     64      /*
     65      const double beta = 10;
    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       /*
    76       if (random.NextDouble() < 0.2) {
     73      */
     74     
     75     
     76      if (random.NextDouble() < 0.5) {
    7777        selectedStateIdx = actionIndexMap[random.Next(maxIdx)];
    7878      } else {
     
    9191        selectedStateIdx = actionIndexMap[bestIdxs[random.Next(bestIdxs.Count)]];
    9292      }
    93       */
     93     
    9494      return true;
    9595    }
     
    140140      double delta = reward - GetValue(state);
    141141      // delta /= problem.GetFeatures(state).Count();
    142       //const double alpha = 0.01;
     142      //const double alpha = 0.001;
    143143      foreach (var feature in problem.GetFeatures(state)) {
    144144        featureTries[feature.Id] = GetFeatureTries(feature.Id) + 1;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Grammar.cs

    r11851 r11980  
    184184        Debug.Assert(maxLenOfReplacement > 0);
    185185
    186         var alts = GetAlternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement);
     186        var alts = GetTerminalAlternatives(nt).Where(alt => MinPhraseLength(alt) <= maxLenOfReplacement);
    187187        Debug.Assert(alts.Any());
    188188
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/Problems/SantaFeAntProblem.cs

    r11977 r11980  
    123123
    124124    public string CanonicalRepresentation(string phrase) {
    125       phrase = phrase.Replace("A", ".");
     125      //phrase = phrase.Replace("A", ".");
    126126      var sb = new StringBuilder(phrase);
    127127      string canonicalPhrase = phrase;
     
    133133        canonicalPhrase = sb.ToString();
    134134      } while (canonicalPhrase != oldPhrase);
    135       return sb.ToString();
     135      return canonicalPhrase;
    136136    }
    137137
     
    141141
    142142
    143       //yield return new Feature("const", 0.0);
     143      yield return new Feature(isTerminal + ToString(), 1.0);
    144144      //if (phrase.Length > 0) {
    145145      //  var ant = new Ant(recordTrail: true);
     
    157157      //}
    158158      //
    159       ////yield return new Feature("$" + phrase[0], 1.0);
    160       // if (!isTerminal) {
    161       //   for (int i = 4; i < phrase.Length; i++) {
    162       //     if (grammar.IsNonTerminal(phrase[i])) {
    163       //       yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 0.1);
    164       //       break;
    165       //     }
    166       //   }
    167       // }
     159      yield return new Feature("$" + (phrase.Length > 0 ? phrase[0] : ' '), 1.0);
     160      if (!isTerminal) {
     161        for (int i = 4; i < phrase.Length; i++) {
     162          if (!grammar.IsTerminal(phrase[i])) {
     163            yield return new Feature(phrase[i - 4].ToString() + phrase[i - 3].ToString() + phrase[i - 2] + phrase[i - 1], 1.0);
     164            break;
     165          }
     166        }
     167      }
    168168      // var d = 0;
    169169      // var ls = 0;
  • branches/HeuristicLab.Problems.GrammaticalOptimization/Main/Program.cs

    r11977 r11980  
    179179
    180180    private static void RunDemo() {
    181       // TODO: unify MCTS, TD and ContextMCTS Solvers (stateInfos)
    182       // TODO: test with eps-greedy using max instead of average as value (seems to work well for symb-reg! explore further!)
    183       // TODO: separate value function from policy
    184       // TODO: warum funktioniert die alte Implementierung von GaussianThompson besser fÃŒr SantaFe als neue? Siehe Vergleich: alte vs. neue implementierung GaussianThompsonSampling
     181      // TODO: cleanup nach EuroCAST
    185182      // TODO: why does GaussianThompsonSampling work so well with MCTS for the artificial ant problem?
    186183      // TODO: research thompson sampling for max bandit?
     
    316313      {
    317314        () => Tuple.Create(100000, 23,  (ISymbolicExpressionTreeProblem)new SymbolicRegressionPoly10Problem()),
    318         () => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()),
     315        //() => Tuple.Create(100000, 17, (ISymbolicExpressionTreeProblem)new SantaFeAntProblem()),
    319316        //() => Tuple.Create(50000, 32,(ISymbolicExpressionTreeProblem)new RoyalSymbolProblem()),
    320317        //() => Tuple.Create(50000, 64, (ISymbolicExpressionTreeProblem)new RoyalPairProblem()),
     
    345342            int iterations = 0;
    346343            double bestQuality = double.NegativeInfinity;
    347             var globalStatistics = new SentenceSetStatistics(prob.BestKnownQuality(maxSize));
     344            var globalStatistics = new SentenceSetStatistics();
    348345            var algName = alg.GetType().Name;
    349346            var probName = prob.GetType().Name;
     
    358355              //}
    359356              //Console.WriteLine("{0:N5} {1}", quality, sentence);
    360               if (iterations % 200 == 0) {
     357              if (iterations % 1000 == 0) {
    361358                Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics);
    362359                if (bestQuality.IsAlmost(1.0)) {
     
    368365            alg.Run(maxIters);
    369366
     367
     368            while (iterations < maxIters) {
     369              iterations++;
     370              globalStatistics.AddSentence("BEST", bestQuality);
     371              if (iterations % 1000 == 0) {
     372                Console.WriteLine("\"{0,25}\" {1} \"{2,25}\" {3}", algName, maxSize, probName, globalStatistics);
     373                if (bestQuality.IsAlmost(1.0)) {
     374                  alg.StopRequested = true;
     375                }
     376              }
     377            }
    370378          }
    371 
    372379        }
    373380      }
Note: See TracChangeset for help on using the changeset viewer.