Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/15 09:14:38 (10 years ago)
Author:
gkronber
Message:

#2283: worked on transformation of arithmetic 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

    r11972 r12014  
    1717    // does not compile to IL it is only necessary to calculate gradients for parameter optimization
    1818    // Expr -> Term { ('+' | '-' | '^' ) Term }
    19     // Term -> Fact { ('*' | '%') Fact }
    20     // Fact -> '!' Expr | '(' Expr ')' | Var | const
     19    // Term -> Fact { ('*' | '%' | '/') Fact }
     20    // Fact -> '!' Expr | '(' Expr ')' | Var | const | one
    2121    // Var -> 'a'..'z'
    2222    // const -> '0' .. '9'
     23    // one -> |    // pipe symbol for constant one instead of ERC 1
    2324
    2425    // constants are completely ignored, instead we introduce a multiplicative constant factor for each term and an additive constant term for each expression
     
    9495      if (f != null) factors.Add(f);
    9596      var curSy = CurSy();
    96       while (curSy == '*' || curSy == '%') {
     97      while (curSy == '*' || curSy == '%' || curSy == '/') { // division and protected division symbols are handled in the same way
    9798        if (curSy == '*') {
    9899          NewSy();
     
    134135        r = variables[varIdx];
    135136        NewSy();
     137      } else if (curSy == '|') {
     138        // pipe symbol is used in the expressionextender to represent constant one (|/x).
     139        // this is necessary because we also use symbols 0..9 as indices for ERCs
     140        r = 1.0;
     141        NewSy();
    136142      } else if (curSy >= '0' && curSy <= '9') {
    137143        int o = (byte)curSy - (byte)'0';
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization.SymbReg/SymbolicRegressionProblem.cs

    r11981 r12014  
    99using System.Text;
    1010using AutoDiff;
     11using HeuristicLab.Algorithms.Bandits;
    1112using HeuristicLab.Common;
    1213using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    128129        return OptimizeConstantsAndEvaluate(sentence);
    129130      else {
     131        var extender = new ExpressionExtender();
     132
     133        Debug.Assert(SimpleEvaluate(sentence) == SimpleEvaluate(extender.CanonicalRepresentation(sentence)));
    130134        return SimpleEvaluate(sentence);
    131135      }
     
    143147
    144148    public string CanonicalRepresentation(string phrase) {
    145       return phrase;
     149      var extender = new ExpressionExtender();
     150      return extender.CanonicalRepresentation(phrase);
    146151    }
    147152
    148153    public IEnumerable<Feature> GetFeatures(string phrase) {
    149       // first generate canonical expression (which must not contain ())
    150       // recursively split into expressions
    151       // for each expression split into terms
    152       // for each term order factors to canonical // ../E = * 1/E
     154      phrase = CanonicalRepresentation(phrase);
    153155      return new Feature[] { new Feature(phrase, 1.0) };
    154156    }
Note: See TracChangeset for help on using the changeset viewer.