Changeset 17827 for branches/3073_IA_constraint_splitting
- Timestamp:
- 01/31/21 08:08:32 (4 years ago)
- Location:
- branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 17811,17817,17820,17826
- Property svn:mergeinfo changed
-
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r17798 r17827 934 934 var constBValue = Math.Round(constB.Value); 935 935 if (constBValue == 1.0) { 936 // root(a, 1) => a 936 937 return a; 937 938 } else if (constBValue == 0.0) { 938 return MakeConstant(1.0); 939 // root(a, 0) is not defined 940 //return MakeConstant(1.0); 941 return MakeConstant(double.NaN); 939 942 } else if (constBValue == -1.0) { 943 // root(a, -1) => a^(-1/1) => 1/a 940 944 return MakeFraction(MakeConstant(1.0), a); 941 945 } else if (constBValue < 0) { 946 // root(a, -b) => a^(-1/b) => (1/a)^(1/b) => root(1, b) / root(a, b) => 1 / root(a, b) 942 947 var rootNode = rootSymbol.CreateTreeNode(); 943 948 rootNode.AddSubtree(a); … … 988 993 double exponent = Math.Round(constB.Value); 989 994 if (exponent == 0.0) { 995 // a^0 => 1 990 996 return MakeConstant(1.0); 991 997 } else if (exponent == 1.0) { 998 // a^1 => a 992 999 return a; 993 1000 } else if (exponent == -1.0) { 1001 // a^-1 => 1/a 994 1002 return MakeFraction(MakeConstant(1.0), a); 995 1003 } else if (exponent < 0) { 1004 // a^-b => (1/a)^b => 1/(a^b) 996 1005 var powNode = powSymbol.CreateTreeNode(); 997 1006 powNode.AddSubtree(a); … … 1019 1028 return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value); 1020 1029 } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) { 1030 // a / x => (a * 1/a) / (x * 1/a) => 1 / (x * 1/a) 1021 1031 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 1022 1032 } else if (IsVariableBase(a) && IsConstant(b)) { -
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r17180 r17827 258 258 if (node.Symbol is CubeRoot) { 259 259 return cbrt(ConvertToAutoDiff(node.GetSubtree(0))); 260 } 261 if (node.Symbol is Power) { 262 var powerNode = node.GetSubtree(1) as ConstantTreeNode; 263 if (powerNode == null) 264 throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol."); 265 var intPower = Math.Truncate(powerNode.Value); 266 if (intPower != powerNode.Value) 267 throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol."); 268 return AutoDiff.TermBuilder.Power(ConvertToAutoDiff(node.GetSubtree(0)), intPower); 260 269 } 261 270 if (node.Symbol is Sine) { … … 340 349 !(n.Symbol is AnalyticQuotient) && 341 350 !(n.Symbol is Cube) && 342 !(n.Symbol is CubeRoot) 351 !(n.Symbol is CubeRoot) && 352 !(n.Symbol is Power) 343 353 select n).Any(); 344 354 return !containsUnknownSymbol; -
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs
r17790 r17827 29 29 using HeuristicLab.Core; 30 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 31 using Microsoft.SqlServer.Server;32 31 33 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 39 38 // operators 40 39 if (token == "+" || token == "-" || token == "OR" || token == "XOR" || 41 token == "*" || token == "/" || token == "AND" || 42 token == "^") { 40 token == "*" || token == "/" || token == "AND") { 43 41 strBuilder.Append("("); 44 42 FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants); … … 47 45 strBuilder.Append(" ").Append(token).Append(" "); 48 46 FormatRecursively(subtree, strBuilder, numberFormat, formatString, constants); 47 } 48 49 strBuilder.Append(")"); 50 } else if (token == "^") { 51 // handle integer powers directly 52 strBuilder.Append("("); 53 FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants); 54 55 var power = node.GetSubtree(1); 56 if(power is ConstantTreeNode constNode && Math.Truncate(constNode.Value) == constNode.Value) { 57 strBuilder.Append(" ").Append(token).Append(" ").Append(constNode.Value.ToString(formatString, numberFormat)); 58 } else { 59 strBuilder.Append(" ").Append(token).Append(" "); 60 FormatRecursively(power, strBuilder, numberFormat, formatString, constants); 49 61 } 50 62 … … 131 143 } else if (node.Symbol is Constant) { 132 144 var constNode = node as ConstantTreeNode; 133 if (constants==null && constNode.Value < 0) {145 if (constants == null && constNode.Value < 0) { 134 146 strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat)) 135 147 .Append(")"); // (-1 -
branches/3073_IA_constraint_splitting/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r17790 r17827 517 517 518 518 private void FormatStartSymbol(StringBuilder strBuilder) { 519 strBuilder.Append( EscapeLatexString(targetVariable) ?? "target_{" + targetCount++ + "}");519 strBuilder.Append(targetVariable != null ? EscapeLatexString(targetVariable) : "\\text{target}_{" + targetCount++ + "}"); 520 520 if (containsTimeSeriesSymbol) 521 521 strBuilder.Append("(t)");
Note: See TracChangeset
for help on using the changeset viewer.