Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1967 worked on GPR evolution

File size: 2.8 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        double negLogLikelihood;
34        HeuristicLab.Algorithms.DataAnalysis.IGaussianProcessSolution solution;
35        interpreter.EvaluateGaussianProcessConfiguration(t, problemData, out negLogLikelihood, out solution);
36        Console.WriteLine();
37      }
38    }
39
40    [TestMethod]
41    public void TestGeneticAlgorithm() {
42      var prob = new Problem();
43      prob.DimensionParameter.Value.Value = 1;
44      var ga = new GeneticAlgorithm();
45      ga.Engine = new SequentialEngine.SequentialEngine();
46      ga.PopulationSize.Value = 100;
47      ga.MaximumGenerations.Value = 10;
48      ga.Problem = prob;
49
50      var signal = new AutoResetEvent(false);
51      Exception ex = null;
52
53      ga.ExceptionOccurred += (sender, args) => {
54        ex = args.Value;
55        signal.Set();
56      };
57      ga.Stopped += (sender, args) => {
58        signal.Set();
59      };
60
61      ga.Prepare();
62      ga.Start();
63
64      signal.WaitOne();
65      if (ex != null) throw ex;
66
67    }
68
69    /*
70    [TestMethod]
71    public void TestInterpreterPrediction() {
72      var interpreter = new Interpreter();
73      var g = new Grammar();
74      g.Symbols.Single(s => s is MeanMask).Enabled = true;
75      g.Dimension = 1;
76      var r = new MersenneTwister(31415);
77      var problemData = new RegressionProblemData();
78
79      double[] means;
80      double[] stdDev;
81      for (int i = 0; i < 10; i++) {
82        var t = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 50, 7);
83        interpreter.EvaluateGaussianProcessConfiguration(t, problemData, problemData.Dataset, problemData.TestIndices, out means, out stdDev);
84      }
85    }
86     */
87  }
88}
Note: See TracBrowser for help on using the repository browser.