Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GeSymbolicRegressionSampleTest.cs @ 17246

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

#2925: merged r17037:17242 from trunk to branch

File size: 4.9 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.IO;
23using System.Linq;
24using HEAL.Attic;
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 {
34
35    private static readonly ProtoBufSerializer serializer = new ProtoBufSerializer();
36
37    #region artificial ant
38    private const string GeArtificialAntSampleFileName = "GE_ArtificialAnt";
39
40    [TestMethod]
41    [TestCategory("Samples.Create")]
42    [TestProperty("Time", "medium")]
43    public void CreateGeArtificialAntSampleTest() {
44      var geaa = CreateGeArtificialAntSample();
45      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeArtificialAntSampleFileName + SamplesUtils.SampleFileExtension);
46      serializer.Serialize(geaa, path);
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();
60
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
71
72      return ga;
73    }
74    #endregion
75
76    #region symbolic regression
77    private const string GeSymbolicRegressionSampleFileName = "GE_SymbReg";
78
79    [TestMethod]
80    [TestCategory("Samples.Create")]
81    [TestProperty("Time", "medium")]
82    public void CreateGeSymbolicRegressionSampleTest() {
83      var geSymbReg = CreateGeSymbolicRegressionSample();
84      string path = Path.Combine(SamplesUtils.SamplesDirectory, GeSymbolicRegressionSampleFileName + SamplesUtils.SampleFileExtension);
85      serializer.Serialize(geSymbReg, path);
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();
99
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
119
120      return ga;
121    }
122    #endregion
123  }
124}
Note: See TracBrowser for help on using the repository browser.