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