[11450] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 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 |
|
---|
| 22 | using System.IO;
|
---|
| 23 | using System.Linq;
|
---|
[17021] | 24 | using HEAL.Attic;
|
---|
[11450] | 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 {
|
---|
[11514] | 33 | private const string SampleFileName = "GPR";
|
---|
[11450] | 34 |
|
---|
[17021] | 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();
|
---|
[11514] | 42 | string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
|
---|
[17021] | 43 | serializer.Serialize(gpr, path);
|
---|
[11450] | 44 | }
|
---|
[11514] | 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);
|
---|
[16704] | 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));
|
---|
[11514] | 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 |
|
---|
[17456] | 70 | gpr.CovarianceFunction = gpr.CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().First();
|
---|
| 71 | gpr.MeanFunction = gpr.MeanFunctionParameter.ValidValues.OfType<MeanConst>().First();
|
---|
[11450] | 72 | gpr.MinimizationIterations = 20;
|
---|
| 73 | gpr.Seed = 0;
|
---|
| 74 | gpr.SetSeedRandomly = true;
|
---|
| 75 | #endregion
|
---|
[11514] | 76 |
|
---|
[11450] | 77 | gpr.Engine = new ParallelEngine.ParallelEngine();
|
---|
| 78 | return gpr;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|