Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GaussianProcessEvolution/HeuristicLab.Problems.GaussianProcessTuning.Tests/UnitTest.cs @ 8753

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

#1967 initial import of Gaussian process evolution plugin

File size: 2.6 KB
Line 
1using System;
2using System.Linq;
3using System.Threading;
4using HeuristicLab.Algorithms.GeneticAlgorithm;
5using HeuristicLab.Problems.DataAnalysis;
6using HeuristicLab.Random;
7using Microsoft.VisualStudio.TestTools.UnitTesting;
8
9namespace HeuristicLab.Problems.GaussianProcessTuning.Tests {
10  [TestClass]
11  public class UnitTest {
12    [TestMethod]
13    public void TestGrammar() {
14      var g = new Grammar();
15      var r = new MersenneTwister();
16      var trees = (from i in Enumerable.Range(0, 1000)
17                   select
18                     HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 100, 10))
19        .ToArray();
20    }
21
22    [TestMethod]
23    public void TestInterpreter() {
24      var interpreter = new Interpreter();
25      var g = new Grammar();
26      g.Symbols.Single(s => s is MeanMask).Enabled = true;
27      g.Dimension = 1;
28      var r = new MersenneTwister(31415);
29      var problemData = new RegressionProblemData();
30
31      for (int i = 0; i < 1000; i++) {
32        var t = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 50, 7);
33        Console.WriteLine(interpreter.EvaluateGaussianProcessConfiguration(t, problemData));
34      }
35    }
36
37    [TestMethod]
38    public void TestGeneticAlgorithm() {
39      var prob = new Problem();
40      prob.DimensionParameter.Value.Value = 1;
41      var ga = new GeneticAlgorithm();
42      ga.Engine = new SequentialEngine.SequentialEngine();
43      ga.PopulationSize.Value = 100;
44      ga.MaximumGenerations.Value = 10;
45      ga.Problem = prob;
46
47      var signal = new AutoResetEvent(false);
48      Exception ex = null;
49
50      ga.ExceptionOccurred += (sender, args) => {
51        ex = args.Value;
52        signal.Set();
53      };
54      ga.Stopped += (sender, args) => {
55        signal.Set();
56      };
57
58      ga.Prepare();
59      ga.Start();
60
61      signal.WaitOne();
62      if (ex != null) throw ex;
63
64    }
65
66    /*
67    [TestMethod]
68    public void TestInterpreterPrediction() {
69      var interpreter = new Interpreter();
70      var g = new Grammar();
71      g.Symbols.Single(s => s is MeanMask).Enabled = true;
72      g.Dimension = 1;
73      var r = new MersenneTwister(31415);
74      var problemData = new RegressionProblemData();
75
76      double[] means;
77      double[] stdDev;
78      for (int i = 0; i < 10; i++) {
79        var t = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 50, 7);
80        interpreter.EvaluateGaussianProcessConfiguration(t, problemData, problemData.Dataset, problemData.TestIndices, out means, out stdDev);
81      }
82    }
83     */
84  }
85}
Note: See TracBrowser for help on using the repository browser.