Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Tests
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeInterpreterTest.cs
r12012 r14029 70 70 } 71 71 72 [TestMethod] 73 [TestCategory("Problems.DataAnalysis.Symbolic")] 74 [TestProperty("Time", "long")] 75 public void CompiledInterpreterTestTypeCoherentGrammarPerformance() { 76 TestTypeCoherentGrammarPerformance(new SymbolicDataAnalysisExpressionCompiledTreeInterpreter(), 12.5e6); 77 } 78 [TestMethod] 79 [TestCategory("Problems.DataAnalysis.Symbolic")] 80 [TestProperty("Time", "long")] 81 public void CompiledInterpreterTestFullGrammarPerformance() { 82 TestFullGrammarPerformance(new SymbolicDataAnalysisExpressionCompiledTreeInterpreter(), 12.5e6); 83 } 84 [TestMethod] 85 [TestCategory("Problems.DataAnalysis.Symbolic")] 86 [TestProperty("Time", "long")] 87 public void CompiledInterpreterTestArithmeticGrammarPerformance() { 88 TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionCompiledTreeInterpreter(), 12.5e6); 89 } 72 90 73 91 [TestMethod] … … 80 98 [TestCategory("Problems.DataAnalysis.Symbolic")] 81 99 [TestProperty("Time", "long")] 82 public void ILEmittingInterpreterTestFullGrammarPerformance() {83 TestFullGrammarPerformance(new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(), 7.5e6);84 }85 [TestMethod]86 [TestCategory("Problems.DataAnalysis.Symbolic")]87 [TestProperty("Time", "long")]88 100 public void ILEmittingInterpreterTestArithmeticGrammarPerformance() { 89 101 TestArithmeticGrammarPerformance(new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(), 7.5e6); 90 102 } 91 92 103 93 104 [TestMethod] … … 113 124 var twister = new MersenneTwister(31415); 114 125 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 126 115 127 var grammar = new TypeCoherentExpressionGrammar(); 116 128 grammar.ConfigureAsDefaultRegressionGrammar(); 117 grammar.MaximumFunctionArguments = 0; 118 grammar.MaximumFunctionDefinitions = 0; 119 grammar.MinimumFunctionArguments = 0; 120 grammar.MinimumFunctionDefinitions = 0; 129 121 130 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 122 131 foreach (ISymbolicExpressionTree tree in randomTrees) { … … 131 140 var twister = new MersenneTwister(31415); 132 141 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 142 133 143 var grammar = new FullFunctionalExpressionGrammar(); 134 grammar.MaximumFunctionArguments = 0;135 grammar.MaximumFunctionDefinitions = 0;136 grammar.MinimumFunctionArguments = 0;137 grammar.MinimumFunctionDefinitions = 0;138 144 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 139 145 foreach (ISymbolicExpressionTree tree in randomTrees) { … … 148 154 var twister = new MersenneTwister(31415); 149 155 var dataset = Util.CreateRandomDataset(twister, Rows, Columns); 156 150 157 var grammar = new ArithmeticExpressionGrammar(); 151 //grammar.Symbols.OfType<Variable>().First().Enabled = false;152 grammar.MaximumFunctionArguments = 0;153 grammar.MaximumFunctionDefinitions = 0;154 grammar.MinimumFunctionArguments = 0;155 grammar.MinimumFunctionDefinitions = 0;156 158 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 100, 0, 0); 157 159 foreach (SymbolicExpressionTree tree in randomTrees) { … … 175 177 EvaluateTerminals(interpreter, ds); 176 178 EvaluateOperations(interpreter, ds); 179 EvaluateLaggedOperations(interpreter, ds); 180 EvaluateSpecialFunctions(interpreter, ds); 177 181 EvaluateAdf(interpreter, ds); 178 182 } … … 181 185 [TestCategory("Problems.DataAnalysis.Symbolic")] 182 186 [TestProperty("Time", "short")] 183 public void ILEmittingInterpreterTestEvaluation() { 184 var interpreter = new SymbolicDataAnalysisExpressionTreeILEmittingInterpreter(); 187 public void CompiledInterpreterTestEvaluation() { 188 var interpreter = new SymbolicDataAnalysisExpressionCompiledTreeInterpreter(); 189 // ADFs are not supported by the compiled tree interpreter 185 190 EvaluateTerminals(interpreter, ds); 186 191 EvaluateOperations(interpreter, ds); 192 EvaluateSpecialFunctions(interpreter, ds); 187 193 } 188 194 … … 192 198 public void LinearInterpreterTestEvaluation() { 193 199 var interpreter = new SymbolicDataAnalysisExpressionTreeLinearInterpreter(); 194 195 200 //ADFs are not supported by the linear interpreter 196 201 EvaluateTerminals(interpreter, ds); 197 202 EvaluateOperations(interpreter, ds); 198 } 199 200 private void EvaluateTerminals(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) { 203 EvaluateLaggedOperations(interpreter, ds); 204 EvaluateSpecialFunctions(interpreter, ds); 205 } 206 207 [TestMethod] 208 [TestCategory("Problems.DataAnalysis.Symbolic")] 209 [TestProperty("Time", "long")] 210 public void TestInterpretersEstimatedValuesConsistency() { 211 var twister = new MersenneTwister(); 212 int seed = twister.Next(0, int.MaxValue); 213 twister.Seed((uint)seed); 214 const int numRows = 100; 215 var dataset = Util.CreateRandomDataset(twister, numRows, Columns); 216 217 var grammar = new TypeCoherentExpressionGrammar(); 218 219 var interpreters = new ISymbolicDataAnalysisExpressionTreeInterpreter[] { 220 new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 221 new SymbolicDataAnalysisExpressionTreeInterpreter(), 222 }; 223 224 var rows = Enumerable.Range(0, numRows).ToList(); 225 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 10, 0, 0); 226 foreach (ISymbolicExpressionTree tree in randomTrees) { 227 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); 228 } 229 230 for (int i = 0; i < randomTrees.Length; ++i) { 231 var tree = randomTrees[i]; 232 var valuesMatrix = interpreters.Select(x => x.GetSymbolicExpressionTreeValues(tree, dataset, rows)).ToList(); 233 for (int m = 0; m < interpreters.Length - 1; ++m) { 234 var sum = valuesMatrix[m].Sum(); 235 for (int n = m + 1; n < interpreters.Length; ++n) { 236 var s = valuesMatrix[n].Sum(); 237 if (double.IsNaN(sum) && double.IsNaN(s)) continue; 238 239 string errorMessage = string.Format("Interpreters {0} and {1} do not agree on tree {2} (seed = {3}).", interpreters[m].Name, interpreters[n].Name, i, seed); 240 Assert.AreEqual(sum, s, 1e-12, errorMessage); 241 } 242 } 243 } 244 } 245 246 [TestMethod] 247 [TestCategory("Problems.DataAnalysis.Symbolic")] 248 [TestProperty("Time", "long")] 249 public void TestCompiledInterpreterEstimatedValuesConsistency() { 250 const double delta = 1e-12; 251 252 var twister = new MersenneTwister(); 253 int seed = twister.Next(0, int.MaxValue); 254 twister.Seed((uint)seed); 255 256 Console.WriteLine(seed); 257 258 const int numRows = 100; 259 var dataset = Util.CreateRandomDataset(twister, numRows, Columns); 260 261 var grammar = new TypeCoherentExpressionGrammar(); 262 grammar.ConfigureAsDefaultRegressionGrammar(); 263 grammar.Symbols.First(x => x.Name == "Power Functions").Enabled = true; 264 265 var randomTrees = Util.CreateRandomTrees(twister, dataset, grammar, N, 1, 10, 0, 0); 266 foreach (ISymbolicExpressionTree tree in randomTrees) { 267 Util.InitTree(tree, twister, new List<string>(dataset.VariableNames)); 268 } 269 270 var interpreters = new ISymbolicDataAnalysisExpressionTreeInterpreter[] { 271 new SymbolicDataAnalysisExpressionCompiledTreeInterpreter(), 272 new SymbolicDataAnalysisExpressionTreeInterpreter(), 273 new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 274 }; 275 var rows = Enumerable.Range(0, numRows).ToList(); 276 var formatter = new SymbolicExpressionTreeHierarchicalFormatter(); 277 278 for (int i = 0; i < randomTrees.Length; ++i) { 279 var tree = randomTrees[i]; 280 var valuesMatrix = interpreters.Select(x => x.GetSymbolicExpressionTreeValues(tree, dataset, rows).ToList()).ToList(); 281 for (int m = 0; m < interpreters.Length - 1; ++m) { 282 for (int n = m + 1; n < interpreters.Length; ++n) { 283 for (int row = 0; row < numRows; ++row) { 284 var v1 = valuesMatrix[m][row]; 285 var v2 = valuesMatrix[n][row]; 286 if (double.IsNaN(v1) && double.IsNaN(v2)) continue; 287 if (Math.Abs(v1 - v2) > delta) { 288 Console.WriteLine(formatter.Format(tree)); 289 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList()) { 290 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 291 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(twister); 292 rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 293 294 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 295 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(twister); 296 startNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 297 298 rootNode.AddSubtree(startNode); 299 var t = new SymbolicExpressionTree(rootNode); 300 var start = t.Root.GetSubtree(0); 301 var p = node.Parent; 302 start.AddSubtree(node); 303 Console.WriteLine(node); 304 305 var y1 = interpreters[m].GetSymbolicExpressionTreeValues(t, dataset, new[] { row }).First(); 306 var y2 = interpreters[n].GetSymbolicExpressionTreeValues(t, dataset, new[] { row }).First(); 307 308 if (double.IsNaN(y1) && double.IsNaN(y2)) continue; 309 string prefix = Math.Abs(y1 - y2) > delta ? "++" : "=="; 310 Console.WriteLine("\t{0} Row {1}: {2} {3}, Deviation = {4}", prefix, row, y1, y2, Math.Abs(y1 - y2)); 311 node.Parent = p; 312 } 313 } 314 string errorMessage = string.Format("Interpreters {0} and {1} do not agree on tree {2} and row {3} (seed = {4}).", interpreters[m].Name, interpreters[n].Name, i, row, seed); 315 Assert.AreEqual(v1, v2, delta, errorMessage); 316 } 317 } 318 } 319 } 320 } 321 322 private void EvaluateTerminals(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds) { 201 323 // constants 202 324 Evaluate(interpreter, ds, "(+ 1.5 3.5)", 0, 5.0); … … 207 329 } 208 330 209 private void EvaluateAdf(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) {331 private void EvaluateAdf(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds) { 210 332 211 333 // ADF … … 246 368 } 247 369 248 private void EvaluateOperations(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds) { 370 private void EvaluateSpecialFunctions(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds) { 371 // special functions 372 Action<double> checkAiry = (x) => { 373 double ai, aip, bi, bip; 374 alglib.airy(x, out ai, out aip, out bi, out bip); 375 Evaluate(interpreter, ds, "(airya " + x + ")", 0, ai); 376 Evaluate(interpreter, ds, "(airyb " + x + ")", 0, bi); 377 }; 378 379 Action<double> checkBessel = (x) => { 380 Evaluate(interpreter, ds, "(bessel " + x + ")", 0, alglib.besseli0(x)); 381 }; 382 383 Action<double> checkSinCosIntegrals = (x) => { 384 double si, ci; 385 alglib.sinecosineintegrals(x, out si, out ci); 386 Evaluate(interpreter, ds, "(cosint " + x + ")", 0, ci); 387 Evaluate(interpreter, ds, "(sinint " + x + ")", 0, si); 388 }; 389 Action<double> checkHypSinCosIntegrals = (x) => { 390 double shi, chi; 391 alglib.hyperbolicsinecosineintegrals(x, out shi, out chi); 392 Evaluate(interpreter, ds, "(hypcosint " + x + ")", 0, chi); 393 Evaluate(interpreter, ds, "(hypsinint " + x + ")", 0, shi); 394 }; 395 Action<double> checkFresnelSinCosIntegrals = (x) => { 396 double c = 0, s = 0; 397 alglib.fresnelintegral(x, ref c, ref s); 398 Evaluate(interpreter, ds, "(fresnelcosint " + x + ")", 0, c); 399 Evaluate(interpreter, ds, "(fresnelsinint " + x + ")", 0, s); 400 }; 401 Action<double> checkNormErf = (x) => { 402 Evaluate(interpreter, ds, "(norm " + x + ")", 0, alglib.normaldistribution(x)); 403 Evaluate(interpreter, ds, "(erf " + x + ")", 0, alglib.errorfunction(x)); 404 }; 405 406 Action<double> checkGamma = (x) => { 407 Evaluate(interpreter, ds, "(gamma " + x + ")", 0, alglib.gammafunction(x)); 408 }; 409 Action<double> checkPsi = (x) => { 410 try { 411 Evaluate(interpreter, ds, "(psi " + x + ")", 0, alglib.psi(x)); 412 } 413 catch (alglib.alglibexception) { // ignore cases where alglib throws an exception 414 } 415 }; 416 Action<double> checkDawson = (x) => { 417 Evaluate(interpreter, ds, "(dawson " + x + ")", 0, alglib.dawsonintegral(x)); 418 }; 419 Action<double> checkExpInt = (x) => { 420 Evaluate(interpreter, ds, "(expint " + x + ")", 0, alglib.exponentialintegralei(x)); 421 }; 422 423 foreach (var e in new[] { -2.0, -1.0, 0.0, 1.0, 2.0 }) { 424 checkAiry(e); 425 checkBessel(e); 426 checkSinCosIntegrals(e); 427 checkGamma(e); 428 checkExpInt(e); 429 checkDawson(e); 430 checkPsi(e); 431 checkNormErf(e); 432 checkFresnelSinCosIntegrals(e); 433 checkHypSinCosIntegrals(e); 434 } 435 } 436 437 private void EvaluateLaggedOperations(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds) { 438 // lag 439 Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 1, ds.GetDoubleValue("A", 0)); 440 Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 2, ds.GetDoubleValue("A", 1)); 441 Evaluate(interpreter, ds, "(lagVariable 1.0 a 0) ", 2, ds.GetDoubleValue("A", 2)); 442 Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1)); 443 444 // integral 445 Evaluate(interpreter, ds, "(integral -1.0 (variable 1.0 a)) ", 1, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1)); 446 Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a 1)) ", 1, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 447 Evaluate(interpreter, ds, "(integral -2.0 (variable 1.0 a)) ", 2, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 448 Evaluate(interpreter, ds, "(integral -1.0 (* (variable 1.0 a) (variable 1.0 b)))", 1, ds.GetDoubleValue("A", 0) * ds.GetDoubleValue("B", 0) + ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1)); 449 Evaluate(interpreter, ds, "(integral -2.0 3.0)", 1, 9.0); 450 451 // derivative 452 // (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1 453 Evaluate(interpreter, ds, "(diff (variable 1.0 a)) ", 5, (ds.GetDoubleValue("A", 5) + 2 * ds.GetDoubleValue("A", 4) - 2 * ds.GetDoubleValue("A", 2) - ds.GetDoubleValue("A", 1)) / 8.0); 454 Evaluate(interpreter, ds, "(diff (variable 1.0 b)) ", 5, (ds.GetDoubleValue("B", 5) + 2 * ds.GetDoubleValue("B", 4) - 2 * ds.GetDoubleValue("B", 2) - ds.GetDoubleValue("B", 1)) / 8.0); 455 Evaluate(interpreter, ds, "(diff (* (variable 1.0 a) (variable 1.0 b)))", 5, + 456 (ds.GetDoubleValue("A", 5) * ds.GetDoubleValue("B", 5) + 457 2 * ds.GetDoubleValue("A", 4) * ds.GetDoubleValue("B", 4) - 458 2 * ds.GetDoubleValue("A", 2) * ds.GetDoubleValue("B", 2) - 459 ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1)) / 8.0); 460 Evaluate(interpreter, ds, "(diff -2.0 3.0)", 5, 0.0); 461 462 // timelag 463 Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a 2)) ", 1, ds.GetDoubleValue("A", 2)); 464 Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a 2)) ", 2, ds.GetDoubleValue("A", 2)); 465 Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a 1) (lagVariable 1.0 b 2)))", 1, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 2)); 466 Evaluate(interpreter, ds, "(lag -2.0 3.0)", 1, 3.0); 467 } 468 469 private void EvaluateOperations(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds) { 249 470 // addition 250 471 Evaluate(interpreter, ds, "(+ (variable 2.0 a ))", 1, 4.0); … … 369 590 // mean 370 591 Evaluate(interpreter, ds, "(mean -1.0 1.0 -1.0)", 0, -1.0 / 3.0); 371 372 // lag 373 Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 1, ds.GetDoubleValue("A", 0)); 374 Evaluate(interpreter, ds, "(lagVariable 1.0 a -1) ", 2, ds.GetDoubleValue("A", 1)); 375 Evaluate(interpreter, ds, "(lagVariable 1.0 a 0) ", 2, ds.GetDoubleValue("A", 2)); 376 Evaluate(interpreter, ds, "(lagVariable 1.0 a 1) ", 0, ds.GetDoubleValue("A", 1)); 377 378 // integral 379 Evaluate(interpreter, ds, "(integral -1.0 (variable 1.0 a)) ", 1, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1)); 380 Evaluate(interpreter, ds, "(integral -1.0 (lagVariable 1.0 a 1)) ", 1, ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 381 Evaluate(interpreter, ds, "(integral -2.0 (variable 1.0 a)) ", 2, ds.GetDoubleValue("A", 0) + ds.GetDoubleValue("A", 1) + ds.GetDoubleValue("A", 2)); 382 Evaluate(interpreter, ds, "(integral -1.0 (* (variable 1.0 a) (variable 1.0 b)))", 1, ds.GetDoubleValue("A", 0) * ds.GetDoubleValue("B", 0) + ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1)); 383 Evaluate(interpreter, ds, "(integral -2.0 3.0)", 1, 9.0); 384 385 // derivative 386 // (f_0 + 2 * f_1 - 2 * f_3 - f_4) / 8; // h = 1 387 Evaluate(interpreter, ds, "(diff (variable 1.0 a)) ", 5, (ds.GetDoubleValue("A", 5) + 2 * ds.GetDoubleValue("A", 4) - 2 * ds.GetDoubleValue("A", 2) - ds.GetDoubleValue("A", 1)) / 8.0); 388 Evaluate(interpreter, ds, "(diff (variable 1.0 b)) ", 5, (ds.GetDoubleValue("B", 5) + 2 * ds.GetDoubleValue("B", 4) - 2 * ds.GetDoubleValue("B", 2) - ds.GetDoubleValue("B", 1)) / 8.0); 389 Evaluate(interpreter, ds, "(diff (* (variable 1.0 a) (variable 1.0 b)))", 5, + 390 (ds.GetDoubleValue("A", 5) * ds.GetDoubleValue("B", 5) + 391 2 * ds.GetDoubleValue("A", 4) * ds.GetDoubleValue("B", 4) - 392 2 * ds.GetDoubleValue("A", 2) * ds.GetDoubleValue("B", 2) - 393 ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 1)) / 8.0); 394 Evaluate(interpreter, ds, "(diff -2.0 3.0)", 5, 0.0); 395 396 // timelag 397 Evaluate(interpreter, ds, "(lag -1.0 (lagVariable 1.0 a 2)) ", 1, ds.GetDoubleValue("A", 2)); 398 Evaluate(interpreter, ds, "(lag -2.0 (lagVariable 1.0 a 2)) ", 2, ds.GetDoubleValue("A", 2)); 399 Evaluate(interpreter, ds, "(lag -1.0 (* (lagVariable 1.0 a 1) (lagVariable 1.0 b 2)))", 1, ds.GetDoubleValue("A", 1) * ds.GetDoubleValue("B", 2)); 400 Evaluate(interpreter, ds, "(lag -2.0 3.0)", 1, 3.0); 401 402 { 403 // special functions 404 Action<double> checkAiry = (x) => { 405 double ai, aip, bi, bip; 406 alglib.airy(x, out ai, out aip, out bi, out bip); 407 Evaluate(interpreter, ds, "(airya " + x + ")", 0, ai); 408 Evaluate(interpreter, ds, "(airyb " + x + ")", 0, bi); 409 }; 410 411 Action<double> checkBessel = (x) => { 412 Evaluate(interpreter, ds, "(bessel " + x + ")", 0, alglib.besseli0(x)); 413 }; 414 415 Action<double> checkSinCosIntegrals = (x) => { 416 double si, ci; 417 alglib.sinecosineintegrals(x, out si, out ci); 418 Evaluate(interpreter, ds, "(cosint " + x + ")", 0, ci); 419 Evaluate(interpreter, ds, "(sinint " + x + ")", 0, si); 420 }; 421 Action<double> checkHypSinCosIntegrals = (x) => { 422 double shi, chi; 423 alglib.hyperbolicsinecosineintegrals(x, out shi, out chi); 424 Evaluate(interpreter, ds, "(hypcosint " + x + ")", 0, chi); 425 Evaluate(interpreter, ds, "(hypsinint " + x + ")", 0, shi); 426 }; 427 Action<double> checkFresnelSinCosIntegrals = (x) => { 428 double c = 0, s = 0; 429 alglib.fresnelintegral(x, ref c, ref s); 430 Evaluate(interpreter, ds, "(fresnelcosint " + x + ")", 0, c); 431 Evaluate(interpreter, ds, "(fresnelsinint " + x + ")", 0, s); 432 }; 433 Action<double> checkNormErf = (x) => { 434 Evaluate(interpreter, ds, "(norm " + x + ")", 0, alglib.normaldistribution(x)); 435 Evaluate(interpreter, ds, "(erf " + x + ")", 0, alglib.errorfunction(x)); 436 }; 437 438 Action<double> checkGamma = (x) => { 439 Evaluate(interpreter, ds, "(gamma " + x + ")", 0, alglib.gammafunction(x)); 440 }; 441 Action<double> checkPsi = (x) => { 442 try { 443 Evaluate(interpreter, ds, "(psi " + x + ")", 0, alglib.psi(x)); 444 } 445 catch (alglib.alglibexception) { // ignore cases where alglib throws an exception 446 } 447 }; 448 Action<double> checkDawson = (x) => { 449 Evaluate(interpreter, ds, "(dawson " + x + ")", 0, alglib.dawsonintegral(x)); 450 }; 451 Action<double> checkExpInt = (x) => { 452 Evaluate(interpreter, ds, "(expint " + x + ")", 0, alglib.exponentialintegralei(x)); 453 }; 454 455 456 457 foreach (var e in new[] { -2.0, -1.0, 0.0, 1.0, 2.0 }) { 458 checkAiry(e); 459 checkBessel(e); 460 checkSinCosIntegrals(e); 461 checkGamma(e); 462 checkExpInt(e); 463 checkDawson(e); 464 checkPsi(e); 465 checkNormErf(e); 466 checkFresnelSinCosIntegrals(e); 467 checkHypSinCosIntegrals(e); 468 } 469 } 470 } 471 472 private void Evaluate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, Dataset ds, string expr, int index, double expected) { 592 } 593 594 private void Evaluate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataset ds, string expr, int index, double expected) { 473 595 var importer = new SymbolicExpressionImporter(); 474 596 ISymbolicExpressionTree tree = importer.Import(expr);
Note: See TracChangeset
for help on using the changeset viewer.