using System; using System.Linq; using System.Threading; using HeuristicLab.Algorithms.DataAnalysis; using HeuristicLab.Algorithms.GeneticAlgorithm; using HeuristicLab.Problems.DataAnalysis; using HeuristicLab.Random; using HeuristicLabEigen; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HeuristicLab.Problems.GaussianProcessTuning.Tests { [TestClass] public class UnitTest { [TestMethod] public void TestGrammar() { var g = new Grammar(); var r = new MersenneTwister(); var trees = (from i in Enumerable.Range(0, 1000) select HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 100, 10)) .ToArray(); } [TestMethod] public void TestInterpreter() { var interpreter = new Interpreter(); var g = new Grammar(); g.Symbols.Single(s => s is MeanMask).Enabled = true; g.Dimension = 1; var r = new MersenneTwister(31415); var problemData = new RegressionProblemData(); for (int i = 0; i < 1000; i++) { var t = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 50, 7); double negLogLikelihood; HeuristicLab.Algorithms.DataAnalysis.IGaussianProcessSolution solution; interpreter.EvaluateGaussianProcessConfiguration(t, problemData, 50, out negLogLikelihood, out solution); Console.WriteLine(); } } [TestMethod] public void TestGeneticAlgorithm() { var prob = new Problem(); prob.DimensionParameter.Value.Value = 1; var ga = new GeneticAlgorithm(); ga.Engine = new SequentialEngine.SequentialEngine(); ga.PopulationSize.Value = 100; ga.MaximumGenerations.Value = 10; ga.Problem = prob; var signal = new AutoResetEvent(false); Exception ex = null; ga.ExceptionOccurred += (sender, args) => { ex = args.Value; signal.Set(); }; ga.Stopped += (sender, args) => { signal.Set(); }; ga.Prepare(); ga.Start(); signal.WaitOne(); if (ex != null) throw ex; } /* [TestMethod] public void TestInterpreterPrediction() { var interpreter = new Interpreter(); var g = new Grammar(); g.Symbols.Single(s => s is MeanMask).Enabled = true; g.Dimension = 1; var r = new MersenneTwister(31415); var problemData = new RegressionProblemData(); double[] means; double[] stdDev; for (int i = 0; i < 10; i++) { var t = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ProbabilisticTreeCreator.Create(r, g, 50, 7); interpreter.EvaluateGaussianProcessConfiguration(t, problemData, problemData.Dataset, problemData.TestIndices, out means, out stdDev); } } */ } }