Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/20/17 12:38:06 (7 years ago)
Author:
gkronber
Message:

#2796 made several changes for debugging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs

    r15420 r15425  
    44using System.Threading;
    55using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies;
     6using HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg;
    67using HeuristicLab.Data;
    78using HeuristicLab.Optimization;
     
    1415  [TestClass()]
    1516  public class MctsSymbolicRegressionTest {
     17    #region heuristics
     18    [TestMethod]
     19    [TestCategory("Algorithms.DataAnalysis")]
     20    [TestProperty("Time", "short")]
     21    public void TestHeuristics() {
     22      {
     23        // a, b ~ U(0, 1) should be trivial
     24        var nRand = new MersenneTwister(1234);
     25
     26        int n = 10000; // large sample so that we can use the thresholds below
     27        var a = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     28        var b = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     29        var x = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     30        var y = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     31
     32        var z = a.Zip(b, (ai, bi) => ai * bi).ToArray();
     33
     34        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, z) > 0.05); // should be detected as relevant
     35        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, x, z) > 0.05); // a and b > 0 so these should be detected as well
     36        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, y, z) > 0.05);
     37        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, x, z) > 0.05);
     38        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) > 0.05);
     39        Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z) < 0.05);
     40      }
     41      {
     42        // a, b ~ U(1000, 2000) also trivial
     43        var nRand = new UniformDistributedRandom(new MersenneTwister(1234), 1000, 2000);
     44
     45        int n = 10000; // large sample so that we can use the thresholds below
     46        var a = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     47        var b = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     48        var x = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     49        var y = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     50
     51        var z = a.Zip(b, (ai, bi) => ai * bi).ToArray();
     52
     53        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, z) > 0.05); // should be detected as relevant
     54        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, x, z) > 0.05);
     55        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, y, z) > 0.05);
     56        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, x, z) > 0.05);
     57        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) > 0.05);
     58        Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z) < 0.05);
     59      }
     60      {
     61        // a, b ~ U(-1, 1)
     62        var nRand = new UniformDistributedRandom(new MersenneTwister(1234), -1, 1);
     63
     64        int n = 10000; // large sample so that we can use the thresholds below
     65        var a = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     66        var b = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     67        var x = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     68        var y = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     69
     70        var z = a.Zip(b, (ai, bi) => ai * bi).ToArray();
     71
     72        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, z) > 0.05); // should be detected as relevant
     73        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, x, z) < 0.05);
     74        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, y, z) < 0.05);
     75        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, x, z) < 0.05);
     76        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) < 0.05);
     77        Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z) < 0.05);
     78      }
     79      {
     80        // a, b ~ N(0, 1)
     81        var nRand = new NormalDistributedRandom(new MersenneTwister(1234), 0, 1);
     82
     83        int n = 10000; // large sample so that we can use the thresholds below
     84        var a = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     85        var b = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     86        var x = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     87        var y = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     88
     89        var z = a.Zip(b, (ai, bi) => ai * bi).ToArray();
     90
     91        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, z) > 0.05); // should be detected as relevant
     92        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, x, z) < 0.05);
     93        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, y, z) < 0.05);
     94        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, x, z) < 0.05);
     95        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) < 0.05);
     96        Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z) < 0.05);
     97      }
     98      {
     99        // a ~ N(100, 1), b ~ N(-100, 1)
     100        var nRand = new NormalDistributedRandom(new MersenneTwister(1234), 0, 1);
     101        var aRand = new NormalDistributedRandom(new MersenneTwister(1234), 100, 1);
     102        var bRand = new NormalDistributedRandom(new MersenneTwister(1234), -100, 1);
     103
     104        int n = 10000; // large sample so that we can use the thresholds below
     105        var a = Enumerable.Range(0, n).Select(_ => aRand.NextDouble()).ToArray();
     106        var b = Enumerable.Range(0, n).Select(_ => bRand.NextDouble()).ToArray();
     107        var x = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     108        var y = Enumerable.Range(0, n).Select(_ => nRand.NextDouble()).ToArray();
     109
     110        var z = a.Zip(b, (ai, bi) => ai * bi).ToArray();
     111
     112        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, z) > 0.05); // should be detected as relevant
     113        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, x, z) > 0.05); // a > 0
     114        Assert.IsTrue(Heuristics.CorrelationForInteraction(a, y, z) > 0.05);
     115        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, x, z) > 0.05); // b < 0
     116        Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) > 0.05);
     117        Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z) < 0.05);
     118      }
     119    }
     120    #endregion
     121
     122
    16123    #region expression hashing
    17124    [TestMethod]
     
    790897      }
    791898
    792       var ds = new Dataset(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "y" }, 
     899      var ds = new Dataset(new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "y" },
    793900        new[] { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, ys });
    794901
    795902
    796       var problemData = new RegressionProblemData(ds, new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}, "y");
     903      var problemData = new RegressionProblemData(ds, new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }, "y");
    797904
    798905      problemData.TrainingPartition.Start = 0;
     
    11181225
    11191226      // UCB tuned
    1120       // var ucbTuned = new UcbTuned();
    1121       // ucbTuned.C = 1.5;
    1122       // mctsSymbReg.Policy = ucbTuned;
     1227      var ucbTuned = new UcbTuned();
     1228      ucbTuned.C = 1;
     1229      mctsSymbReg.Policy = ucbTuned;
    11231230
    11241231
Note: See TracChangeset for help on using the changeset viewer.