Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/Test/TestSymbRegInstances.cs @ 12850

Last change on this file since 12850 was 12025, checked in by gkronber, 10 years ago

#2283: unit test cases for symbolic regression

File size: 2.0 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Algorithms.Bandits.BanditPolicies;
4using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
5using HeuristicLab.Algorithms.GeneticProgramming;
6using HeuristicLab.Algorithms.GrammaticalOptimization;
7using HeuristicLab.Problems.GrammaticalOptimization.SymbReg;
8using Microsoft.VisualStudio.TestTools.UnitTesting;
9
10namespace HeuristicLab.Problems.GrammaticalOptimization.Test {
11  // tests for the brige to the HL symb-reg instances
12  [TestClass]
13  public class TestSymbRegInstances {
14    [TestMethod]
15    public void TestGetDataDescriptors() {
16      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
17      Assert.IsNotNull(problem);
18    }
19
20    [TestMethod]
21    public void TestConstantOptimization() {
22      double r2;
23      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
24      Assert.AreEqual(problem.Evaluate("a*b"), problem.OptimizeConstantsAndEvaluate("a*b"));
25      Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("a*b"), problem.Evaluate("a*b"));
26      Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a*b"), problem.Evaluate("a*b"), 1E-6);
27      Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a*b+1"), problem.Evaluate("a*b"), 1E-6);
28      Assert.IsTrue(problem.OptimizeConstantsAndEvaluate("0*a+b") >= problem.Evaluate("a+b"));
29      Assert.AreEqual(problem.OptimizeConstantsAndEvaluate("0*a+0*b"), problem.Evaluate("a+b"), 1E-6);
30      Assert.IsTrue(problem.OptimizeConstantsAndEvaluate("0*a+1*b") >= problem.Evaluate("a+b"));
31    }
32
33    [TestMethod]
34    [Timeout(1000 * 60 * 60 * 8)] // 8 hours
35    public void TestSequentialSolverForTower() {
36      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
37      var random = new Random(31415);
38      var solver = new SequentialSearch(problem, 50, random, 0, new GenericFunctionApproximationGrammarPolicy(problem, true));
39      solver.FoundNewBestSolution += (s, d) => {
40        Console.WriteLine("{0:F3} {1}", d, s);
41      };
42      solver.Run(100000);
43    }
44
45  }
46}
Note: See TracBrowser for help on using the repository browser.