Changeset 15403 for branches/MCTS-SymbReg-2796/Tests
- Timestamp:
- 10/04/17 22:00:52 (7 years ago)
- Location:
- branches/MCTS-SymbReg-2796
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MCTS-SymbReg-2796
-
Property
svn:ignore
set to
TestResults
-
Property
svn:ignore
set to
-
branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs
r15057 r15403 1 1 using System; 2 using System.Diagnostics.Contracts;3 2 using System.Linq; 4 3 using System.Threading; … … 8 7 using HeuristicLab.Optimization; 9 8 using HeuristicLab.Problems.DataAnalysis; 10 using HeuristicLab. Tests;9 using HeuristicLab.Problems.Instances.DataAnalysis; 11 10 using Microsoft.VisualStudio.TestTools.UnitTesting; 12 11 … … 21 20 public void MctsSymbRegNumberOfSolutionsOneVariable() { 22 21 // this problem has only one variable 23 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();22 var provider = new NguyenInstanceProvider(); 24 23 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 "))); 25 24 { … … 276 275 277 276 278 #region Nguyen 277 #region test structure search (no constants) 278 [TestMethod] 279 [TestCategory("Algorithms.DataAnalysis")] 280 [TestProperty("Time", "short")] 281 public void MctsSymbReg_NoConstants_Nguyen1() { 282 // x³ + x² + x 283 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 284 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 "))); 285 TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false); 286 } 287 [TestMethod] 288 [TestCategory("Algorithms.DataAnalysis")] 289 [TestProperty("Time", "short")] 290 public void MctsSymbReg_NoConstants_Nguyen2() { 291 // x^4 + x³ + x² + x 292 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 293 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 "))); 294 TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false); 295 } 296 [TestMethod] 297 [TestCategory("Algorithms.DataAnalysis")] 298 [TestProperty("Time", "short")] 299 public void MctsSymbReg_NoConstants_Nguyen3() { 300 // x^5 + x^4 + x³ + x² + x 301 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 302 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 "))); 303 TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false); 304 } 305 [TestMethod] 306 [TestCategory("Algorithms.DataAnalysis")] 307 [TestProperty("Time", "short")] 308 public void MctsSymbReg_NoConstants_Nguyen4() { 309 // x^6 + x^5 + x^4 + x³ + x² + x 310 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 311 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 "))); 312 TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false); 313 } 314 315 [TestMethod] 316 [TestCategory("Algorithms.DataAnalysis")] 317 [TestProperty("Time", "short")] 318 public void MctsSymbReg_NoConstants_Poly10() { 319 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.VariousInstanceProvider(seed: 1234); 320 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Poly-10"))); 321 TestMctsWithoutConstants(regProblem, allowExp: false, allowLog: false, allowInv: false); 322 } 323 #endregion 324 325 #region restricted structure but including numeric constants 326 327 [TestMethod] 328 [TestCategory("Algorithms.DataAnalysis")] 329 [TestProperty("Time", "short")] 330 public void MctsSymbRegKeijzer7() { 331 // ln(x) 332 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 333 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f("))); 334 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 335 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 336 TestMcts(regProblem, allowExp: false, allowLog: true, allowInv: false); 337 } 338 339 /* 279 340 // [TestMethod] 280 341 [TestCategory("Algorithms.DataAnalysis")] 281 342 [TestProperty("Time", "short")] 282 public void MctsSymbRegBenchmarkNguyen1() {283 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();284 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));285 TestMcts(regProblem);286 }287 // [TestMethod]288 [TestCategory("Algorithms.DataAnalysis")]289 [TestProperty("Time", "short")]290 public void MctsSymbRegBenchmarkNguyen2() {291 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();292 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));293 TestMcts(regProblem);294 }295 // [TestMethod]296 [TestCategory("Algorithms.DataAnalysis")]297 [TestProperty("Time", "short")]298 public void MctsSymbRegBenchmarkNguyen3() {299 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();300 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));301 TestMcts(regProblem, successThreshold: 0.99);302 }303 // [TestMethod]304 [TestCategory("Algorithms.DataAnalysis")]305 [TestProperty("Time", "short")]306 public void MctsSymbRegBenchmarkNguyen4() {307 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();308 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));309 TestMcts(regProblem);310 }311 // [TestMethod]312 [TestCategory("Algorithms.DataAnalysis")]313 [TestProperty("Time", "short")]314 343 public void MctsSymbRegBenchmarkNguyen5() { 344 // sin(x²)cos(x) - 1 315 345 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 316 346 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 "))); … … 321 351 [TestProperty("Time", "short")] 322 352 public void MctsSymbRegBenchmarkNguyen6() { 353 // sin(x) + sin(x + x²) 323 354 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 324 355 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 "))); 325 356 TestMcts(regProblem); 326 357 } 358 */ 359 [TestMethod] 360 [TestCategory("Algorithms.DataAnalysis")] 361 [TestProperty("Time", "short")] 362 public void MctsSymbRegBenchmarkNguyen7() { 363 // log(x + 1) + log(x² + 1) 364 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 365 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 "))); 366 TestMcts(regProblem, maxVariableReferences:5, allowExp: false, allowLog: true, allowInv: false); 367 } 368 [TestMethod] 369 [TestCategory("Algorithms.DataAnalysis")] 370 [TestProperty("Time", "short")] 371 public void MctsSymbRegBenchmarkNguyen8() { 372 // Sqrt(x) 373 // = x ^ 0.5 374 // = exp(0.5 * log(x)) 375 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 376 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 "))); 377 TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false); 378 } 379 /* 327 380 // [TestMethod] 328 381 [TestCategory("Algorithms.DataAnalysis")] 329 382 [TestProperty("Time", "short")] 330 public void MctsSymbRegBenchmarkNguyen7() {331 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();332 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F7 ")));333 TestMcts(regProblem);334 }335 // [TestMethod]336 [TestCategory("Algorithms.DataAnalysis")]337 [TestProperty("Time", "short")]338 public void MctsSymbRegBenchmarkNguyen8() {339 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();340 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F8 ")));341 TestMcts(regProblem, successThreshold: 0.99);342 }343 // [TestMethod]344 [TestCategory("Algorithms.DataAnalysis")]345 [TestProperty("Time", "short")]346 383 public void MctsSymbRegBenchmarkNguyen9() { 384 // sin(x) + sin(y²) 347 385 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 348 386 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 "))); 349 TestMcts(regProblem , iterations: 10000);387 TestMcts(regProblem); 350 388 } 351 389 // [TestMethod] … … 353 391 [TestProperty("Time", "short")] 354 392 public void MctsSymbRegBenchmarkNguyen10() { 393 // 2sin(x)cos(y) 355 394 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 356 395 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 "))); 357 396 TestMcts(regProblem); 358 397 } 359 // [TestMethod] 398 */ 399 [TestMethod] 360 400 [TestCategory("Algorithms.DataAnalysis")] 361 401 [TestProperty("Time", "short")] 362 402 public void MctsSymbRegBenchmarkNguyen11() { 363 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 403 // x ^ y , x > 0, y > 0 404 // = exp(y * log(x)) 405 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 364 406 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 "))); 365 TestMcts(regProblem, 10000, 0.95); // cannot solve exactly in 10000 iterations366 } 367 //[TestMethod]407 TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false); 408 } 409 [TestMethod] 368 410 [TestCategory("Algorithms.DataAnalysis")] 369 411 [TestProperty("Time", "short")] 370 412 public void MctsSymbRegBenchmarkNguyen12() { 371 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(); 413 // x^4 - x³ + y²/2 - y 414 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(seed: 1234); 372 415 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F12 "))); 373 TestMcts(regProblem, iterations: 10000, successThreshold: 0.99, allowLog: false, allowExp: false, allowInv: false);416 TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: false); 374 417 } 375 418 … … 377 420 378 421 #region keijzer 379 //[TestMethod]422 [TestMethod] 380 423 [TestCategory("Algorithms.DataAnalysis")] 381 424 [TestProperty("Time", "long")] 382 425 public void MctsSymbRegBenchmarkKeijzer5() { 383 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 426 // (30 * x * z) / ((x - 10) * y²) 427 // = 30 x z / (xy² - y²) 428 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 384 429 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f("))); 385 430 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 386 431 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 387 TestMcts(regProblem, iterations: 10000, allowExp: false, allowLog: false, allowSum: false, successThreshold: 0.99);388 } 389 390 //[TestMethod]432 TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: true); 433 } 434 435 [TestMethod] 391 436 [TestCategory("Algorithms.DataAnalysis")] 392 437 [TestProperty("Time", "short")] 393 438 public void MctsSymbRegBenchmarkKeijzer6() { 394 // Keijzer 6 f(x) = Sum(1 / i) From 1 to X 395 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 439 // Keijzer 6 f(x) = Sum(1 / i) From 1 to X , x \in [0..120] 440 // we can only approximate this 441 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 396 442 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f("))); 397 443 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 398 444 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 399 TestMcts(regProblem, allowLog: false, allowExp: false, successThreshold: 0.995); // cannot solve 400 } 401 402 // [TestMethod] 403 [TestCategory("Algorithms.DataAnalysis")] 404 [TestProperty("Time", "short")] 405 public void MctsSymbRegBenchmarkKeijzer7() { 406 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 407 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 7 f("))); 408 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 409 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 410 TestMcts(regProblem); 411 } 412 413 [TestMethod] 414 // [TestCategory("Algorithms.DataAnalysis")] 445 TestMcts(regProblem, maxVariableReferences: 20, allowExp: false, allowLog: false, allowInv: true); 446 } 447 448 449 [TestMethod] 450 [TestCategory("Algorithms.DataAnalysis")] 415 451 [TestProperty("Time", "short")] 416 452 public void MctsSymbRegBenchmarkKeijzer8() { 417 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 453 // sqrt(x) 454 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 418 455 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f("))); 419 456 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 420 457 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 421 TestMcts(regProblem );422 } 423 424 [TestMethod] 425 //[TestCategory("Algorithms.DataAnalysis")]458 TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false); 459 } 460 461 [TestMethod] 462 [TestCategory("Algorithms.DataAnalysis")] 426 463 [TestProperty("Time", "short")] 427 464 public void MctsSymbRegBenchmarkKeijzer9() { 428 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 465 // arcsinh(x) i.e. ln(x + sqrt(x² + 1)) 466 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 429 467 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f("))); 430 468 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 431 469 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 432 TestMcts(regProblem); 433 } 434 435 /* 436 * cannot solve this yet x^y 437 [TestMethod] 438 [TestCategory("Algorithms.DataAnalysis")] 439 [TestProperty("Time", "short")] 440 public void MctsSymbRegBenchmarkKeijzer10() { 441 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 442 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 10 f("))); 443 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 444 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 445 TestMcts(regProblem, iterations: 10000, successThreshold: 0.99); 446 } 447 */ 448 449 /* cannot solve this yet 450 * xy + sin( (x-1) (y-1) ) 470 TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false); 471 } 472 473 /* 451 474 [TestMethod] 452 475 [TestCategory("Algorithms.DataAnalysis")] 453 476 [TestProperty("Time", "short")] 454 477 public void MctsSymbRegBenchmarkKeijzer11() { 478 // xy + sin( (x-1) (y-1) ) 455 479 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 456 480 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f("))); … … 460 484 } 461 485 */ 462 //[TestMethod]486 [TestMethod] 463 487 [TestCategory("Algorithms.DataAnalysis")] 464 488 [TestProperty("Time", "short")] 465 489 public void MctsSymbRegBenchmarkKeijzer12() { 466 // sames a Nguyen 12467 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider( );490 // x^4 - x³ + y² / 2 - y, same as Nguyen 12 491 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 468 492 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f("))); 469 493 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 470 494 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 471 TestMcts(regProblem, iterations: 10000, allowLog: false, allowExp: false, allowInv: false, successThreshold: 0.99); // cannot solve exactly in 10000 iterations472 } 473 //[TestMethod]495 TestMcts(regProblem, maxVariableReferences: 15, allowExp: false, allowLog: false, allowInv: false); 496 } 497 [TestMethod] 474 498 [TestCategory("Algorithms.DataAnalysis")] 475 499 [TestProperty("Time", "short")] 476 500 public void MctsSymbRegBenchmarkKeijzer14() { 477 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 501 // 8 / (2 + x² + y²) 502 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 478 503 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f("))); 479 504 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 480 505 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 481 TestMcts(regProblem );482 } 483 //[TestMethod]506 TestMcts(regProblem, maxVariableReferences: 10, allowExp: false, allowLog: false, allowInv: true); 507 } 508 [TestMethod] 484 509 [TestCategory("Algorithms.DataAnalysis")] 485 510 [TestProperty("Time", "short")] 486 511 public void MctsSymbRegBenchmarkKeijzer15() { 487 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(); 512 // x³ / 5 + y³ / 2 - y - x 513 var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider(seed: 1234); 488 514 var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f("))); 489 515 // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance) 490 516 if (regProblem.TestPartition.End - regProblem.TestPartition.Start > 1000) regProblem.TestPartition.End = regProblem.TestPartition.Start + 1000; 491 TestMcts(regProblem, iterations: 10000, allowLog: false, allowExp: false, allowInv: false);517 TestMcts(regProblem, maxVariableReferences: 10, allowExp: false, allowLog: false, allowInv: false); 492 518 } 493 519 #endregion 494 520 495 private void TestMcts(IRegressionProblemData problemData, int iterations = 2000, double successThreshold = 0.999, 521 private void TestMcts(IRegressionProblemData problemData, 522 int iterations = 20000, 523 double successThreshold = 0.99999, 524 int maxVariableReferences = 5, 496 525 bool allowExp = true, 497 526 bool allowLog = true, … … 505 534 mctsSymbReg.Problem = regProblem; 506 535 mctsSymbReg.Iterations = iterations; 507 mctsSymbReg.MaxVariableReferences = 10; 508 var ucbPolicy = new Ucb(); 509 ucbPolicy.C = 2; 510 mctsSymbReg.Policy = ucbPolicy; 536 mctsSymbReg.MaxVariableReferences = maxVariableReferences; 537 511 538 mctsSymbReg.SetSeedRandomly = false; 512 539 mctsSymbReg.Seed = 1234; … … 514 541 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog); 515 542 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv); 516 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("sum of multiple")), allowSum); 543 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum); 544 545 mctsSymbReg.ScaleVariables = true; 546 mctsSymbReg.ConstantOptimizationIterations = 0; 547 517 548 #endregion 518 549 RunAlgorithm(mctsSymbReg); 519 550 520 551 Console.WriteLine(mctsSymbReg.ExecutionTime); 521 // R² >= 0.999 522 // using arequal to get output of the actual value 552 var eps = 1.0 - successThreshold; 553 Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps); 554 Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (test)"].Value).Value, eps); 555 } 556 557 558 private void TestMctsWithoutConstants(IRegressionProblemData problemData, int iterations = 200000, double successThreshold = 0.99999, 559 bool allowExp = true, 560 bool allowLog = true, 561 bool allowInv = true, 562 bool allowSum = true 563 ) { 564 var mctsSymbReg = new MctsSymbolicRegressionAlgorithm(); 565 var regProblem = new RegressionProblem(); 566 regProblem.ProblemDataParameter.Value = problemData; 567 #region Algorithm Configuration 568 mctsSymbReg.Problem = regProblem; 569 mctsSymbReg.Iterations = iterations; 570 mctsSymbReg.MaxVariableReferences = 25; 571 mctsSymbReg.SetSeedRandomly = false; 572 mctsSymbReg.Seed = 1234; 573 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp")), allowExp); 574 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog); 575 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 /")), allowInv); 576 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum); 577 578 // no constants 579 mctsSymbReg.ScaleVariables = false; 580 mctsSymbReg.ConstantOptimizationIterations = -1; 581 582 #endregion 583 RunAlgorithm(mctsSymbReg); 584 585 Console.WriteLine(mctsSymbReg.ExecutionTime); 523 586 var eps = 1.0 - successThreshold; 524 587 Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps); … … 546 609 ucbPolicy.C = 1000; // essentially breadth first search 547 610 mctsSymbReg.Policy = ucbPolicy; 548 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.StartsWith(" prod")), allowProd);549 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp ")), allowExp);550 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log ")), allowLog);551 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 / ")), allowInv);552 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains(" sum of multiple")), allowSum);611 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.StartsWith("x * y * ...")), allowProd); 612 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("exp(c * x * y ...)")), allowExp); 613 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log(c + c1 x + c2 x + ...)")), allowLog); 614 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("1 / (1 + c1 x + c2 x + ...)")), allowInv); 615 mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("t1(x) + t2(x) + ... ")), allowSum); 553 616 #endregion 554 617 RunAlgorithm(mctsSymbReg);
Note: See TracChangeset
for help on using the changeset viewer.