Changeset 18176
- Timestamp:
- 01/03/22 12:23:11 (3 years ago)
- Location:
- branches/3136_Structural_GP
- Files:
-
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3136_Structural_GP
- Property svn:mergeinfo changed
/trunk merged: 18165-18174
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Clients.OKB.Views (added) merged: 18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonDateTimeFilterView.cs
r17180 r18176 52 52 53 53 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 54 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 54 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 55 55 label.Focus(); // set focus on label to validate data 56 if (e.KeyCode == Keys.Escape) { 56 e.SuppressKeyPress = true; 57 } else if (e.KeyCode == Keys.Escape) { 57 58 valueTextBox.Text = Content.Value.ToString(); 58 59 label.Focus(); // set focus on label to validate data 60 e.SuppressKeyPress = true; 59 61 } 60 62 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonDoubleFilterView.cs
r17180 r18176 51 51 52 52 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 54 54 label.Focus(); // set focus on label to validate data 55 if (e.KeyCode == Keys.Escape) { 55 e.SuppressKeyPress = true; 56 } else if (e.KeyCode == Keys.Escape) { 56 57 valueTextBox.Text = Content.Value.ToString(); 57 58 label.Focus(); // set focus on label to validate data 59 e.SuppressKeyPress = true; 58 60 } 59 61 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonFloatFilterView.cs
r17180 r18176 51 51 52 52 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 54 54 label.Focus(); // set focus on label to validate data 55 if (e.KeyCode == Keys.Escape) { 55 e.SuppressKeyPress = true; 56 } else if (e.KeyCode == Keys.Escape) { 56 57 valueTextBox.Text = Content.Value.ToString(); 57 58 label.Focus(); // set focus on label to validate data 59 e.SuppressKeyPress = true; 58 60 } 59 61 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonIntFilterView.cs
r17180 r18176 51 51 52 52 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 54 54 label.Focus(); // set focus on label to validate data 55 if (e.KeyCode == Keys.Escape) { 55 e.SuppressKeyPress = true; 56 } else if (e.KeyCode == Keys.Escape) { 56 57 valueTextBox.Text = Content.Value.ToString(); 57 58 label.Focus(); // set focus on label to validate data 59 e.SuppressKeyPress = true; 58 60 } 59 61 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonLongFilterView.cs
r17180 r18176 51 51 52 52 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 53 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 54 54 label.Focus(); // set focus on label to validate data 55 if (e.KeyCode == Keys.Escape) { 55 e.SuppressKeyPress = true; 56 } else if (e.KeyCode == Keys.Escape) { 56 57 valueTextBox.Text = Content.Value.ToString(); 57 58 label.Focus(); // set focus on label to validate data 59 e.SuppressKeyPress = true; 58 60 } 59 61 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonPercentFilterView.cs
r17180 r18176 58 58 59 59 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 60 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 60 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 61 61 label.Focus(); // set focus on label to validate data 62 if (e.KeyCode == Keys.Escape) { 62 e.SuppressKeyPress = true; 63 } else if (e.KeyCode == Keys.Escape) { 63 64 valueTextBox.Text = Content.Value.ToString(); 64 65 label.Focus(); // set focus on label to validate data 66 e.SuppressKeyPress = true; 65 67 } 66 68 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/OrdinalComparisonTimeSpanFilterView.cs
r17180 r18176 59 59 60 60 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 61 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 61 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 62 62 label.Focus(); // set focus on label to validate data 63 if (e.KeyCode == Keys.Escape) { 63 e.SuppressKeyPress = true; 64 } else if (e.KeyCode == Keys.Escape) { 64 65 valueTextBox.Text = Content.Value.ToString(); 65 66 label.Focus(); // set focus on label to validate data 67 e.SuppressKeyPress = true; 66 68 } 67 69 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/StringComparisonAvailableValuesFilterView.cs
r17180 r18176 82 82 83 83 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 84 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 84 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 85 85 label.Focus(); // set focus on label to validate data 86 if (e.KeyCode == Keys.Escape) { 86 e.SuppressKeyPress = true; 87 } else if (e.KeyCode == Keys.Escape) { 87 88 valueComboBox.Text = Content.Value; 88 89 label.Focus(); // set focus on label to validate data 90 e.SuppressKeyPress = true; 89 91 } 90 92 } -
branches/3136_Structural_GP/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/StringComparisonFilterView.cs
r17180 r18176 82 82 83 83 private void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 84 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 84 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 85 85 label.Focus(); // set focus on label to validate data 86 if (e.KeyCode == Keys.Escape) { 86 e.SuppressKeyPress = true; 87 } else if (e.KeyCode == Keys.Escape) { 87 88 valueTextBox.Text = Content.Value; 88 89 label.Focus(); // set focus on label to validate data 90 e.SuppressKeyPress = true; 89 91 } 90 92 } -
branches/3136_Structural_GP/HeuristicLab.Core.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Core.Views (added) merged: 18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Core.Views/3.3/NamedItemView.cs
r17180 r18176 119 119 } 120 120 protected virtual void nameTextBox_KeyDown(object sender, KeyEventArgs e) { 121 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 121 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 122 122 nameLabel.Focus(); // set focus on label to validate data 123 if (e.KeyCode == Keys.Escape) { 123 e.SuppressKeyPress = true; 124 } else if (e.KeyCode == Keys.Escape) { 124 125 nameTextBox.Text = Content.Name; 125 126 nameLabel.Focus(); // set focus on label to validate data 127 e.SuppressKeyPress = true; 126 128 } 127 129 } -
branches/3136_Structural_GP/HeuristicLab.Data.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Data.Views (added) merged: 18165-18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Data.Views/3.3
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Data.Views/3.3 (added) merged: 18165-18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs
r17180 r18176 156 156 } 157 157 private void lengthTextBox_KeyDown(object sender, KeyEventArgs e) { 158 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) 158 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { 159 159 lengthLabel.Focus(); // set focus on label to validate data 160 if (e.KeyCode == Keys.Escape) { 160 e.SuppressKeyPress = true; 161 } else if (e.KeyCode == Keys.Escape) { 161 162 lengthTextBox.Text = Content.Length.ToString(); 162 163 lengthLabel.Focus(); // set focus on label to validate data 164 e.SuppressKeyPress = true; 163 165 } 164 166 } … … 249 251 clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length); //remove last newline constant 250 252 251 var lines = clipboardText.Split(new 253 var lines = clipboardText.Split(new[] { Environment.NewLine }, StringSplitOptions.None); 252 254 var tabSep = new[] { '\t' }; 253 255 if (lines.Length > 2) { -
branches/3136_Structural_GP/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
r17921 r18176 227 227 } 228 228 private void rowsTextBox_KeyDown(object sender, KeyEventArgs e) { 229 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) 229 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { 230 230 rowsLabel.Focus(); // set focus on label to validate data 231 if (e.KeyCode == Keys.Escape) { 231 e.SuppressKeyPress = true; 232 } else if (e.KeyCode == Keys.Escape) { 232 233 rowsTextBox.Text = Content.Rows.ToString(); 233 234 rowsLabel.Focus(); // set focus on label to validate data 235 e.SuppressKeyPress = true; 234 236 } 235 237 } … … 249 251 } 250 252 private void columnsTextBox_KeyDown(object sender, KeyEventArgs e) { 251 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) 253 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { 252 254 columnsLabel.Focus(); // set focus on label to validate data 253 if (e.KeyCode == Keys.Escape) { 255 e.SuppressKeyPress = true; 256 } else if (e.KeyCode == Keys.Escape) { 254 257 columnsTextBox.Text = Content.Columns.ToString(); 255 258 columnsLabel.Focus(); // set focus on label to validate data 259 e.SuppressKeyPress = true; 256 260 } 257 261 } -
branches/3136_Structural_GP/HeuristicLab.Data.Views/3.3/StringConvertibleValueView.cs
r17180 r18176 86 86 87 87 protected virtual void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 88 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 88 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 89 89 valueLabel.Select(); // select label to validate data 90 91 if (e.KeyCode == Keys.Escape) {90 e.SuppressKeyPress = true; 91 } else if (e.KeyCode == Keys.Escape) { 92 92 valueTextBox.Text = Content.GetValue(); 93 93 valueLabel.Select(); // select label to validate data 94 e.SuppressKeyPress = true; 94 95 } 95 96 } -
branches/3136_Structural_GP/HeuristicLab.Data.Views/3.3/TextValueView.cs
r17180 r18176 86 86 87 87 protected virtual void valueTextBox_KeyDown(object sender, KeyEventArgs e) { 88 if (e.Shift && (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)) 88 if (e.Shift && (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)) { 89 89 valueLabel.Select(); // select label to validate data 90 91 if (e.KeyCode == Keys.Escape) {90 e.SuppressKeyPress = true; 91 } else if (e.KeyCode == Keys.Escape) { 92 92 valueTextBox.Text = Content.GetValue(); 93 93 valueLabel.Select(); // select label to validate data 94 e.SuppressKeyPress = true; 94 95 } 95 96 } -
branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views (added) merged: 18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs
r17180 r18176 70 70 #region control event handlers 71 71 private void initialFrequencyTextBox_KeyDown(object sender, KeyEventArgs e) { 72 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 72 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 73 73 initialFrequencyLabel.Select(); // select label to validate data 74 75 if (e.KeyCode == Keys.Escape) {74 e.SuppressKeyPress = true; 75 } else if (e.KeyCode == Keys.Escape) { 76 76 initialFrequencyTextBox.Text = Content.InitialFrequency.ToString(); 77 77 initialFrequencyLabel.Select(); // select label to validate data 78 e.SuppressKeyPress = true; 78 79 } 79 80 } -
branches/3136_Structural_GP/HeuristicLab.Parameters.Views/3.3/ScopeTreeLookupParameterView.cs
r17180 r18176 106 106 } 107 107 protected virtual void depthTextBox_KeyDown(object sender, KeyEventArgs e) { 108 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 108 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 109 109 depthLabel.Focus(); // set focus on label to validate data 110 if (e.KeyCode == Keys.Escape) { 110 e.SuppressKeyPress = true; 111 } else if (e.KeyCode == Keys.Escape) { 111 112 depthTextBox.Text = Content.Depth.ToString(); 112 113 depthLabel.Focus(); // set focus on label to validate data 114 e.SuppressKeyPress = true; 113 115 } 114 116 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 18169,18171-18172,18174
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs
r18146 r18176 158 158 var newExponent = (NumberTreeNode)numberSy.CreateTreeNode(); 159 159 newExponent.Value = ((NumberTreeNode)newPower.GetSubtree(1)).Value - 1; 160 newPower.RemoveSubtree(1); 161 newPower.AddSubtree(newExponent); 160 162 return Product(Product(CreateNumber(exponent.Value), newPower), Derive(f, variableName)); 161 163 } else throw new NotSupportedException("Cannot derive non-integer powers"); -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs
r18157 r18176 37 37 var token = GetToken(node.Symbol); 38 38 // operators 39 if (token == "+" || token == "-" || token == "OR" || token == "XOR" || 40 token == "*" || token == "/" || token == "AND") { 41 strBuilder.Append("("); 39 if (token == "+" || token == "-" || token == "OR" || token == "XOR") { 40 var parenthesisRequired = false; 41 if (node.Parent != null && node.Parent.SubtreeCount > 1) { 42 var parentOp = GetToken(node.Parent.Symbol); 43 if (parentOp != "+" && parentOp != "-" && parentOp != "OR" && parentOp != "XOR") 44 parenthesisRequired = true; 45 } 46 if (parenthesisRequired) strBuilder.Append("("); 42 47 FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters); 43 48 … … 47 52 } 48 53 49 strBuilder.Append(")"); 54 if (parenthesisRequired) strBuilder.Append(")"); 55 } else if (token == "*" || token == "/" || token == "AND") { 56 FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters); 57 58 foreach (var subtree in node.Subtrees.Skip(1)) { 59 strBuilder.Append(" ").Append(token).Append(" "); 60 // a / b * c => a / (b * C) 61 if (subtree.SubtreeCount > 1 && token == "/" && GetToken(subtree.Symbol) == "*") { 62 strBuilder.Append("("); 63 FormatRecursively(subtree, strBuilder, numberFormat, formatString, parameters); 64 strBuilder.Append(")"); 65 } else { 66 FormatRecursively(subtree, strBuilder, numberFormat, formatString, parameters); 67 } 68 } 50 69 } else if (token == "^") { 51 70 // handle integer powers directly 52 strBuilder.Append("(");53 71 FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, parameters); 54 72 … … 60 78 FormatRecursively(power, strBuilder, numberFormat, formatString, parameters); 61 79 } 62 63 strBuilder.Append(")");64 80 } else { 65 81 // function with multiple arguments … … 78 94 var token = GetToken(node.Symbol); 79 95 if (token == "-" || token == "NOT") { 80 strBuilder.Append("(").Append(token).Append("("); 81 FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, parameters); 82 strBuilder.Append("))"); 96 strBuilder.Append(token); 97 FormatRecursively(node.GetSubtree(0), strBuilder, numberFormat, formatString, parameters); 83 98 } else if (token == "/") { 84 99 strBuilder.Append("1/"); … … 97 112 var varNode = node as LaggedVariableTreeNode; 98 113 if (!varNode.Weight.IsAlmost(1.0)) { 99 strBuilder.Append("(");100 114 AppendNumber(strBuilder, parameters, varNode.Weight, formatString, numberFormat); 101 115 strBuilder.Append("*"); … … 107 121 .AppendFormat(numberFormat, "{0}", varNode.Lag) 108 122 .Append(")"); 109 if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");110 123 } else if (node.Symbol is Variable) { 111 124 var varNode = node as VariableTreeNode; 112 125 if (!varNode.Weight.IsAlmost(1.0)) { 113 strBuilder.Append("(");114 126 AppendNumber(strBuilder, parameters, varNode.Weight, formatString, numberFormat); 115 127 strBuilder.Append("*"); 116 128 } 117 118 129 AppendVariableName(strBuilder, varNode.VariableName); 119 120 if (!varNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");121 130 } else if (node.Symbol is FactorVariable) { 122 131 var factorNode = node as FactorVariableTreeNode; … … 132 141 var factorNode = node as BinaryFactorVariableTreeNode; 133 142 if (!factorNode.Weight.IsAlmost(1.0)) { 134 strBuilder.Append("(");135 143 AppendNumber(strBuilder, parameters, factorNode.Weight, formatString, numberFormat); 136 137 144 strBuilder.Append("*"); 138 145 } 139 140 146 AppendVariableName(strBuilder, factorNode.VariableName); 141 147 strBuilder.Append(" = "); 142 148 AppendVariableName(strBuilder, factorNode.VariableValue); 143 144 if (!factorNode.Weight.IsAlmost(1.0)) strBuilder.Append(")");145 149 } else if (node is INumericTreeNode numNode) { 146 150 if (parameters == null && numNode.Value < 0) { 147 151 // negative value 148 strBuilder.Append("(").Append(numNode.Value.ToString(formatString, numberFormat)) 149 .Append(")"); 152 strBuilder.Append(numNode.Value.ToString(formatString, numberFormat)); 150 153 } else { 151 154 AppendNumber(strBuilder, parameters, numNode.Value, formatString, numberFormat); -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r18157 r18176 40 40 /// 41 41 /// S = Expr EOF 42 /// Expr = ['-' | '+']Term { '+' Term | '-' Term }42 /// Expr = Term { '+' Term | '-' Term } 43 43 /// Term = Fact { '*' Fact | '/' Fact } 44 44 /// Fact = SimpleFact [ '^' SimpleFact ] … … 49 49 /// | VarExpr 50 50 /// | number 51 /// | ['+' | '-'] SimpleFact 51 52 /// ArgList = Expr { ',' Expr } 52 53 /// VarExpr = varId OptFactorPart 53 /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ]number } ']' ) ]54 /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ] number } ']' ) ] 54 55 /// varId = ident | ' ident ' | " ident " 55 56 /// varVal = ident | ' ident ' | " ident " … … 84 85 85 86 private Number number = new Number(); 86 private Constant constant = new Constant();87 private Constant minusOne = new Constant() { Value = -1 }; 87 88 private Variable variable = new Variable(); 88 89 private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable(); … … 139 140 { "XOR", new Xor()}, 140 141 { "DIFF", new Derivative()}, 141 { "LAG", new LaggedVariable() } 142 { "LAG", new LaggedVariable() }, 142 143 }; 143 144 … … 163 164 int pos = 0; 164 165 while (true) { 165 while (pos < str.Length && Char.IsWhiteSpace(str[pos])) pos++;166 while (pos < str.Length && char.IsWhiteSpace(str[pos])) pos++; 166 167 if (pos >= str.Length) { 167 168 yield return new Token { TokenType = TokenType.End, strVal = "" }; … … 169 170 } 170 171 if (char.IsDigit(str[pos])) { 171 // read number (=> read until white space or o perator or comma)172 // read number (=> read until white space or other symbol) 172 173 var sb = new StringBuilder(); 173 174 sb.Append(str[pos]); … … 270 271 } else if (str[pos] == '<') { 271 272 pos++; 272 yield return new Token { TokenType = TokenType.LeftAngleBracket, strVal = "<"};273 yield return new Token { TokenType = TokenType.LeftAngleBracket, strVal = "<" }; 273 274 } else if (str[pos] == '>') { 274 275 pos++; 275 yield return new Token { TokenType = TokenType.RightAngleBracket, strVal = ">"};276 yield return new Token { TokenType = TokenType.RightAngleBracket, strVal = ">" }; 276 277 } else { 277 278 throw new ArgumentException("Invalid character: " + str[pos]); … … 290 291 } 291 292 292 /// Expr = ['-' | '+']Term { '+' Term | '-' Term }293 /// Expr = Term { '+' Term | '-' Term } 293 294 private ISymbolicExpressionTreeNode ParseExpr(Queue<Token> tokens) { 295 // build tree from bottom to top and left to right 296 // a + b - c => ((a + b) - c) 297 // a - b - c => ((a - b) - c) 298 // and then flatten as far as possible 299 var left = ParseTerm(tokens); 300 294 301 var next = tokens.Peek(); 295 var posTerms = new List<ISymbolicExpressionTreeNode>();296 var negTerms = new List<ISymbolicExpressionTreeNode>();297 bool negateFirstTerm = false;298 if (next.TokenType == TokenType.Operator && (next.strVal == "+" || next.strVal == "-")) {299 tokens.Dequeue();300 if (next.strVal == "-")301 negateFirstTerm = true;302 }303 var t = ParseTerm(tokens);304 if (negateFirstTerm) negTerms.Add(t);305 else posTerms.Add(t);306 307 next = tokens.Peek();308 302 while (next.strVal == "+" || next.strVal == "-") { 309 303 switch (next.strVal) { 310 304 case "+": { 311 305 tokens.Dequeue(); 312 var term = ParseTerm(tokens); 313 posTerms.Add(term); 306 var right = ParseTerm(tokens); 307 var op = GetSymbol("+").CreateTreeNode(); 308 op.AddSubtree(left); 309 op.AddSubtree(right); 310 left = op; 314 311 break; 315 312 } 316 313 case "-": { 317 314 tokens.Dequeue(); 318 var term = ParseTerm(tokens); 319 negTerms.Add(term); 315 var right = ParseTerm(tokens); 316 var op = GetSymbol("-").CreateTreeNode(); 317 op.AddSubtree(left); 318 op.AddSubtree(right); 319 left = op; 320 320 break; 321 321 } … … 324 324 } 325 325 326 var sum = GetSymbol("+").CreateTreeNode(); 327 foreach (var posTerm in posTerms) sum.AddSubtree(posTerm); 328 if (negTerms.Any()) { 329 if (negTerms.Count == 1) { 330 var sub = GetSymbol("-").CreateTreeNode(); 331 sub.AddSubtree(negTerms.Single()); 332 sum.AddSubtree(sub); 333 } else { 334 var sumNeg = GetSymbol("+").CreateTreeNode(); 335 foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm); 336 337 var constNode = (NumberTreeNode)number.CreateTreeNode(); 338 constNode.Value = -1.0; 339 var prod = GetSymbol("*").CreateTreeNode(); 340 prod.AddSubtree(constNode); 341 prod.AddSubtree(sumNeg); 342 343 sum.AddSubtree(prod); 344 } 345 } 346 if (sum.SubtreeCount == 1) return sum.Subtrees.First(); 347 else return sum; 326 FoldLeftRecursive(left); 327 return left; 348 328 } 349 329 350 330 private ISymbol GetSymbol(string tok) { 351 if (knownSymbols.ContainsFirst(tok))331 if (knownSymbols.ContainsFirst(tok)) 352 332 return knownSymbols.GetByFirst(tok).FirstOrDefault(); 353 333 else … … 357 337 /// Term = Fact { '*' Fact | '/' Fact } 358 338 private ISymbolicExpressionTreeNode ParseTerm(Queue<Token> tokens) { 359 var factors = new List<ISymbolicExpressionTreeNode>(); 360 var firstFactor = ParseFact(tokens); 361 factors.Add(firstFactor); 339 // build tree from bottom to top and left to right 340 // a / b * c => ((a / b) * c) 341 // a / b / c => ((a / b) / c) 342 // and then flatten as far as possible 343 344 var left = ParseFact(tokens); 362 345 363 346 var next = tokens.Peek(); … … 366 349 case "*": { 367 350 tokens.Dequeue(); 368 var fact = ParseFact(tokens); 369 factors.Add(fact); 351 var right = ParseFact(tokens); 352 353 var op = GetSymbol("*").CreateTreeNode(); 354 op.AddSubtree(left); 355 op.AddSubtree(right); 356 left = op; 370 357 break; 371 358 } 372 359 case "/": { 373 360 tokens.Dequeue(); 374 var invFact = ParseFact(tokens); 375 var divNode = GetSymbol("/").CreateTreeNode(); // 1/x 376 divNode.AddSubtree(invFact); 377 factors.Add(divNode); 361 var right = ParseFact(tokens); 362 var op = GetSymbol("/").CreateTreeNode(); 363 op.AddSubtree(left); 364 op.AddSubtree(right); 365 left = op; 378 366 break; 379 367 } … … 382 370 next = tokens.Peek(); 383 371 } 384 if (factors.Count == 1) return factors.First(); 385 else { 386 var prod = GetSymbol("*").CreateTreeNode(); 387 foreach (var f in factors) prod.AddSubtree(f); 388 return prod; 372 // remove all nodes where the child op is the same as the parent op 373 // (a * b) * c) => (a * b * c) 374 // (a / b) / c) => (a / b / c) 375 376 FoldLeftRecursive(left); 377 return left; 378 } 379 380 private void FoldLeftRecursive(ISymbolicExpressionTreeNode parent) { 381 if (parent.SubtreeCount > 1) { 382 var child = parent.GetSubtree(0); 383 FoldLeftRecursive(child); 384 if (parent.Symbol == child.Symbol && IsAssociative(parent.Symbol)) { 385 parent.RemoveSubtree(0); 386 for (int i = 0; i < child.SubtreeCount; i++) { 387 parent.InsertSubtree(i, child.GetSubtree(i)); 388 } 389 } 389 390 } 390 391 } … … 411 412 /// | funcId '(' ArgList ') 412 413 /// | VarExpr 414 /// | '<' 'num' [ '=' [ '+' | '-' ] number ] '>' 413 415 /// | number 416 /// | ['+' | '-' ] SimpleFact 414 417 /// ArgList = Expr { ',' Expr } 415 418 /// VarExpr = varId OptFactorPart … … 435 438 if (tokens.Peek().TokenType == TokenType.LeftPar) { 436 439 // function identifier or LAG 437 var funcId = idTok.strVal.ToUpperInvariant(); 438 439 var funcNode = GetSymbol(funcId).CreateTreeNode(); 440 var lPar = tokens.Dequeue(); 441 if (lPar.TokenType != TokenType.LeftPar) 442 throw new ArgumentException("expected ("); 443 444 // handle 'lag' specifically 445 if (funcNode.Symbol is LaggedVariable) { 446 var varId = tokens.Dequeue(); 447 if (varId.TokenType != TokenType.Identifier) throw new ArgumentException("Identifier expected. Format for lagged variables: \"lag(x, -1)\""); 448 var comma = tokens.Dequeue(); 449 if (comma.TokenType != TokenType.Comma) throw new ArgumentException("',' expected, Format for lagged variables: \"lag(x, -1)\""); 450 double sign = 1.0; 451 if (tokens.Peek().strVal == "+" || tokens.Peek().strVal == "-") { 452 // read sign 453 var signTok = tokens.Dequeue(); 454 if (signTok.strVal == "-") sign = -1.0; 455 } 456 var lagToken = tokens.Dequeue(); 457 if (lagToken.TokenType != TokenType.Number) throw new ArgumentException("Number expected, Format for lagged variables: \"lag(x, -1)\""); 458 if (!lagToken.doubleVal.IsAlmost(Math.Round(lagToken.doubleVal))) 459 throw new ArgumentException("Time lags must be integer values"); 460 var laggedVarNode = funcNode as LaggedVariableTreeNode; 461 laggedVarNode.VariableName = varId.strVal; 462 laggedVarNode.Lag = (int)Math.Round(sign * lagToken.doubleVal); 463 laggedVarNode.Weight = 1.0; 464 } else if (funcNode.Symbol is SubFunctionSymbol) { // SubFunction 465 var subFunction = funcNode as SubFunctionTreeNode; 466 subFunction.Name = next.strVal; 467 // input arguments 468 var args = ParseArgList(tokens); 469 IList<string> arguments = new List<string>(); 470 foreach (var arg in args) 471 if(arg is VariableTreeNode varTreeNode) 472 arguments.Add(varTreeNode.VariableName); 473 subFunction.Arguments = arguments; 440 return ParseFunctionOrLaggedVariable(tokens, idTok); 441 } else { 442 return ParseVariable(tokens, idTok); 443 } 444 } else if (next.TokenType == TokenType.LeftAngleBracket) { 445 // '<' 'num' [ '=' ['+'|'-'] number ] '>' 446 return ParseNumber(tokens); 447 } else if (next.TokenType == TokenType.Operator && (next.strVal == "-" || next.strVal == "+")) { 448 // ['+' | '-' ] SimpleFact 449 if (tokens.Dequeue().strVal == "-") { 450 var arg = ParseSimpleFact(tokens); 451 if (arg is NumberTreeNode numNode) { 452 numNode.Value *= -1; 453 return numNode; 454 } else if (arg is ConstantTreeNode constNode) { 455 var constSy = new Constant { Value = -constNode.Value }; 456 return constSy.CreateTreeNode(); 457 } else if (arg is VariableTreeNode varNode) { 458 varNode.Weight *= -1; 459 return varNode; 474 460 } else { 475 // functions 476 var args = ParseArgList(tokens); 477 // check number of arguments 478 if (funcNode.Symbol.MinimumArity > args.Length || funcNode.Symbol.MaximumArity < args.Length) { 479 throw new ArgumentException(string.Format("Symbol {0} requires between {1} and {2} arguments.", funcId, 480 funcNode.Symbol.MinimumArity, funcNode.Symbol.MaximumArity)); 481 } 482 foreach (var arg in args) funcNode.AddSubtree(arg); 461 var mul = GetSymbol("*").CreateTreeNode(); 462 var neg = minusOne.CreateTreeNode(); 463 mul.AddSubtree(neg); 464 mul.AddSubtree(arg); 465 return mul; 483 466 } 484 485 var rPar = tokens.Dequeue();486 if (rPar.TokenType != TokenType.RightPar)487 throw new ArgumentException("expected )");488 489 490 return funcNode;491 467 } else { 492 // variable 493 if (tokens.Peek().TokenType == TokenType.Eq) { 494 // binary factor 495 tokens.Dequeue(); // skip Eq 496 var valTok = tokens.Dequeue(); 497 if (valTok.TokenType != TokenType.Identifier) throw new ArgumentException("expected identifier"); 498 var binFactorNode = (BinaryFactorVariableTreeNode)binaryFactorVar.CreateTreeNode(); 499 binFactorNode.Weight = 1.0; 500 binFactorNode.VariableName = idTok.strVal; 501 binFactorNode.VariableValue = valTok.strVal; 502 return binFactorNode; 503 } else if (tokens.Peek().TokenType == TokenType.LeftBracket) { 504 // factor variable 505 var factorVariableNode = (FactorVariableTreeNode)factorVar.CreateTreeNode(); 506 factorVariableNode.VariableName = idTok.strVal; 507 508 tokens.Dequeue(); // skip [ 509 var weights = new List<double>(); 510 // at least one weight is necessary 511 var sign = 1.0; 512 if (tokens.Peek().TokenType == TokenType.Operator) { 513 var opToken = tokens.Dequeue(); 514 if (opToken.strVal == "+") sign = 1.0; 515 else if (opToken.strVal == "-") sign = -1.0; 516 else throw new ArgumentException(); 517 } 518 if (tokens.Peek().TokenType != TokenType.Number) throw new ArgumentException("number expected"); 519 var weightTok = tokens.Dequeue(); 520 weights.Add(sign * weightTok.doubleVal); 521 while (tokens.Peek().TokenType == TokenType.Comma) { 522 // skip comma 523 tokens.Dequeue(); 524 if (tokens.Peek().TokenType == TokenType.Operator) { 525 var opToken = tokens.Dequeue(); 526 if (opToken.strVal == "+") sign = 1.0; 527 else if (opToken.strVal == "-") sign = -1.0; 528 else throw new ArgumentException(); 529 } 530 weightTok = tokens.Dequeue(); 531 if (weightTok.TokenType != TokenType.Number) throw new ArgumentException("number expected"); 532 weights.Add(sign * weightTok.doubleVal); 533 } 534 var rightBracketToken = tokens.Dequeue(); 535 if (rightBracketToken.TokenType != TokenType.RightBracket) throw new ArgumentException("closing bracket ] expected"); 536 factorVariableNode.Weights = weights.ToArray(); 537 return factorVariableNode; 538 } else { 539 // variable 540 var varNode = (VariableTreeNode)variable.CreateTreeNode(); 541 varNode.Weight = 1.0; 542 varNode.VariableName = idTok.strVal; 543 return varNode; 544 } 545 } 546 } else if (next.TokenType == TokenType.LeftAngleBracket) { 547 Token numberTok = null; 548 var leftAngleBracket = tokens.Dequeue(); 549 if (leftAngleBracket.TokenType != TokenType.LeftAngleBracket) 550 throw new ArgumentException("opening bracket < expected"); 551 552 var idTok = tokens.Dequeue(); 553 if (idTok.TokenType != TokenType.Identifier || idTok.strVal.ToLower() != "num") 554 throw new ArgumentException("string 'num' expected"); 555 556 if (tokens.Peek().TokenType == TokenType.Eq) { 557 var equalTok = tokens.Dequeue(); 558 if (tokens.Peek().TokenType != TokenType.Number) 559 throw new ArgumentException("No value for number specified."); 560 561 numberTok = tokens.Dequeue(); 562 } 563 564 var rightAngleBracket = tokens.Dequeue(); 565 if (rightAngleBracket.TokenType != TokenType.RightAngleBracket) 566 throw new ArgumentException("closing bracket > expected"); 567 var numNode = (NumberTreeNode)number.CreateTreeNode(); 568 if (numberTok != null) numNode.Value = numberTok.doubleVal; 569 return numNode; 468 return ParseSimpleFact(tokens); 469 } 570 470 } else if (next.TokenType == TokenType.Number) { 471 // number 571 472 var numTok = tokens.Dequeue(); 572 var constSy = new Constant { Value = numTok.doubleVal};473 var constSy = new Constant { Value = numTok.doubleVal }; 573 474 return constSy.CreateTreeNode(); 574 475 } else { 575 476 throw new ArgumentException(string.Format("unexpected token in expression {0}", next.strVal)); 576 477 } 478 } 479 480 private ISymbolicExpressionTreeNode ParseNumber(Queue<Token> tokens) { 481 // we distinguish parameters and constants. The values of parameters can be changed. 482 // a parameter is written as '<' 'num' [ '=' ['+'|'-'] number ] '>' with an optional initialization 483 Token numberTok = null; 484 var leftAngleBracket = tokens.Dequeue(); 485 if (leftAngleBracket.TokenType != TokenType.LeftAngleBracket) 486 throw new ArgumentException("opening bracket < expected"); 487 488 var idTok = tokens.Dequeue(); 489 if (idTok.TokenType != TokenType.Identifier || idTok.strVal.ToLower() != "num") 490 throw new ArgumentException("string 'num' expected"); 491 492 var numNode = (NumberTreeNode)number.CreateTreeNode(); 493 494 if (tokens.Peek().TokenType == TokenType.Eq) { 495 tokens.Dequeue(); // skip "=" 496 var next = tokens.Peek(); 497 if (next.strVal != "+" && next.strVal != "-" && next.TokenType != TokenType.Number) 498 throw new ArgumentException("Expected '+', '-' or number."); 499 500 var sign = 1.0; 501 if (next.strVal == "+" || next.strVal == "-") { 502 if (tokens.Dequeue().strVal == "-") sign = -1.0; 503 } 504 if (tokens.Peek().TokenType != TokenType.Number) { 505 throw new ArgumentException("Expected number."); 506 } 507 numberTok = tokens.Dequeue(); 508 numNode.Value = sign * numberTok.doubleVal; 509 } 510 511 var rightAngleBracket = tokens.Dequeue(); 512 if (rightAngleBracket.TokenType != TokenType.RightAngleBracket) 513 throw new ArgumentException("closing bracket > expected"); 514 515 return numNode; 516 } 517 518 private ISymbolicExpressionTreeNode ParseVariable(Queue<Token> tokens, Token idTok) { 519 // variable 520 if (tokens.Peek().TokenType == TokenType.Eq) { 521 // binary factor 522 tokens.Dequeue(); // skip Eq 523 var valTok = tokens.Dequeue(); 524 if (valTok.TokenType != TokenType.Identifier) throw new ArgumentException("expected identifier"); 525 var binFactorNode = (BinaryFactorVariableTreeNode)binaryFactorVar.CreateTreeNode(); 526 binFactorNode.Weight = 1.0; 527 binFactorNode.VariableName = idTok.strVal; 528 binFactorNode.VariableValue = valTok.strVal; 529 return binFactorNode; 530 } else if (tokens.Peek().TokenType == TokenType.LeftBracket) { 531 // factor variable 532 var factorVariableNode = (FactorVariableTreeNode)factorVar.CreateTreeNode(); 533 factorVariableNode.VariableName = idTok.strVal; 534 535 tokens.Dequeue(); // skip [ 536 var weights = new List<double>(); 537 // at least one weight is necessary 538 var sign = 1.0; 539 if (tokens.Peek().TokenType == TokenType.Operator) { 540 var opToken = tokens.Dequeue(); 541 if (opToken.strVal == "+") sign = 1.0; 542 else if (opToken.strVal == "-") sign = -1.0; 543 else throw new ArgumentException(); 544 } 545 if (tokens.Peek().TokenType != TokenType.Number) throw new ArgumentException("number expected"); 546 var weightTok = tokens.Dequeue(); 547 weights.Add(sign * weightTok.doubleVal); 548 while (tokens.Peek().TokenType == TokenType.Comma) { 549 // skip comma 550 tokens.Dequeue(); 551 if (tokens.Peek().TokenType == TokenType.Operator) { 552 var opToken = tokens.Dequeue(); 553 if (opToken.strVal == "+") sign = 1.0; 554 else if (opToken.strVal == "-") sign = -1.0; 555 else throw new ArgumentException(); 556 } 557 weightTok = tokens.Dequeue(); 558 if (weightTok.TokenType != TokenType.Number) throw new ArgumentException("number expected"); 559 weights.Add(sign * weightTok.doubleVal); 560 } 561 var rightBracketToken = tokens.Dequeue(); 562 if (rightBracketToken.TokenType != TokenType.RightBracket) throw new ArgumentException("closing bracket ] expected"); 563 factorVariableNode.Weights = weights.ToArray(); 564 return factorVariableNode; 565 } else { 566 // variable 567 var varNode = (VariableTreeNode)variable.CreateTreeNode(); 568 varNode.Weight = 1.0; 569 varNode.VariableName = idTok.strVal; 570 return varNode; 571 } 572 } 573 574 private ISymbolicExpressionTreeNode ParseFunctionOrLaggedVariable(Queue<Token> tokens, Token idTok) { 575 var funcId = idTok.strVal.ToUpperInvariant(); 576 577 var funcNode = GetSymbol(funcId).CreateTreeNode(); 578 var lPar = tokens.Dequeue(); 579 if (lPar.TokenType != TokenType.LeftPar) 580 throw new ArgumentException("expected ("); 581 582 // handle 'lag' specifically 583 if (funcNode.Symbol is LaggedVariable) { 584 ParseLaggedVariable(tokens, funcNode); 585 } else if (funcNode.Symbol is SubFunctionSymbol) { // SubFunction 586 var subFunction = funcNode as SubFunctionTreeNode; 587 subFunction.Name = idTok.strVal; 588 // input arguments 589 var args = ParseArgList(tokens); 590 IList<string> arguments = new List<string>(); 591 foreach (var arg in args) 592 if (arg is VariableTreeNode varTreeNode) 593 arguments.Add(varTreeNode.VariableName); 594 subFunction.Arguments = arguments; 595 } else { 596 // functions 597 var args = ParseArgList(tokens); 598 // check number of arguments 599 if (funcNode.Symbol.MinimumArity > args.Length || funcNode.Symbol.MaximumArity < args.Length) { 600 throw new ArgumentException(string.Format("Symbol {0} requires between {1} and {2} arguments.", funcId, 601 funcNode.Symbol.MinimumArity, funcNode.Symbol.MaximumArity)); 602 } 603 foreach (var arg in args) funcNode.AddSubtree(arg); 604 } 605 606 var rPar = tokens.Dequeue(); 607 if (rPar.TokenType != TokenType.RightPar) 608 throw new ArgumentException("expected )"); 609 610 611 return funcNode; 612 } 613 614 private static void ParseLaggedVariable(Queue<Token> tokens, ISymbolicExpressionTreeNode funcNode) { 615 var varId = tokens.Dequeue(); 616 if (varId.TokenType != TokenType.Identifier) throw new ArgumentException("Identifier expected. Format for lagged variables: \"lag(x, -1)\""); 617 var comma = tokens.Dequeue(); 618 if (comma.TokenType != TokenType.Comma) throw new ArgumentException("',' expected, Format for lagged variables: \"lag(x, -1)\""); 619 double sign = 1.0; 620 if (tokens.Peek().strVal == "+" || tokens.Peek().strVal == "-") { 621 // read sign 622 var signTok = tokens.Dequeue(); 623 if (signTok.strVal == "-") sign = -1.0; 624 } 625 var lagToken = tokens.Dequeue(); 626 if (lagToken.TokenType != TokenType.Number) throw new ArgumentException("Number expected, Format for lagged variables: \"lag(x, -1)\""); 627 if (!lagToken.doubleVal.IsAlmost(Math.Round(lagToken.doubleVal))) 628 throw new ArgumentException("Time lags must be integer values"); 629 var laggedVarNode = funcNode as LaggedVariableTreeNode; 630 laggedVarNode.VariableName = varId.strVal; 631 laggedVarNode.Lag = (int)Math.Round(sign * lagToken.doubleVal); 632 laggedVarNode.Weight = 1.0; 577 633 } 578 634 … … 588 644 return exprList.ToArray(); 589 645 } 646 647 private bool IsAssociative(ISymbol sy) { 648 return sy == GetSymbol("+") || sy == GetSymbol("-") || 649 sy == GetSymbol("*") || sy == GetSymbol("/") || 650 sy == GetSymbol("AND") || sy == GetSymbol("OR") || sy == GetSymbol("XOR"); 651 } 590 652 } 591 653 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 18166
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r17180 r18176 70 70 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) { 71 71 timeFrameLabel.Select(); // select label to validate data 72 } 73 74 if (e.KeyCode == Keys.Escape) { 72 e.SuppressKeyPress = true; 73 } else if (e.KeyCode == Keys.Escape) { 75 74 timeframeTextbox.Text = lastFramesValue; 76 75 timeFrameLabel.Select(); // select label to validate data 76 e.SuppressKeyPress = true; 77 77 } 78 78 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Views/3.4/TimeSeriesPrognosis/TimeSeriesPrognosisResultsView.cs
r17180 r18176 107 107 108 108 private void TrainingHorizonTextBox_KeyDown(object sender, KeyEventArgs e) { 109 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 109 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 110 110 TrainingHorizonLabel.Select(); // select label to validate data 111 112 if (e.KeyCode == Keys.Escape) {111 e.SuppressKeyPress = true; 112 } else if (e.KeyCode == Keys.Escape) { 113 113 TrainingHorizonTextBox.Text = Content.TrainingHorizon.ToString(); 114 114 TrainingHorizonLabel.Select(); // select label to validate data 115 e.SuppressKeyPress = true; 115 116 } 116 117 } … … 132 133 133 134 private void TestHorizonTextBox_KeyDown(object sender, KeyEventArgs e) { 134 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) 135 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 135 136 TestHorizonLabel.Select(); // select label to validate data 136 137 if (e.KeyCode == Keys.Escape) {137 e.SuppressKeyPress = true; 138 } else if (e.KeyCode == Keys.Escape) { 138 139 TestHorizonTextBox.Text = Content.TestHorizon.ToString(); 139 140 TestHorizonLabel.Select(); // select label to validate data 141 e.SuppressKeyPress = true; 140 142 } 141 143 } -
branches/3136_Structural_GP/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 18167-18173
- Property svn:mergeinfo changed
-
branches/3136_Structural_GP/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs
r18146 r18176 34 34 public void DeriveExpressions() { 35 35 var formatter = new InfixExpressionFormatter(); 36 var parser = new InfixExpressionParser();37 36 Assert.AreEqual("0", Derive("<num=3>", "x")); 38 37 Assert.AreEqual("1", Derive("x", "x")); 39 38 Assert.AreEqual("10", Derive("<num=10>*x", "x")); 40 39 Assert.AreEqual("10", Derive("x*<num=10>", "x")); 41 Assert.AreEqual(" (2*'x')", Derive("x*x", "x"));42 Assert.AreEqual(" ((('x' * 'x') * 2) + ('x' * 'x'))", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x to 3*x*x40 Assert.AreEqual("2*'x'", Derive("x*x", "x")); 41 Assert.AreEqual("'x' * 'x' * 2 + 'x' * 'x'", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x to 3*x*x 43 42 Assert.AreEqual("0", Derive("<num=10>*x", "y")); 44 43 Assert.AreEqual("20", Derive("<num=10>*x+<num=20>*y", "y")); 45 44 Assert.AreEqual("6", Derive("<num=2>*<num=3>*x", "x")); 46 Assert.AreEqual(" (10*'y')", Derive("<num=10>*x*y+<num=20>*y", "x"));47 Assert.AreEqual(" (1 / (SQR('x') * (-1)))", Derive("1/x", "x"));48 Assert.AreEqual(" ('y' / (SQR('x') * (-1)))", Derive("y/x", "x"));49 Assert.AreEqual("( (((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + ('x' * 'x'))))",45 Assert.AreEqual("10*'y'", Derive("<num=10>*x*y+<num=20>*y", "x")); 46 Assert.AreEqual("1 * -1 / SQR('x')", Derive("1/x", "x")); 47 Assert.AreEqual("-1*'y' / SQR('x')", Derive("y/x", "x")); 48 Assert.AreEqual("('a' + 'b') * (-2*'x' + -1) / SQR('x' + 'x' * 'x')", 50 49 Derive("(a+b)/(x+x*x)", "x")); 51 Assert.AreEqual("( (((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + SQR('x'))))", Derive("(a+b)/(x+SQR(x))", "x"));50 Assert.AreEqual("('a' + 'b') * (-2*'x' + -1) / SQR('x' + SQR('x'))", Derive("(a+b)/(x+SQR(x))", "x")); 52 51 Assert.AreEqual("EXP('x')", Derive("exp(x)", "x")); 53 Assert.AreEqual(" (EXP((3*'x')) * 3)", Derive("exp(<num=3>*x)", "x"));54 Assert.AreEqual(" (1 / 'x')", Derive("log(x)", "x"));55 Assert.AreEqual(" (1 / 'x')", Derive("log(<num=3>*x)", "x")); // 3 * 1/(3*x)56 Assert.AreEqual(" (1 / ('x' + (0.333333333333333*'y')))", Derive("log(<num=3>*x+y)", "x")); // simplifier does not try to keep fractions57 Assert.AreEqual(" (1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(<num=3>*x+y)", "x")); // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y))58 Assert.AreEqual(" (COS((3*'x')) * 3)", Derive("sin(<num=3>*x)", "x"));59 Assert.AreEqual(" (SIN((3*'x')) * (-3))", Derive("cos(<num=3>*x)", "x"));60 Assert.AreEqual(" (1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator52 Assert.AreEqual("EXP(3*'x') * 3", Derive("exp(<num=3>*x)", "x")); 53 Assert.AreEqual("1 / 'x'", Derive("log(x)", "x")); 54 Assert.AreEqual("1 / 'x'", Derive("log(<num=3>*x)", "x")); // 3 * 1/(3*x) 55 Assert.AreEqual("1 / ('x' + 0.333333333333333*'y')", Derive("log(<num=3>*x+y)", "x")); // simplifier does not try to keep fractions 56 Assert.AreEqual("1 / (SQRT(3*'x' + 'y') * 0.666666666666667)", Derive("sqrt(<num=3>*x+y)", "x")); // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y)) 57 Assert.AreEqual("COS(3*'x') * 3", Derive("sin(<num=3>*x)", "x")); 58 Assert.AreEqual("SIN(3*'x') * -3", Derive("cos(<num=3>*x)", "x")); 59 Assert.AreEqual("1 / (SQR(COS(3*'x')) * 0.333333333333333)", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator 61 60 62 Assert.AreEqual(" ((9*'x') / ABS((3*'x')))", Derive("abs(<num=3>*x)", "x"));63 Assert.AreEqual(" (SQR('x') * 3)", Derive("cube(x)", "x"));64 Assert.AreEqual(" (1 / (SQR(CUBEROOT('x')) * 3))", Derive("cuberoot(x)", "x"));61 Assert.AreEqual("9*'x' / ABS(3*'x')", Derive("abs(<num=3>*x)", "x")); 62 Assert.AreEqual("SQR('x') * 3", Derive("cube(x)", "x")); 63 Assert.AreEqual("1 / (SQR(CUBEROOT('x')) * 3)", Derive("cuberoot(x)", "x")); 65 64 66 65 Assert.AreEqual("0", Derive("(a+b)/(x+SQR(x))", "y")); // df(a,b,x) / dy = 0 67 66 68 67 69 Assert.AreEqual(" ('a' * 'b' * 'c')", Derive("a*b*c*d", "d"));70 Assert.AreEqual(" ('a' / ('b' * 'c' * SQR('d') * (-1)))", Derive("a/b/c/d", "d"));68 Assert.AreEqual("'a' * 'b' * 'c'", Derive("a*b*c*d", "d")); 69 Assert.AreEqual("'b' * 'c' * -1*'a' / (SQR('b') * SQR('c') * SQR('d'))", Derive("a/b/c/d", "d")); // TODO simplifier should be able to simplify this 71 70 72 Assert.AreEqual(" ('x' * ((SQR(TANH(SQR('x'))) * (-1)) + 1) * 2)", Derive("tanh(sqr(x))", "x")); // (2*'x'*(1 - SQR(TANH(SQR('x'))))71 Assert.AreEqual("'x' * (SQR(TANH(SQR('x'))) * -1 + 1) * 2", Derive("tanh(sqr(x))", "x")); // (2*'x'*(1 - SQR(TANH(SQR('x')))) 73 72 74 73 { … … 85 84 root.AddSubtree(start); 86 85 var t = new SymbolicExpressionTree(root); 87 Assert.AreEqual(" (1 / (SQR('x') * (-1)))",86 Assert.AreEqual("1 / (SQR('x') * -1)", 88 87 formatter.Format(DerivativeCalculator.Derive(t, "x"))); 89 88 } … … 125 124 var t = new SymbolicExpressionTree(root); 126 125 127 Assert.AreEqual(" (('y' * 'z' * 60) / (SQR('y') * SQR('z') * 400))", // actually 3 / (4y 5z) but simplifier is not smart enough to cancel numerator and denominator126 Assert.AreEqual("'y' * 'z' * 60 / (SQR('y') * SQR('z') * 400)", // actually 3 / (4y 5z) but simplifier is not smart enough to cancel numerator and denominator 128 127 // 60 y z / y² z² 20² == 6 / y z 40 == 3 / y z 20 129 128 formatter.Format(DerivativeCalculator.Derive(t, "x"))); 130 Assert.AreEqual(" (('x' * 'z' * (-60)) / (SQR('y') * SQR('z') * 400))", // actually 3x * -(4 5 z) / (4y 5z)² = -3x / (20 y² z)129 Assert.AreEqual("'x' * 'z' * -60 / (SQR('y') * SQR('z') * 400)", // actually 3x * -(4 5 z) / (4y 5z)² = -3x / (20 y² z) 131 130 // -3 4 5 x z / 4² y² 5² z² = -60 x z / 20² z² y² == -60 x z / y² z² 20² 132 131 formatter.Format(DerivativeCalculator.Derive(t, "y"))); 133 Assert.AreEqual(" (('x' * 'y' * (-60)) / (SQR('y') * SQR('z') * 400))",132 Assert.AreEqual("'x' * 'y' * -60 / (SQR('y') * SQR('z') * 400)", 134 133 formatter.Format(DerivativeCalculator.Derive(t, "z"))); 135 134 } -
branches/3136_Structural_GP/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/InfixExpressionParserTest.cs
r17180 r18176 34 34 var formatter = new InfixExpressionFormatter(); 35 35 var parser = new InfixExpressionParser(); 36 Console.WriteLine(formatter.Format(parser.Parse("3")));37 Console.WriteLine(formatter.Format(parser.Parse("3*3")));38 Console.WriteLine(formatter.Format(parser.Parse("3 * 4")));39 Console.WriteLine(formatter.Format(parser.Parse("123E-03")));40 Console.WriteLine(formatter.Format(parser.Parse("123e-03")));41 Console.WriteLine(formatter.Format(parser.Parse("123e+03")));42 Console.WriteLine(formatter.Format(parser.Parse("123E+03")));43 Console.WriteLine(formatter.Format(parser.Parse("123.0E-03")));44 Console.WriteLine(formatter.Format(parser.Parse("123.0e-03")));45 Console.WriteLine(formatter.Format(parser.Parse("123.0e+03")));46 Console.WriteLine(formatter.Format(parser.Parse("123.0E+03")));47 Console.WriteLine(formatter.Format(parser.Parse("123.0E-3")));48 Console.WriteLine(formatter.Format(parser.Parse("123.0e-3")));49 Console.WriteLine(formatter.Format(parser.Parse("123.0e+3")));50 Console.WriteLine(formatter.Format(parser.Parse("123.0E+3")));36 Assert.AreEqual("3", formatter.Format(parser.Parse("3"))); 37 Assert.AreEqual("3 * 3", formatter.Format(parser.Parse("3*3"))); 38 Assert.AreEqual("3 * 4",formatter.Format(parser.Parse("3 * 4"))); 39 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123E-03"))); 40 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123e-03"))); 41 Assert.AreEqual("123000",formatter.Format(parser.Parse("123e+03"))); 42 Assert.AreEqual("123000",formatter.Format(parser.Parse("123E+03"))); 43 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123.0E-03"))); 44 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123.0e-03"))); 45 Assert.AreEqual("123000",formatter.Format(parser.Parse("123.0e+03"))); 46 Assert.AreEqual("123000",formatter.Format(parser.Parse("123.0E+03"))); 47 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123.0E-3"))); 48 Assert.AreEqual("0.123",formatter.Format(parser.Parse("123.0e-3"))); 49 Assert.AreEqual("123000",formatter.Format(parser.Parse("123.0e+3"))); 50 Assert.AreEqual("123000",formatter.Format(parser.Parse("123.0E+3"))); 51 51 52 Console.WriteLine(formatter.Format(parser.Parse("3.1415+2.0")));53 Console.WriteLine(formatter.Format(parser.Parse("3.1415/2.0")));54 Console.WriteLine(formatter.Format(parser.Parse("3.1415*2.0")));55 Console.WriteLine(formatter.Format(parser.Parse("3.1415-2.0")));52 Assert.AreEqual("3.1415 + 2",formatter.Format(parser.Parse("3.1415+2.0"))); 53 Assert.AreEqual("3.1415 / 2",formatter.Format(parser.Parse("3.1415/2.0"))); 54 Assert.AreEqual("3.1415 * 2",formatter.Format(parser.Parse("3.1415*2.0"))); 55 Assert.AreEqual("3.1415 - 2", formatter.Format(parser.Parse("3.1415-2.0"))); 56 56 // round-trip 57 Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0")))));58 Console.WriteLine(formatter.Format(parser.Parse("3.1415+(2.0)")));59 Console.WriteLine(formatter.Format(parser.Parse("(3.1415+(2.0))")));57 Assert.AreEqual("3.1415 - 2",formatter.Format(parser.Parse(formatter.Format(parser.Parse("3.1415-2.0"))))); 58 Assert.AreEqual("3.1415 + 2",formatter.Format(parser.Parse("3.1415+(2.0)"))); 59 Assert.AreEqual("3.1415 + 2", formatter.Format(parser.Parse("(3.1415+(2.0))"))); 60 60 61 61 62 Console.WriteLine(formatter.Format(parser.Parse("log(3)")));63 Console.WriteLine(formatter.Format(parser.Parse("log(-3)"))); // should produce log(-3) as output64 Console.WriteLine(formatter.Format(parser.Parse("exp(3)")));65 Console.WriteLine(formatter.Format(parser.Parse("exp(-3)"))); // should produce exp(-3) as output66 Console.WriteLine(formatter.Format(parser.Parse("sqrt(3)")));62 Assert.AreEqual("LOG(3)",formatter.Format(parser.Parse("log(3)"))); 63 Assert.AreEqual("LOG(-3)",formatter.Format(parser.Parse("log(-3)"))); 64 Assert.AreEqual("EXP(3)",formatter.Format(parser.Parse("exp(3)"))); 65 Assert.AreEqual("EXP(-3)",formatter.Format(parser.Parse("exp(-3)"))); 66 Assert.AreEqual("SQRT(3)", formatter.Format(parser.Parse("sqrt(3)"))); 67 67 68 Console.WriteLine(formatter.Format(parser.Parse("sqr((-3))"))); // should produce sqr((-3)) as output68 Assert.AreEqual("SQR(-3)", formatter.Format(parser.Parse("sqr((-3))"))); 69 69 70 Console.WriteLine(formatter.Format(parser.Parse("3/3+2/2+1/1"))); // ((3 * 1 / 3) + (2 * 1 / 2) + (1 * 1 / 1)) 71 Console.WriteLine(formatter.Format(parser.Parse("-3+30-2+20-1+10"))); // not (30 + 20 + 10 + ((-1) * (3 + 2 + 1))) 72 // round trip 73 Console.WriteLine(formatter.Format(parser.Parse(formatter.Format(parser.Parse("-3+30-2+20-1+10"))))); // not (30 + 20 + 10 + ((-(1)) * (3 + 2 + 1))) 70 Assert.AreEqual("3 / 3 + 2 / 2 + 1 / 1",formatter.Format(parser.Parse("3/3+2/2+1/1"))); 71 Assert.AreEqual("-3 + 30 - 2 + 20 - 1 + 10", formatter.Format(parser.Parse("-3+30-2+20-1+10"))); 74 72 75 Console.WriteLine(formatter.Format(parser.Parse("\"x1\""))); 76 Console.WriteLine(formatter.Format(parser.Parse("\'var name\'"))); 77 Console.WriteLine(formatter.Format(parser.Parse("\"var name\""))); 78 Console.WriteLine(formatter.Format(parser.Parse("\"1\""))); 73 // 'flattening' of nested addition, subtraction, multiplication, or division 74 Assert.AreEqual("1 + 2 + 3 + 4", formatter.Format(parser.Parse("1 + 2 + 3 + 4"))); 75 Assert.AreEqual("1 - 2 - 3 - 4", formatter.Format(parser.Parse("1 - 2 - 3 - 4"))); 76 Assert.AreEqual("1 * 2 * 3 * 4", formatter.Format(parser.Parse("1 * 2 * 3 * 4"))); 77 Assert.AreEqual("1 / 2 / 3 / 4", formatter.Format(parser.Parse("1 / 2 / 3 / 4"))); 79 78 80 Console.WriteLine(formatter.Format(parser.Parse("'var \" name\'"))); 81 Console.WriteLine(formatter.Format(parser.Parse("\"var \' name\""))); 79 // signed variables / constants 80 Assert.AreEqual("-1*'x1'", formatter.Format(parser.Parse("-x1"))); 81 Assert.AreEqual("1", formatter.Format(parser.Parse("--1.0"))); 82 Assert.AreEqual("1", formatter.Format(parser.Parse("----1.0"))); 83 Assert.AreEqual("1", formatter.Format(parser.Parse("-+-1.0"))); 84 Assert.AreEqual("1", formatter.Format(parser.Parse("+-+-1.0"))); 85 Assert.AreEqual("-3 + -1", formatter.Format(parser.Parse("-3 + -1.0"))); 82 86 83 87 84 Console.WriteLine(formatter.Format(parser.Parse("\"x1\"*\"x2\""))); 85 Console.WriteLine(formatter.Format(parser.Parse("\"x1\"*\"x2\"+\"x3\"*\"x4\""))); 86 Console.WriteLine(formatter.Format(parser.Parse("x1*x2+x3*x4"))); 88 Assert.AreEqual("'x1'",formatter.Format(parser.Parse("\"x1\""))); 89 Assert.AreEqual("'var name'",formatter.Format(parser.Parse("\'var name\'"))); 90 Assert.AreEqual("'var name'",formatter.Format(parser.Parse("\"var name\""))); 91 Assert.AreEqual("'1'",formatter.Format(parser.Parse("\"1\""))); 92 93 Assert.AreEqual("'var \" name'",formatter.Format(parser.Parse("'var \" name\'"))); 94 Assert.AreEqual("\"var ' name\"", formatter.Format(parser.Parse("\"var \' name\""))); 87 95 88 96 89 Console.WriteLine(formatter.Format(parser.Parse("POW(3, 2)"))); 90 Console.WriteLine(formatter.Format(parser.Parse("POW(3.1, 2.1)"))); 91 Console.WriteLine(formatter.Format(parser.Parse("POW(3.1 , 2.1)"))); 92 Console.WriteLine(formatter.Format(parser.Parse("POW(3.1 ,2.1)"))); 93 Console.WriteLine(formatter.Format(parser.Parse("POW(-3.1 , - 2.1)"))); 94 Console.WriteLine(formatter.Format(parser.Parse("ROOT(3, 2)"))); 95 Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1, 2.1)"))); 96 Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1 , 2.1)"))); 97 Console.WriteLine(formatter.Format(parser.Parse("ROOT(3.1 ,2.1)"))); 98 Console.WriteLine(formatter.Format(parser.Parse("ROOT(-3.1 , - 2.1)"))); 97 Assert.AreEqual("'x1' * 'x2'",formatter.Format(parser.Parse("\"x1\"*\"x2\""))); 98 Assert.AreEqual("'x1' * 'x2' + 'x3' * 'x4'",formatter.Format(parser.Parse("\"x1\"*\"x2\"+\"x3\"*\"x4\""))); 99 Assert.AreEqual("'x1' * 'x2' + 'x3' * 'x4'", formatter.Format(parser.Parse("x1*x2+x3*x4"))); 99 100 100 Console.WriteLine(formatter.Format(parser.Parse("IF(GT( 0, 1), 1, 0)")));101 Console.WriteLine(formatter.Format(parser.Parse("IF(LT(0,1), 1 , 0)")));102 101 103 Console.WriteLine(formatter.Format(parser.Parse("LAG(x, 1)"))); 104 Console.WriteLine(formatter.Format(parser.Parse("LAG(x, -1)"))); 105 Console.WriteLine(formatter.Format(parser.Parse("LAG(x, +1)"))); 106 Console.WriteLine(formatter.Format(parser.Parse("x * LAG('x', +1)"))); 102 Assert.AreEqual("3 ^ 2",formatter.Format(parser.Parse("POW(3, 2)"))); 103 Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1, 2.1)"))); 104 Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1 , 2.1)"))); 105 Assert.AreEqual("3.1 ^ 2.1",formatter.Format(parser.Parse("POW(3.1 ,2.1)"))); 106 Assert.AreEqual("-3.1 ^ -2.1",formatter.Format(parser.Parse("POW(-3.1 , - 2.1)"))); 107 Assert.AreEqual("ROOT(3, 2)",formatter.Format(parser.Parse("ROOT(3, 2)"))); 108 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1, 2.1)"))); 109 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 , 2.1)"))); 110 Assert.AreEqual("ROOT(3.1, 2.1)",formatter.Format(parser.Parse("ROOT(3.1 ,2.1)"))); 111 Assert.AreEqual("ROOT(-3.1, -2.1)", formatter.Format(parser.Parse("ROOT(-3.1 , -2.1)"))); 107 112 108 Console.WriteLine(formatter.Format(parser.Parse("x [1.0] * y"))); 109 Console.WriteLine(formatter.Format(parser.Parse("x [1.0, 2.0] * y [1.0, 2.0]"))); 110 Console.WriteLine(formatter.Format(parser.Parse("x[1] * y"))); 111 Console.WriteLine(formatter.Format(parser.Parse("x[1, 2] * y [1, 2]"))); 113 Assert.AreEqual("IF(GT(0, 1), 1, 0)",formatter.Format(parser.Parse("IF(GT( 0, 1), 1, 0)"))); 114 Assert.AreEqual("IF(LT(0, 1), 1, 0)",formatter.Format(parser.Parse("IF(LT(0,1), 1 , 0)"))); 115 Assert.AreEqual("LAG('x', 1)",formatter.Format(parser.Parse("LAG(x, 1)"))); 116 Assert.AreEqual("LAG('x', -1)",formatter.Format(parser.Parse("LAG(x, -1)"))); 117 Assert.AreEqual("LAG('x', 1)",formatter.Format(parser.Parse("LAG(x, +1)"))); 118 Assert.AreEqual("'x' * LAG('x', 1)", formatter.Format(parser.Parse("x * LAG('x', +1)"))); 112 119 113 Console.WriteLine(formatter.Format(parser.Parse("x [+1.0] * y"))); 114 Console.WriteLine(formatter.Format(parser.Parse("x [-1.0] * y"))); 115 Console.WriteLine(formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]"))); 120 // factor variables 121 Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x [1.0] * y"))); 122 Assert.AreEqual("'x'[1, 2] * 'y'[1, 2]",formatter.Format(parser.Parse("x [1.0, 2.0] * y [1.0, 2.0]"))); 123 Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x[1] * y"))); 124 Assert.AreEqual("'x'[1, 2] * 'y'[1, 2]",formatter.Format(parser.Parse("x[1, 2] * y [1, 2]"))); 125 Assert.AreEqual("'x'[1] * 'y'",formatter.Format(parser.Parse("x [+1.0] * y"))); 126 Assert.AreEqual("'x'[-1] * 'y'",formatter.Format(parser.Parse("x [-1.0] * y"))); 127 Assert.AreEqual("'x'[-1, -2] * 'y'[1, 2]", formatter.Format(parser.Parse("x [-1.0, -2.0] * y [+1.0, +2.0]"))); 116 128 117 Console.WriteLine(formatter.Format(parser.Parse("x='bla' * y"))); 118 Console.WriteLine(formatter.Format(parser.Parse("x = 'bla'"))); 119 Console.WriteLine(formatter.Format(parser.Parse("x = \"bla\""))); 120 Console.WriteLine(formatter.Format(parser.Parse("1.0 * x = bla"))); 121 Console.WriteLine(formatter.Format(parser.Parse("-1.0 * x = bla"))); 122 Console.WriteLine(formatter.Format(parser.Parse("+1.0 * \"x\" = bla + y = \"bla2\""))); 129 // one-hot for factor 130 Assert.AreEqual("'x' = 'val' * 'y'",formatter.Format(parser.Parse("x='val' * y"))); 131 Assert.AreEqual("'x' = 'val'",formatter.Format(parser.Parse("x = 'val'"))); 132 Assert.AreEqual("'x' = 'val'",formatter.Format(parser.Parse("x = \"val\""))); 133 Assert.AreEqual("1 * 'x' = 'val'",formatter.Format(parser.Parse("1.0 * x = val"))); 134 Assert.AreEqual("-1 * 'x' = 'val'",formatter.Format(parser.Parse("-1.0 * x = val"))); 135 Assert.AreEqual("1 * 'x' = 'val1' + 'y' = 'val2'", formatter.Format(parser.Parse("+1.0 * \"x\" = val1 + y = \"val2\""))); 136 137 // numeric parameters 138 Assert.AreEqual("0", formatter.Format(parser.Parse("<num>"))); // default initial value is zero 139 Assert.AreEqual("0", formatter.Format(parser.Parse("< num >"))); 140 Assert.AreEqual("1", formatter.Format(parser.Parse("< num=1.0>"))); 141 Assert.AreEqual("1", formatter.Format(parser.Parse("< num = 1.0>"))); 142 Assert.AreEqual("-1", formatter.Format(parser.Parse("< num =-1.0>"))); 143 Assert.AreEqual("-1", formatter.Format(parser.Parse("< num = - 1.0>"))); 144 145 // numeric parameter with sign 146 Assert.AreEqual("1", formatter.Format(parser.Parse("-<num=-1.0>"))); 147 148 // nested functions 149 Assert.AreEqual("SIN(SIN(SIN('X1')))", formatter.Format(parser.Parse("SIN(SIN(SIN(X1)))"))); 123 150 } 124 151 } -
branches/3136_Structural_GP/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs
r18150 r18176 7 7 [TestClass] 8 8 public class BottomUpSimilarityCalculatorTest { 9 private readonly SymbolicExpressionImporter importer = new SymbolicExpressionImporter();10 9 private readonly InfixExpressionParser parser = new InfixExpressionParser(); 11 10 … … 13 12 private const int Rows = 1; 14 13 private const int Columns = 10; 15 16 public BottomUpSimilarityCalculatorTest() {17 var parser = new InfixExpressionParser();18 }19 14 20 15 [TestMethod] … … 28 23 29 24 TestMatchedNodes("1 - 1", "2 - 2", 0, strict: true); 30 TestMatchedNodes("1 - 1", "2 - 2", 4, strict: false); // 4, because of the way strings are parsed into trees by the infix parser25 TestMatchedNodes("1 - 1", "2 - 2", 3, strict: false); 31 26 32 27 TestMatchedNodes("2 - 1", "1 - 2", 2, strict: true); 33 TestMatchedNodes("2 - 1", "1 - 2", 4, strict: false);28 TestMatchedNodes("2 - 1", "1 - 2", 3, strict: false); 34 29 35 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) + (X3 * X4)", 7, strict: true);36 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) + (X3 * X4)", 7, strict: false);30 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 + X3 * X4", 7, strict: true); 31 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 + X3 * X4", 7, strict: false); 37 32 38 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) + (X5 * X6)", 3, strict: true);39 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) + (X5 * X6)", 3, strict: false);33 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 + X5 * X6", 3, strict: true); 34 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 + X5 * X6", 3, strict: false); 40 35 41 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) - (X5 * X6)", 3, strict: true);42 TestMatchedNodes(" (X1 * X2) + (X3 * X4)", "(X1 * X2) - (X5 * X6)", 3, strict: false);36 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 - X5 * X6", 3, strict: true); 37 TestMatchedNodes("X1 * X2 + X3 * X4", "X1 * X2 - X5 * X6", 3, strict: false); 43 38 44 39 TestMatchedNodes("SIN(SIN(SIN(X1)))", "SIN(SIN(SIN(X1)))", 4, strict: true); … … 47 42 TestMatchedNodes("SIN(SIN(SIN(X1)))", "COS(COS(COS(X1)))", 1, strict: true); 48 43 49 const string lhs = " (0.006153 + (X9 * X7 * X2 * 0.229506) + (X6 * X10 * X3 * 0.924598) + (X2 * X1 * 0.951272) + (X4 * X3 * 0.992570) + (X6 * X5 * 1.027299))";50 const string rhs = " (0.006153 + (X10 * X7 * X2 * 0.229506) + (X6 * X10 * X3 * 0.924598) + (X2 * X1 * 0.951272) + (X4 * X3 * 0.992570) + (X6 * X5 * 1.027299))";44 const string lhs = "0.006153 + X9 * X7 * X2 * 0.229506 + X6 * X10 * X3 * 0.924598 + X2 * X1 * 0.951272 + X4 * X3 * 0.992570 + X6 * X5 * 1.027299"; 45 const string rhs = "0.006153 + X10 * X7 * X2 * 0.229506 + X6 * X10 * X3 * 0.924598 + X2 * X1 * 0.951272 + X4 * X3 * 0.992570 + X6 * X5 * 1.027299"; 51 46 52 47 TestMatchedNodes(lhs, lhs, 24, strict: true);
Note: See TracChangeset
for help on using the changeset viewer.