1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 |
|
---|
22 | using System.IO;
|
---|
23 | using System.Linq;
|
---|
24 | using HEAL.Attic;
|
---|
25 | using HeuristicLab.Algorithms.DataAnalysis;
|
---|
26 | using HeuristicLab.Problems.DataAnalysis;
|
---|
27 | using HeuristicLab.Problems.Instances.DataAnalysis;
|
---|
28 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Tests {
|
---|
31 | [TestClass]
|
---|
32 | public class GaussianProcessRegressionSampleTest {
|
---|
33 | private const string SampleFileName = "GPR";
|
---|
34 |
|
---|
35 | private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
|
---|
36 |
|
---|
37 | [TestMethod]
|
---|
38 | [TestCategory("Samples.Create")]
|
---|
39 | [TestProperty("Time", "medium")]
|
---|
40 | public void CreateGaussianProcessRegressionSampleTest() {
|
---|
41 | var gpr = CreateGaussianProcessRegressionSample();
|
---|
42 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
43 | serializer.Serialize(gpr, path);
|
---|
44 | }
|
---|
45 |
|
---|
46 | [TestMethod]
|
---|
47 | [TestCategory("Samples.Execute")]
|
---|
48 | [TestProperty("Time", "long")]
|
---|
49 | public void RunGaussianProcessRegressionSample() {
|
---|
50 | var gpr = CreateGaussianProcessRegressionSample();
|
---|
51 | gpr.SetSeedRandomly = false;
|
---|
52 | gpr.Seed = 1618551877;
|
---|
53 | SamplesUtils.RunAlgorithm(gpr);
|
---|
54 | Assert.AreEqual(-992.445399028808, SamplesUtils.GetDoubleResult(gpr, "NegativeLogLikelihood"), 1e-8);
|
---|
55 | Assert.AreEqual(0.99559260785271853, SamplesUtils.GetDoubleResult(gpr, "Training R²"), 1e-8);
|
---|
56 | }
|
---|
57 |
|
---|
58 | private GaussianProcessRegression CreateGaussianProcessRegressionSample() {
|
---|
59 | var gpr = new GaussianProcessRegression();
|
---|
60 | var provider = new VariousInstanceProvider();
|
---|
61 | var instance = provider.GetDataDescriptors().Where(x => x.Name.Contains("Spatial co-evolution")).Single();
|
---|
62 | var regProblem = new RegressionProblem();
|
---|
63 | regProblem.Load(provider.LoadData(instance));
|
---|
64 |
|
---|
65 | #region Algorithm Configuration
|
---|
66 | gpr.Name = "Gaussian Process Regression";
|
---|
67 | gpr.Description = "A Gaussian process regression algorithm which solves the spatial co-evolution benchmark problem";
|
---|
68 | gpr.Problem = regProblem;
|
---|
69 |
|
---|
70 | gpr.CovarianceFunction = gpr.CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().First();
|
---|
71 | gpr.MeanFunction = gpr.MeanFunctionParameter.ValidValues.OfType<MeanConst>().First();
|
---|
72 | gpr.MinimizationIterations = 20;
|
---|
73 | gpr.Seed = 0;
|
---|
74 | gpr.SetSeedRandomly = true;
|
---|
75 | #endregion
|
---|
76 |
|
---|
77 | gpr.Engine = new ParallelEngine.ParallelEngine();
|
---|
78 | return gpr;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|