Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 11009 was 10792, checked in by gkronber, 11 years ago

worked on a GP model for time series using toeplitz structure

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