Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2283: unit test cases for symbolic regression

File size: 2.0 KB
RevLine 
[11732]1using System;
2using System.Linq;
[12014]3using HeuristicLab.Algorithms.Bandits.BanditPolicies;
4using HeuristicLab.Algorithms.Bandits.GrammarPolicies;
[11895]5using HeuristicLab.Algorithms.GeneticProgramming;
[11732]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() {
[12014]16      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
17      Assert.IsNotNull(problem);
18    }
[11732]19
[12014]20    [TestMethod]
21    public void TestConstantOptimization() {
22      double r2;
[11832]23      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
[11895]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"));
[11732]31    }
[12014]32
33    [TestMethod]
[12025]34    [Timeout(1000 * 60 * 60 * 8)] // 8 hours
[12014]35    public void TestSequentialSolverForTower() {
36      var problem = new SymbolicRegressionProblem(new Random(), "Tower");
37      var random = new Random(31415);
[12025]38      var solver = new SequentialSearch(problem, 50, random, 0, new GenericFunctionApproximationGrammarPolicy(problem, true));
[12014]39      solver.FoundNewBestSolution += (s, d) => {
40        Console.WriteLine("{0:F3} {1}", d, s);
41      };
[12025]42      solver.Run(100000);
[12014]43    }
44
[11732]45  }
46}
Note: See TracBrowser for help on using the repository browser.