- Timestamp:
- 01/14/17 19:11:27 (8 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14350
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 14350
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r14564 r14565 26 26 using System.Text; 27 27 using HeuristicLab.Collections; 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 … … 109 110 { "XOR", new Xor()}, 110 111 { "DIFF", new Derivative()}, 112 { "LAG", new LaggedVariable() }, 111 113 }; 112 114 … … 333 335 } 334 336 335 // Fact = '(' Expr ')' | funcId '(' ArgList ')' | varId | number337 // Fact = '(' Expr ')' | 'LAG' '(' varId ',' ['+' | '-'] number ')' | funcId '(' ArgList ')' | varId | number 336 338 private ISymbolicExpressionTreeNode ParseFact(Queue<Token> tokens) { 337 339 var next = tokens.Peek(); … … 353 355 if (lPar.TokenType != TokenType.LeftPar) 354 356 throw new ArgumentException("expected ("); 355 var args = ParseArgList(tokens); 356 357 // check semantic constraints 358 if (funcNode.Symbol.MinimumArity > args.Length || funcNode.Symbol.MaximumArity < args.Length) 359 throw new ArgumentException(string.Format("Symbol {0} requires between {1} and {2} arguments.", funcId, 360 funcNode.Symbol.MinimumArity, funcNode.Symbol.MaximumArity)); 361 foreach (var arg in args) funcNode.AddSubtree(arg); 357 358 // handle 'lag' specifically 359 if (funcNode.Symbol is LaggedVariable) { 360 var varId = tokens.Dequeue(); 361 if (varId.TokenType != TokenType.Identifier) throw new ArgumentException("Identifier expected. Format for lagged variables: \"lag(x, -1)\""); 362 var comma = tokens.Dequeue(); 363 if (comma.TokenType != TokenType.Comma) throw new ArgumentException("',' expected, Format for lagged variables: \"lag(x, -1)\""); 364 double sign = 1.0; 365 if (tokens.Peek().strVal == "+" || tokens.Peek().strVal == "-") { 366 // read sign 367 var signTok = tokens.Dequeue(); 368 if (signTok.strVal == "-") sign = -1.0; 369 } 370 var lagToken = tokens.Dequeue(); 371 if (lagToken.TokenType != TokenType.Number) throw new ArgumentException("Number expected, Format for lagged variables: \"lag(x, -1)\""); 372 if (!lagToken.doubleVal.IsAlmost(Math.Round(lagToken.doubleVal))) 373 throw new ArgumentException("Time lags must be integer values"); 374 var laggedVarNode = funcNode as LaggedVariableTreeNode; 375 laggedVarNode.VariableName = varId.strVal; 376 laggedVarNode.Lag = (int)Math.Round(sign * lagToken.doubleVal); 377 laggedVarNode.Weight = 1.0; 378 } else { 379 // functions 380 var args = ParseArgList(tokens); 381 // check number of arguments 382 if (funcNode.Symbol.MinimumArity > args.Length || funcNode.Symbol.MaximumArity < args.Length) { 383 throw new ArgumentException(string.Format("Symbol {0} requires between {1} and {2} arguments.", funcId, 384 funcNode.Symbol.MinimumArity, funcNode.Symbol.MaximumArity)); 385 } 386 foreach (var arg in args) funcNode.AddSubtree(arg); 387 } 362 388 363 389 var rPar = tokens.Dequeue();
Note: See TracChangeset
for help on using the changeset viewer.