Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs @ 17197

Last change on this file since 17197 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.1 KB
RevLine 
[11450]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11450]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;
[17105]24using HEAL.Attic;
[11450]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 {
[11907]33    private const string SampleFileName = "GPR";
[11450]34
[17105]35    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
36
[11450]37    [TestMethod]
38    [TestCategory("Samples.Create")]
39    [TestProperty("Time", "medium")]
40    public void CreateGaussianProcessRegressionSampleTest() {
41      var gpr = CreateGaussianProcessRegressionSample();
[11907]42      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
[17105]43      serializer.Serialize(gpr, path);
[11450]44    }
[11907]45
[11450]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);
[16934]54      Assert.AreEqual(-940.70700288855619, SamplesUtils.GetDoubleResult(gpr, "NegativeLogLikelihood"));
55      Assert.AreEqual(0.99563390794061979, SamplesUtils.GetDoubleResult(gpr, "Training R²"));
[11450]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));
[11907]64
[11450]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 = new CovarianceSquaredExponentialIso();
71      gpr.MeanFunction = new MeanConst();
72      gpr.MinimizationIterations = 20;
73      gpr.Seed = 0;
74      gpr.SetSeedRandomly = true;
75      #endregion
[11907]76
[11450]77      gpr.Engine = new ParallelEngine.ParallelEngine();
78      return gpr;
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.