Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/10/15 16:12:08 (9 years ago)
Author:
gkronber
Message:

#2283: experiments with q-learning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.GrammaticalOptimization/Problems/SymbolicRegressionPoly10Problem.cs

    r12295 r12298  
    156156    // splits the phrase into terms and creates (sparse) term-occurrance features
    157157    public IEnumerable<Feature> GetFeatures(string phrase) {
    158       // var canonicalTerms = new HashSet<string>();
    159       // foreach (string t in phrase.Split('+')) {
    160       //   canonicalTerms.Add(CanonicalTerm(t));
     158      //if (phrase.EndsWith("E")) phrase = phrase.TrimEnd('*', '+', 'E');
     159      //yield return new Feature("$$$", 1.0); // const
     160      //var canonicalTerms = new HashSet<string>();
     161      //foreach (string t in phrase.Split('+')) {
     162      //  canonicalTerms.Add(CanonicalTerm(t));
     163      //}
     164      //return canonicalTerms.Select(entry => new Feature(entry, 1.0));
     165      //.Concat(new Feature[] { new Feature(CanonicalRepresentation(phrase), 1.0) });
     166
     167
     168      if (phrase.EndsWith("E")) phrase = phrase.TrimEnd('*', '+', 'E');
     169      //var len = 5;
     170      //var start = Math.Max(0, phrase.Length - len);
     171      //var end = Math.Min(phrase.Length, start + len);
     172      //string f = phrase.Substring(start, end - start);
     173      //yield return new Feature(f, 1.0);
     174      //
     175
     176      var terms = phrase.Split('+');
     177      foreach (var t in terms.Distinct()) yield return new Feature(t, 1.0);
     178
     179      for (int i = 0; i < terms.Length; i++) {
     180        for (int j = i + 1; j < terms.Length; j++) {
     181          yield return new Feature(terms[i] + " " + terms[j], 1.0);
     182        }
     183      }
     184
     185      // var substrings = new HashSet<string>();
     186      // for (int start = 0; start <= phrase.Length - 2; start += 2) {
     187      //   var s = phrase.Substring(start, 3);
     188      //   substrings.Add(s);
    161189      // }
    162       // return canonicalTerms.Select(entry => new Feature(entry, 1.0))
    163       //   .Concat(new Feature[] { new Feature(CanonicalRepresentation(phrase), 1.0) });
    164 
    165       return new Feature[] { new Feature(phrase, 1.0), };
    166 
    167       // var partialInterpreter = new PartialExpressionInterpreter();
    168       // var vars = new double[] { 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, };
    169       // var s = partialInterpreter.Interpret(phrase, vars);
    170       // //if (s.Any())
    171       // //  return new Feature[] { new Feature(s.Pop().ToString(), 1.0), };
    172       // //else
    173       // //  return new Feature[] { new Feature("$", 1.0), };
    174       // return new Feature[] { new Feature(string.Join(",", s), 1.0) };
     190      //
     191      // var list = new List<string>(substrings);
     192      //
     193      // for (int i = 0; i < list.Count; i++) {
     194      //   yield return new Feature(list[i], 1.0);
     195      //   //for (int j = i+1; j < list.Count; j++) {
     196      //   //  yield return new Feature(list[i] + " " + list[j], 1.0);
     197      //   //}
     198      // }
     199
     200      //
     201      // for (int len = 1; len <= phrase.Length; len += 2) {
     202      //   var start = Math.Max(0, phrase.Length - len);
     203      //   var end = Math.Min(phrase.Length, start + len);
     204      //   string f = phrase.Substring(start, end - start);
     205      //   yield return new Feature(f, 1.0);
     206      //
     207      // }
     208
     209      //var partialInterpreter = new PartialExpressionInterpreter();
     210      //var vars = new double[] { 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, };
     211      //var s = partialInterpreter.Interpret(phrase, vars);
     212      ////if (s.Any())
     213      ////  return new Feature[] { new Feature(s.Pop().ToString(), 1.0), };
     214      ////else
     215      ////  return new Feature[] { new Feature("$", 1.0), };
     216      //return s.Select(f => new Feature(f.ToString(), 1.0));
    175217    }
    176218
Note: See TracChangeset for help on using the changeset viewer.