Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/CrossValidationTest.cs @ 17823

Last change on this file since 17823 was 17823, checked in by gkronber, 3 years ago

#3099: added a unit test for the problem

File size: 2.6 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.Linq;
23using HeuristicLab.Data;
24using HeuristicLab.Optimization;
25using HeuristicLab.Problems.DataAnalysis;
26using HeuristicLab.Problems.Instances.DataAnalysis;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
29
30namespace HeuristicLab.Algorithms.DataAnalysis.Tests {
31  [TestClass]
32  public class CrossValidationTest {
33    [TestMethod]
34    [TestCategory("Algorithms.DataAnalysis")]
35    [TestProperty("Time", "medium")]
36    public void RunCrossValidationTest() {
37      var instanceProvider = new VariousInstanceProvider();
38     
39      var poly10 = instanceProvider.LoadData(instanceProvider.GetDataDescriptors().Single(x => x.Name.StartsWith("Poly")));
40      var symRegProb = new SymbolicRegressionSingleObjectiveProblem();
41      symRegProb.Load(poly10);
42      symRegProb.EstimationLimits.Lower = -1;
43      symRegProb.EstimationLimits.Upper = 1;
44
45      var ga = new GeneticAlgorithm.GeneticAlgorithm();
46      ga.Problem = symRegProb;
47      // minimal configuration
48      // we only need to check how estimation limits are set in the CV folds.
49      ga.PopulationSize.Value = 10;
50      ga.MaximumGenerations.Value = 1;
51
52
53      var cv = new CrossValidation();
54      cv.Algorithm = ga;
55      cv.Start();
56
57      Assert.AreEqual(Core.ExecutionState.Stopped, cv.ExecutionState);
58      IResult cvFoldsResult;
59      Assert.IsTrue(cv.Results.TryGetValue("CrossValidation Folds", out cvFoldsResult));
60      var runs = ((RunCollection)cvFoldsResult.Value);
61      var foldEstimationLimits = (DoubleLimit)runs.First().Parameters["EstimationLimits"];
62
63      Assert.AreEqual(symRegProb.EstimationLimits.Lower, foldEstimationLimits.Lower); // -1
64      Assert.AreEqual(symRegProb.EstimationLimits.Upper, foldEstimationLimits.Upper); // 1
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.