Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs @ 8796

Last change on this file since 8796 was 8463, checked in by gkronber, 12 years ago

#1902 improved GPR implementation

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Linq;
24using System.Threading;
25using HeuristicLab.Algorithms.DataAnalysis;
26using HeuristicLab.Common;
27using HeuristicLab.Problems.DataAnalysis;
28using HeuristicLab.Problems.Instances.DataAnalysis;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
30
31namespace HeuristicLab.Algorithms.DataAnalysis_34.Tests {
32  [TestClass]
33  [DeploymentItem(@"HeuristicLab.Algorithms.DataAnalysis-3.4/co2.txt")]
34  public class GaussianProcessRegressionTest {
35    public GaussianProcessRegressionTest() { }
36
37    private TestContext testContextInstance;
38
39    /// <summary>
40    ///Gets or sets the test context which provides
41    ///information about and functionality for the current test run.
42    ///</summary>
43    public TestContext TestContext {
44      get {
45        return testContextInstance;
46      }
47      set {
48        testContextInstance = value;
49      }
50    }
51
52    private EventWaitHandle trigger = new AutoResetEvent(false);
53    private Exception ex;
54
55    [TestMethod]
56    public void GaussianProcessRegressionPerformanceTest() {
57      ex = null;
58
59      var alg = new GaussianProcessRegression();
60      alg.Engine = new HeuristicLab.SequentialEngine.SequentialEngine();
61
62      alg.Problem = new RegressionProblem();
63      var provider = new RegressionCSVInstanceProvider();
64      var problemData = (RegressionProblemData)provider.ImportData("co2.txt");
65      problemData.TargetVariableParameter.ActualValue = problemData.TargetVariableParameter.ValidValues.First(x => x.Value == "interpolated");
66      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "year"), false);
67      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "month"), false);
68      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "average"), false);
69      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "interpolated"), false);
70      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "trend"), false);
71      problemData.InputVariables.SetItemCheckedState(problemData.InputVariables.First(x => x.Value == "#days"), false);
72
73      alg.Problem.ProblemDataParameter.Value = problemData;
74
75      alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
76      alg.Stopped += new EventHandler(cv_Stopped);
77
78      alg.Prepare();
79      alg.Start();
80      trigger.WaitOne();
81      if (ex != null) throw ex;
82
83      TestContext.WriteLine("Runtime: {0}", alg.ExecutionTime.ToString());
84    }
85
86    private void cv_ExceptionOccurred(object sender, EventArgs<Exception> e) {
87      ex = e.Value;
88    }
89
90    private void cv_Stopped(object sender, EventArgs e) {
91      trigger.Set();
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.