[8323] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8323] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Threading;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[8463] | 27 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
[8323] | 28 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 29 |
|
---|
[9764] | 30 | namespace HeuristicLab.Algorithms.DataAnalysis.Tests {
|
---|
[8323] | 31 | [TestClass]
|
---|
[8463] | 32 | [DeploymentItem(@"HeuristicLab.Algorithms.DataAnalysis-3.4/co2.txt")]
|
---|
[8323] | 33 | public class GaussianProcessRegressionTest {
|
---|
| 34 | public GaussianProcessRegressionTest() { }
|
---|
| 35 |
|
---|
| 36 | private TestContext testContextInstance;
|
---|
| 37 | public TestContext TestContext {
|
---|
[9783] | 38 | get { return testContextInstance; }
|
---|
| 39 | set { testContextInstance = value; }
|
---|
[8323] | 40 | }
|
---|
| 41 |
|
---|
| 42 | private EventWaitHandle trigger = new AutoResetEvent(false);
|
---|
| 43 | private Exception ex;
|
---|
| 44 |
|
---|
| 45 | [TestMethod]
|
---|
[9783] | 46 | [TestCategory("Algorithms.DataAnalysis")]
|
---|
| 47 | [TestProperty("Time", "long")]
|
---|
[8323] | 48 | public void GaussianProcessRegressionPerformanceTest() {
|
---|
| 49 | ex = null;
|
---|
| 50 |
|
---|
[8371] | 51 | var alg = new GaussianProcessRegression();
|
---|
[8463] | 52 | alg.Engine = new HeuristicLab.SequentialEngine.SequentialEngine();
|
---|
[8371] | 53 |
|
---|
[8463] | 54 | alg.Problem = new RegressionProblem();
|
---|
| 55 | var provider = new RegressionCSVInstanceProvider();
|
---|
| 56 | var problemData = (RegressionProblemData)provider.ImportData("co2.txt");
|
---|
| 57 | problemData.TargetVariableParameter.ActualValue = problemData.TargetVariableParameter.ValidValues.First(x => x.Value == "interpolated");
|
---|
| 58 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "year"), false);
|
---|
| 59 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "month"), false);
|
---|
| 60 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "average"), false);
|
---|
| 61 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "interpolated"), false);
|
---|
| 62 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "trend"), false);
|
---|
| 63 | problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "#days"), false);
|
---|
[8323] | 64 |
|
---|
[8463] | 65 | alg.Problem.ProblemDataParameter.Value = problemData;
|
---|
[8323] | 66 |
|
---|
[8463] | 67 | alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
|
---|
| 68 | alg.Stopped += new EventHandler(cv_Stopped);
|
---|
| 69 |
|
---|
| 70 | alg.Prepare();
|
---|
| 71 | alg.Start();
|
---|
[8323] | 72 | trigger.WaitOne();
|
---|
| 73 | if (ex != null) throw ex;
|
---|
| 74 |
|
---|
[8463] | 75 | TestContext.WriteLine("Runtime: {0}", alg.ExecutionTime.ToString());
|
---|
[8323] | 76 | }
|
---|
| 77 |
|
---|
| 78 | private void cv_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
| 79 | ex = e.Value;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | private void cv_Stopped(object sender, EventArgs e) {
|
---|
| 83 | trigger.Set();
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|