Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2994-AutoDiffForIntervals/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs @ 17399

Last change on this file since 17399 was 17209, checked in by gkronber, 5 years ago

#2994: merged r17132:17198 from trunk to branch

File size: 4.9 KB
RevLine 
[11450]1#region License Information
2/* HeuristicLab
[17209]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;
[17120]24using HEAL.Attic;
[11450]25using HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm;
26using HeuristicLab.Problems.DataAnalysis.Symbolic;
27using HeuristicLab.Problems.Instances.DataAnalysis;
28using HeuristicLab.Selection;
29using Microsoft.VisualStudio.TestTools.UnitTesting;
30
31namespace HeuristicLab.Tests {
32  [TestClass]
33  public class GeSymbolicRegressionSampleTest {
[17120]34
35    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
36
[11514]37    #region artificial ant
38    private const string GeArtificialAntSampleFileName = "GE_ArtificialAnt";
[11450]39
40    [TestMethod]
41    [TestCategory("Samples.Create")]
42    [TestProperty("Time", "medium")]
43    public void CreateGeArtificialAntSampleTest() {
44      var geaa = CreateGeArtificialAntSample();
[11514]45      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeArtificialAntSampleFileName + SamplesUtils.SampleFileExtension);
[17120]46      serializer.Serialize(geaa, path);
[11450]47    }
48
49    [TestMethod]
50    [TestCategory("Samples.Execute")]
51    [TestProperty("Time", "long")]
52    public void RunGeArtificalAntSampleTest() {
53      var ga = CreateGeArtificialAntSample();
54      ga.SetSeedRandomly.Value = false;
55      SamplesUtils.RunAlgorithm(ga);
56    }
57
58    public OffspringSelectionGeneticAlgorithm CreateGeArtificialAntSample() {
59      OffspringSelectionGeneticAlgorithm ga = new OffspringSelectionGeneticAlgorithm();
[11514]60
[11450]61      #region Problem Configuration
62      var problem = new HeuristicLab.Problems.GrammaticalEvolution.GEArtificialAntProblem();
63      #endregion
64      #region Algorithm Configuration
65      ga.Name = "Grammatical Evolution - Artificial Ant (SantaFe)";
66      ga.Description = "Grammatical evolution algorithm for solving a artificial ant problem";
67      ga.Problem = problem;
68      SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
69        ga, 200, 1, 50, 0.05, 200);
70      #endregion
[11514]71
[11450]72      return ga;
73    }
74    #endregion
75
76    #region symbolic regression
[11514]77    private const string GeSymbolicRegressionSampleFileName = "GE_SymbReg";
78
[11450]79    [TestMethod]
80    [TestCategory("Samples.Create")]
81    [TestProperty("Time", "medium")]
82    public void CreateGeSymbolicRegressionSampleTest() {
83      var geSymbReg = CreateGeSymbolicRegressionSample();
[11514]84      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeSymbolicRegressionSampleFileName + SamplesUtils.SampleFileExtension);
[17120]85      serializer.Serialize(geSymbReg, path);
[11450]86    }
87
88    [TestMethod]
89    [TestCategory("Samples.Execute")]
90    [TestProperty("Time", "long")]
91    public void RunGeSymbolicRegressionSampleTest() {
92      var ga = CreateGeSymbolicRegressionSample();
93      ga.SetSeedRandomly.Value = false;
94      SamplesUtils.RunAlgorithm(ga);
95    }
96
97    public OffspringSelectionGeneticAlgorithm CreateGeSymbolicRegressionSample() {
98      var ga = new OffspringSelectionGeneticAlgorithm();
[11514]99
[11450]100      #region Problem Configuration
101      var problem = new HeuristicLab.Problems.GrammaticalEvolution.GESymbolicRegressionSingleObjectiveProblem();
102
103      #endregion
104      #region Algorithm Configuration
105      ga.Name = "Grammatical Evolution - Symbolic Regression (Poly-10)";
106      ga.Description = "Grammatical evolution algorithm for solving a symbolic regression problem problem";
107      ga.Problem = problem;
108      problem.Load(new PolyTen().GenerateRegressionData());
109
110      // must occur after loading problem data because the grammar creates symbols for random constants once the data is loaded
111      var consts = problem.SymbolicExpressionTreeGrammar.AllowedSymbols.OfType<Constant>().ToList();
112      foreach (var c in consts) {
113        problem.SymbolicExpressionTreeGrammar.RemoveSymbol(c);
114      }
115
116      SamplesUtils.ConfigureOsGeneticAlgorithmParameters<GenderSpecificSelector, Encodings.IntegerVectorEncoding.SinglePointCrossover, Encodings.IntegerVectorEncoding.UniformOnePositionManipulator>(
117        ga, 1000, 1, 50, 0.05, 200);
118      #endregion
[11514]119
[11450]120      return ga;
121    }
[11514]122    #endregion
[11450]123  }
124}
Note: See TracBrowser for help on using the repository browser.