Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/17/15 16:03:49 (10 years ago)
Author:
gkronber
Message:

#2283: changed handling of inverse expressions in transformation of expressions to canonical form

Location:
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg/ExpressionCompiler.cs

    r12014 r12024  
    9595      if (f != null) factors.Add(f);
    9696      var curSy = CurSy();
    97       while (curSy == '*' || curSy == '%' || curSy == '/') { // division and protected division symbols are handled in the same way
     97      while (curSy == '*' || curSy == '%') { // division and protected division symbols are handled in the same way
    9898        if (curSy == '*') {
    9999          NewSy();
     
    135135        r = variables[varIdx];
    136136        NewSy();
    137       } else if (curSy == '|') {
    138         // pipe symbol is used in the expressionextender to represent constant one (|/x).
     137      } else if (curSy == '/') {
     138        // /-symbol used in the expressionextender to represent inverse (1/x).
    139139        // this is necessary because we also use symbols 0..9 as indices for ERCs
    140         r = 1.0;
    141140        NewSy();
     141        r = 1.0 / Fact(variables, constants);
    142142      } else if (curSy >= '0' && curSy <= '9') {
    143143        int o = (byte)curSy - (byte)'0';
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg/SymbolicRegressionProblem.cs

    r12014 r12024  
    126126
    127127    public double Evaluate(string sentence) {
     128      var extender = new ExpressionExtender();
     129      sentence = extender.CanonicalRepresentation(sentence);
    128130      if (useConstantOpt)
    129131        return OptimizeConstantsAndEvaluate(sentence);
    130132      else {
    131         var extender = new ExpressionExtender();
    132133
    133134        Debug.Assert(SimpleEvaluate(sentence) == SimpleEvaluate(extender.CanonicalRepresentation(sentence)));
     
    152153
    153154    public IEnumerable<Feature> GetFeatures(string phrase) {
     155      // throw new NotImplementedException();
    154156      phrase = CanonicalRepresentation(phrase);
    155       return new Feature[] { new Feature(phrase, 1.0) };
     157      return phrase.Split('+').Distinct().Select(t => new Feature(t, 1.0));
     158      // return new Feature[] { new Feature(phrase, 1.0) };
    156159    }
    157160
Note: See TracChangeset for help on using the changeset viewer.