Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs @ 17105

Last change on this file since 17105 was 17105, checked in by mkommend, 5 years ago

#2520: Merged 16584, 16585,16594,16595, 16625, 16658, 16659, 16672, 16707, 16729, 16792, 16796, 16797, 16799, 16819, 16906, 16907, 16908, 16933, 16945, 16992, 16994, 16995, 16996, 16997, 17014, 17015, 17017, 17020, 17021, 17022, 17023, 17024, 17029, 17086, 17087, 17088, 17089 into stable.

File size: 4.9 KB
RevLine 
[11450]1#region License Information
2/* HeuristicLab
[17097]3 * Copyright (C) 2002-2019 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.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 {
[17105]34
35    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
36
[11907]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();
[11907]45      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeArtificialAntSampleFileName + SamplesUtils.SampleFileExtension);
[17105]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();
[11907]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
[11907]71
[11450]72      return ga;
73    }
74    #endregion
75
76    #region symbolic regression
[11907]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();
[11907]84      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeSymbolicRegressionSampleFileName + SamplesUtils.SampleFileExtension);
[17105]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();
[11907]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
[11907]119
[11450]120      return ga;
121    }
[11907]122    #endregion
[11450]123  }
124}
Note: See TracBrowser for help on using the repository browser.