Ignore:
Timestamp:
02/06/18 13:18:31 (20 months ago)
Author:
lkammere
Message:

#2886: Add simple data analysis tests and further informations about algorithm run.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/Test/GrammarEnumerationTest.cs

    r15714 r15723  
    11using System;
    2 using System.Collections.Generic;
    32using System.Linq;
    43using HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration;
     
    109
    1110namespace HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression {
    12   //[TestClass()]
     11  [TestClass()]
    1312  public class MctsSymbolicRegressionTest {
    1413    private const int Seed = 1234;
    1514    private IRandom rand;
    1615
    17     private const double SuccessThreshold = 0.99999;
     16    private const double SuccessThreshold = 0.9999999;
     17
     18    private GrammarEnumerationAlgorithm alg;
     19    private RegressionProblem problem;
    1820
    1921    [TestInitialize]
     
    2123      Console.Write("init called... ");
    2224      rand = new FastRandom(Seed);
    23     }
     25
     26      alg = new GrammarEnumerationAlgorithm();
     27      problem = new RegressionProblem();
     28      alg.Problem = problem;
     29      alg.GuiUpdateInterval = int.MaxValue;
     30    }
     31
     32
     33    private void TestGrammarEnumeration(IRegressionProblemData problemData) {
     34      alg.Problem.ProblemData = problemData;
     35
     36      // Run
     37      alg.Start();
     38
     39      // Evaluate results
     40      var eps = 1.0 - SuccessThreshold;
     41
     42      // Check if algorithm terminated correctly
     43      Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (training)"), "No training solution returned!");
     44      Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (test)"), "No test solution returned!");
     45
     46      // Check resultss
     47      Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (training)"].Value).Value, eps, "Training quality too low!");
     48      Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (test)"].Value).Value, eps, "Test quality too low!");
     49
     50      // Check overfitting
     51      Assert.AreEqual(alg.Results["Best solution string (training)"].Value.ToString(),
     52                      alg.Results["Best solution string (test)"].Value.ToString());
     53    }
     54
    2455
    2556    #region test structure search (no constants)
    2657    [TestMethod]
    27     [TestCategory("Algorithms.DataAnalysis")]
    28     [TestProperty("Time", "short")]
     58    [TestProperty("Goal", "structure search")]
    2959    public void MctsSymbReg_NoConstants_Nguyen1() {
    3060      // x³ + x² + x
     61      alg.MaxTreeSize = 15;
    3162      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    3263      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F1 ")));
    3364      TestGrammarEnumeration(regProblem);
    34     }
    35     [TestMethod]
    36     [TestCategory("Algorithms.DataAnalysis")]
    37     [TestProperty("Time", "short")]
     65
     66      Console.WriteLine("Nguyen1: " + alg.Results["Best solution string (training)"].Value);
     67    }
     68
     69    [TestMethod]
     70    [TestProperty("Goal", "structure search")]
    3871    public void MctsSymbReg_NoConstants_Nguyen2() {
    3972      // x^4 + x³ + x² + x
     73      alg.MaxTreeSize = 20;
    4074      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    4175      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F2 ")));
    4276      TestGrammarEnumeration(regProblem);
    43     }
    44     [TestMethod]
    45     [TestCategory("Algorithms.DataAnalysis")]
    46     [TestProperty("Time", "short")]
     77
     78      Console.WriteLine("Nguyen2: " + alg.Results["Best solution string (training)"].Value);
     79    }
     80
     81    /*  NEXT UP
     82    [TestMethod]
     83    [TestProperty("Goal", "structure search")]
    4784    public void MctsSymbReg_NoConstants_Nguyen3() {
    4885      // x^5 + x^4 + x³ + x² + x
     86      alg.MaxTreeSize = 25;
    4987      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    5088      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F3 ")));
     
    5290    }
    5391    [TestMethod]
    54     [TestCategory("Algorithms.DataAnalysis")]
    55     [TestProperty("Time", "short")]
     92    [TestProperty("Goal", "structure search")]
    5693    public void MctsSymbReg_NoConstants_Nguyen4() {
     94
    5795      // x^6 + x^5 + x^4 + x³ + x² + x
     96      alg.MaxTreeSize = 30;
    5897      var provider = new HeuristicLab.Problems.Instances.DataAnalysis.NguyenInstanceProvider(Seed);
    5998      var regProblem = provider.LoadData(provider.GetDataDescriptors().Single(x => x.Name.Contains("F4 ")));
    6099      TestGrammarEnumeration(regProblem);
    61     }
    62 
     100    } */
     101
     102
     103    #endregion
     104
     105    #region TODO
     106
     107#if false
    63108    [TestMethod]
    64109    [TestCategory("Algorithms.DataAnalysis")]
     
    357402      TestGrammarEnumeration(problemData);
    358403    }
    359     #endregion
    360404
    361405    #region restricted structure but including numeric constants
     
    557601    #endregion
    558602
    559     private void TestGrammarEnumeration(IRegressionProblemData problemData)
    560     {
    561       // Configure algorithm and problem
    562       var alg = new GrammarEnumerationAlgorithm();
    563       var problem = new RegressionProblem();
    564       alg.Problem = problem;
    565       problem.ProblemData = problemData;
    566      
    567       // Run
    568       alg.Start();
    569 
    570       // Evaluate results
    571       var eps = 1.0 - SuccessThreshold;
    572 
    573       // Check if algorithm terminated correctly
    574       Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (training)"), "No training solution returned!");
    575       Assert.IsTrue(alg.Results.ContainsKey("Best solution quality (test)"), "No test solution returned!");
    576 
    577       // Check resultss
    578       Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (training)"].Value).Value, eps, "Training quality too low!");
    579       Assert.AreEqual(1.0, ((DoubleValue)alg.Results["Best solution quality (test)"].Value).Value, eps, "Test quality too low!");
    580     }
     603#endif
     604    #endregion
    581605  }
    582606}
Note: See TracChangeset for help on using the changeset viewer.