Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/17 22:00:52 (7 years ago)
Author:
gkronber
Message:

#2796 worked on MCTS symb reg

Location:
branches/MCTS-SymbReg-2796
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/MCTS-SymbReg-2796

    • Property svn:ignore set to
      TestResults
  • branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs

    r15057 r15403  
    11using System;
    2 using System.Diagnostics.Contracts;
    32using System.Linq;
    43using System.Threading;
     
    87using HeuristicLab.Optimization;
    98using HeuristicLab.Problems.DataAnalysis;
    10 using HeuristicLab.Tests;
     9using HeuristicLab.Problems.Instances.DataAnalysis;
    1110using Microsoft.VisualStudio.TestTools.UnitTesting;
    1211
     
    2120    public void MctsSymbRegNumberOfSolutionsOneVariable() {
    2221      // this problem has only one variable
    23       var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
     22      var provider = new NguyenInstanceProvider();
    2423      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
    2524      {
     
    276275
    277276
    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    /*
    279340    // [TestMethod]
    280341    [TestCategory("Algorithms.DataAnalysis")]
    281342    [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")]
    314343    public void MctsSymbRegBenchmarkNguyen5() {
     344      // sin(x²)cos(x) - 1
    315345      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
    316346      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F5 ")));
     
    321351    [TestProperty("Time", "short")]
    322352    public void MctsSymbRegBenchmarkNguyen6() {
     353      // sin(x) + sin(x + x²)
    323354      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
    324355      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F6 ")));
    325356      TestMcts(regProblem);
    326357    }
     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    /*
    327380    // [TestMethod]
    328381    [TestCategory("Algorithms.DataAnalysis")]
    329382    [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")]
    346383    public void MctsSymbRegBenchmarkNguyen9() {
     384      //  sin(x) + sin(y²)
    347385      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
    348386      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F9 ")));
    349       TestMcts(regProblem, iterations: 10000);
     387      TestMcts(regProblem);
    350388    }
    351389    // [TestMethod]
     
    353391    [TestProperty("Time", "short")]
    354392    public void MctsSymbRegBenchmarkNguyen10() {
     393      // 2sin(x)cos(y)
    355394      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider();
    356395      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F10 ")));
    357396      TestMcts(regProblem);
    358397    }
    359     // [TestMethod]
     398    */
     399    [TestMethod]
    360400    [TestCategory("Algorithms.DataAnalysis")]
    361401    [TestProperty("Time", "short")]
    362402    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);
    364406      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F11 ")));
    365       TestMcts(regProblem, 10000, 0.95); // cannot solve exactly in 10000 iterations
    366     }
    367     // [TestMethod]
     407      TestMcts(regProblem, maxVariableReferences: 5, allowExp: true, allowLog: true, allowInv: false);
     408    }
     409    [TestMethod]
    368410    [TestCategory("Algorithms.DataAnalysis")]
    369411    [TestProperty("Time", "short")]
    370412    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);
    372415      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);
    374417    }
    375418
     
    377420
    378421    #region keijzer
    379     // [TestMethod]
     422    [TestMethod]
    380423    [TestCategory("Algorithms.DataAnalysis")]
    381424    [TestProperty("Time", "long")]
    382425    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);
    384429      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 5 f(")));
    385430      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    386431      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]
    391436    [TestCategory("Algorithms.DataAnalysis")]
    392437    [TestProperty("Time", "short")]
    393438    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);
    396442      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 6 f(")));
    397443      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    398444      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")]
    415451    [TestProperty("Time", "short")]
    416452    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);
    418455      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 8 f(")));
    419456      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    420457      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")]
    426463    [TestProperty("Time", "short")]
    427464    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);
    429467      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 9 f(")));
    430468      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    431469      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    /*
    451474    [TestMethod]
    452475    [TestCategory("Algorithms.DataAnalysis")]
    453476    [TestProperty("Time", "short")]
    454477    public void MctsSymbRegBenchmarkKeijzer11() {
     478      // xy + sin( (x-1) (y-1) )
    455479      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.KeijzerInstanceProvider();
    456480      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 11 f(")));
     
    460484    }
    461485     */
    462     // [TestMethod]
     486    [TestMethod]
    463487    [TestCategory("Algorithms.DataAnalysis")]
    464488    [TestProperty("Time", "short")]
    465489    public void MctsSymbRegBenchmarkKeijzer12() {
    466       // sames a Nguyen 12
    467       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);
    468492      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 12 f(")));
    469493      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    470494      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 iterations
    472     }
    473     // [TestMethod]
     495      TestMcts(regProblem, maxVariableReferences: 15, allowExp: false, allowLog: false, allowInv: false);
     496    }
     497    [TestMethod]
    474498    [TestCategory("Algorithms.DataAnalysis")]
    475499    [TestProperty("Time", "short")]
    476500    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);
    478503      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 14 f(")));
    479504      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    480505      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]
    484509    [TestCategory("Algorithms.DataAnalysis")]
    485510    [TestProperty("Time", "short")]
    486511    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);
    488514      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("Keijzer 15 f(")));
    489515      // some Keijzer problem instances have very large test partitions (here we are not concerened about test performance)
    490516      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);
    492518    }
    493519    #endregion
    494520
    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,
    496525      bool allowExp = true,
    497526      bool allowLog = true,
     
    505534      mctsSymbReg.Problem = regProblem;
    506535      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
    511538      mctsSymbReg.SetSeedRandomly = false;
    512539      mctsSymbReg.Seed = 1234;
     
    514541      mctsSymbReg.AllowedFactors.SetItemCheckedState(mctsSymbReg.AllowedFactors.Single(s => s.Value.Contains("log")), allowLog);
    515542      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
    517548      #endregion
    518549      RunAlgorithm(mctsSymbReg);
    519550
    520551      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);
    523586      var eps = 1.0 - successThreshold;
    524587      Assert.AreEqual(1.0, ((DoubleValue)mctsSymbReg.Results["Best solution quality (train)"].Value).Value, eps);
     
    546609      ucbPolicy.C = 1000; // essentially breadth first search
    547610      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);
    553616      #endregion
    554617      RunAlgorithm(mctsSymbReg);
Note: See TracChangeset for help on using the changeset viewer.