Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs

Last change on this file was 17456, checked in by pfleck, 5 years ago

#3040 Merged trunk to branch

File size: 3.2 KB
Line 
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
22using System.IO;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Algorithms.DataAnalysis;
26using HeuristicLab.Problems.DataAnalysis;
27using HeuristicLab.Problems.Instances.DataAnalysis;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace 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(-940.70700288855619, SamplesUtils.GetDoubleResult(gpr, "NegativeLogLikelihood"));
55      Assert.AreEqual(0.99563390794061979, SamplesUtils.GetDoubleResult(gpr, "Training R²"));
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}
Note: See TracBrowser for help on using the repository browser.