Changeset 16238
- Timestamp:
- 10/18/18 15:29:59 (6 years ago)
- Location:
- branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r16236 r16238 59 59 var square = new Square(); 60 60 square.InitialFrequency = 0.0; 61 var cube = new Cube(); 62 cube.InitialFrequency = 0.0; 61 63 var root = new Root(); 62 64 root.InitialFrequency = 0.0; 63 65 var sqrt = new SquareRoot(); 64 66 sqrt.InitialFrequency = 0.0; 67 var cubeRoot = new CubeRoot(); 68 cubeRoot.InitialFrequency = 0.0; 65 69 var airyA = new AiryA(); 66 70 airyA.InitialFrequency = 0.0; … … 125 129 autoregressiveVariable.Enabled = false; 126 130 127 var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, pow, sqrt, root, exp,131 var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, 128 132 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 129 133 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition }; 130 var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,134 var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, not, timeLag, integral, derivative, 131 135 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral 132 136 }; -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r15944 r16238 69 69 var root = new Root(); 70 70 var sqrt = new SquareRoot(); 71 var cube = new Cube(); 72 var cubeRoot = new CubeRoot(); 71 73 var exp = new Exponential(); 72 74 var abs = new Absolute(); … … 87 89 var psi = new Psi(); 88 90 var sineIntegral = new SineIntegral(); 91 var analyticalQuotient = new AnalyticalQuotient(); 89 92 90 93 var @if = new IfThenElse(); … … 112 115 113 116 #region group symbol declaration 114 var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean , abs});117 var arithmeticSymbols = new GroupSymbol(ArithmeticFunctionsName, new List<ISymbol>() { add, sub, mul, div, mean }); 115 118 var trigonometricSymbols = new GroupSymbol(TrigonometricFunctionsName, new List<ISymbol>() { sin, cos, tan }); 116 119 var exponentialAndLogarithmicSymbols = new GroupSymbol(ExponentialFunctionsName, new List<ISymbol> { exp, log }); 117 var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { a iryA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,118 fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral });120 var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, 121 fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral, analyticalQuotient}); 119 122 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, binFactorVariable, factorVariable }); 120 123 var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols }); 121 124 122 var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, pow, sqrt, root });125 var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, pow, sqrt, root, cube, cubeRoot }); 123 126 124 127 var conditionSymbols = new GroupSymbol(ConditionsName, new List<ISymbol> { @if, variableCondition }); … … 141 144 SetSubtreeCount(root, 2, 2); 142 145 SetSubtreeCount(square, 1, 1); 146 SetSubtreeCount(cube, 1, 1); 143 147 SetSubtreeCount(sqrt, 1, 1); 148 SetSubtreeCount(cubeRoot, 1, 1); 144 149 SetSubtreeCount(exponentialAndLogarithmicSymbols, 1, 1); 145 SetSubtreeCount(specialFunctions, 1, 1); 150 foreach(var sy in specialFunctions.Symbols.Except(new[] { analyticalQuotient})) { 151 SetSubtreeCount(sy, 1, 1); 152 } 153 SetSubtreeCount(analyticalQuotient, 2, 2); 154 146 155 SetSubtreeCount(terminalSymbols, 0, 0); 147 156 -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r16236 r16238 209 209 <Compile Include="Symbols\BinaryFactorVariableTreeNode.cs" /> 210 210 <Compile Include="Symbols\AnalyticalQuotient.cs" /> 211 <Compile Include="Symbols\Cube.cs" /> 211 212 <Compile Include="Symbols\FactorVariableTreeNode.cs" /> 212 213 <Compile Include="Symbols\FactorVariable.cs" /> 213 214 <Compile Include="Symbols\Absolute.cs" /> 215 <Compile Include="Symbols\CubeRoot.cs" /> 214 216 <Compile Include="Symbols\VariableBase.cs" /> 215 217 <Compile Include="Symbols\VariableTreeNodeBase.cs" /> -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r16237 r16238 87 87 public const byte Absolute = 48; 88 88 public const byte AnalyticalQuotient = 49; 89 public const byte Cube = 50; 90 public const byte CubeRoot = 51; 89 91 90 92 … … 138 140 { typeof(FactorVariable), OpCodes.FactorVariable }, 139 141 { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable }, 140 { typeof(Absolute), OpCodes.Absolute }, 141 { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient } 142 { typeof(Absolute), OpCodes.Absolute }, 143 { typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient }, 144 { typeof(Cube), OpCodes.Cube }, 145 { typeof(CubeRoot), OpCodes.CubeRoot } 142 146 }; 143 147 -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r15583 r16238 41 41 42 42 #region method info for the commonly called functions 43 private static readonly MethodInfo Abs = typeof(Math).GetMethod("Abs", new[] { typeof(double) }); 43 44 private static readonly MethodInfo Sin = typeof(Math).GetMethod("Sin", new[] { typeof(double) }); 44 45 private static readonly MethodInfo Cos = typeof(Math).GetMethod("Cos", new[] { typeof(double) }); … … 207 208 return Expression.Divide(result, Expression.Constant((double)node.SubtreeCount)); 208 209 } 210 case OpCodes.Absolute: { 211 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 212 return Expression.Call(Abs, arg); 213 } 209 214 case OpCodes.Cos: { 210 215 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); … … 222 227 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 223 228 return Expression.Power(arg, Expression.Constant(2.0)); 229 } 230 case OpCodes.Cube: { 231 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 232 return Expression.Power(arg, Expression.Constant(3.0)); 224 233 } 225 234 case OpCodes.Power: { … … 231 240 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 232 241 return Expression.Call(Sqrt, arg); 242 } 243 case OpCodes.CubeRoot: { 244 var arg = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 245 return Expression.Power(arg, Expression.Constant(1.0 / 3.0)); 233 246 } 234 247 case OpCodes.Root: { … … 493 506 Expression.Assign(result, Expression.Call(Bessel, arg))), 494 507 result); 508 } 509 case OpCodes.AnalyticalQuotient: { 510 var x1 = MakeExpr(node.GetSubtree(0), variableIndices, row, columns); 511 var x2 = MakeExpr(node.GetSubtree(1), variableIndices, row, columns); 512 return Expression.Divide(x1, 513 Expression.Call(Sqrt, 514 Expression.Add( 515 Expression.Constant(1.0), 516 Expression.Multiply(x2, x2)))); 495 517 } 496 518 case OpCodes.IfThenElse: { -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r15583 r16238 50 50 private static MethodInfo round = typeof(Math).GetMethod("Round", new Type[] { typeof(double) }); 51 51 private static MethodInfo sqrt = typeof(Math).GetMethod("Sqrt", new Type[] { typeof(double) }); 52 private static MethodInfo abs = typeof(Math).GetMethod("Abs", new Type[] { typeof(double) }); 52 53 53 54 private static MethodInfo airyA = thisType.GetMethod("AiryA", new Type[] { typeof(double) }); … … 264 265 return; 265 266 } 267 case OpCodes.Absolute: { 268 CompileInstructions(il, state, ds); 269 il.Emit(System.Reflection.Emit.OpCodes.Call, abs); 270 return; 271 } 266 272 case OpCodes.Cos: { 267 273 CompileInstructions(il, state, ds); … … 311 317 return; 312 318 } 319 case OpCodes.Cube: { 320 CompileInstructions(il, state, ds); 321 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 3.0); 322 il.Emit(System.Reflection.Emit.OpCodes.Call, power); 323 return; 324 } 313 325 case OpCodes.SquareRoot: { 314 326 CompileInstructions(il, state, ds); … … 316 328 return; 317 329 } 330 case OpCodes.CubeRoot: { 331 CompileInstructions(il, state, ds); 332 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0 / 3.0); 333 il.Emit(System.Reflection.Emit.OpCodes.Call, power); 334 return; 335 } 318 336 case OpCodes.AiryA: { 319 337 CompileInstructions(il, state, ds); … … 389 407 CompileInstructions(il, state, ds); 390 408 il.Emit(System.Reflection.Emit.OpCodes.Call, sinIntegral); 409 return; 410 } 411 case OpCodes.AnalyticalQuotient: { 412 CompileInstructions(il, state, ds); // x1 413 CompileInstructions(il, state, ds); // x2 414 415 il.Emit(System.Reflection.Emit.OpCodes.Dup); 416 il.Emit(System.Reflection.Emit.OpCodes.Mul); // x2*x2 417 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 1.0); 418 il.Emit(System.Reflection.Emit.OpCodes.Mul); // 1+x2*x2 419 il.Emit(System.Reflection.Emit.OpCodes.Call, sqrt); 420 il.Emit(System.Reflection.Emit.OpCodes.Div); 391 421 return; 392 422 } -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r15944 r16238 218 218 return Math.Pow(Evaluate(dataset, ref row, state), 2); 219 219 } 220 case OpCodes.Cube: { 221 return Math.Pow(Evaluate(dataset, ref row, state), 3); 222 } 220 223 case OpCodes.Power: { 221 224 double x = Evaluate(dataset, ref row, state); … … 226 229 return Math.Sqrt(Evaluate(dataset, ref row, state)); 227 230 } 231 case OpCodes.CubeRoot: { 232 return Math.Pow(Evaluate(dataset, ref row, state), 1.0 / 3.0); 233 } 228 234 case OpCodes.Root: { 229 235 double x = Evaluate(dataset, ref row, state); … … 343 349 if (double.IsNaN(x)) return double.NaN; 344 350 else return alglib.besseli0(x); 351 } 352 353 case OpCodes.AnalyticalQuotient: { 354 var x1 = Evaluate(dataset, ref row, state); 355 var x2 = Evaluate(dataset, ref row, state); 356 return x1 / Math.Pow(1 + x2 * x2, 0.5); 345 357 } 346 358 case OpCodes.IfThenElse: { -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r16236 r16238 233 233 } else if (instr.opCode == OpCodes.Tan) { 234 234 instr.value = Math.Tan(code[instr.childIndex].value); 235 } else if 235 } else if(instr.opCode == OpCodes.Square) { 236 236 instr.value = Math.Pow(code[instr.childIndex].value, 2); 237 } else if(instr.opCode == OpCodes.Cube) { 238 instr.value = Math.Pow(code[instr.childIndex].value, 3); 237 239 } else if (instr.opCode == OpCodes.Power) { 238 240 double x = code[instr.childIndex].value; 239 241 double y = Math.Round(code[instr.childIndex + 1].value); 240 242 instr.value = Math.Pow(x, y); 241 } else if 243 } else if(instr.opCode == OpCodes.SquareRoot) { 242 244 instr.value = Math.Sqrt(code[instr.childIndex].value); 245 } else if(instr.opCode == OpCodes.CubeRoot) { 246 instr.value = Math.Pow(code[instr.childIndex].value, 1.0 / 3.0); 243 247 } else if (instr.opCode == OpCodes.Root) { 244 248 double x = code[instr.childIndex].value;
Note: See TracChangeset
for help on using the changeset viewer.