Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3127-MRGP-VarPro-Exploration/HeuristicLab.Problems.VarProMRGP/3.3/VarProGrammar.cs @ 18003

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

#3127: changed VarProMRGP to use HEAL.VarPro instead of VarPro implementation in NativeInterpreter

File size: 4.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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HEAL.Attic;
25using System.Collections.Generic;
26using System;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
29
30namespace HeuristicLab.Problems.VarProMRGP {
31  [Item("VarProGrammar", "")]
32  [StorableType("E2FFA4F4-2301-4A28-BC6E-670A0D233262")]
33  public sealed class VarProGrammar : DataAnalysisGrammar {
34    [StorableConstructor]
35    private VarProGrammar(StorableConstructorFlag _) : base(_) { }
36
37    private VarProGrammar(VarProGrammar orig, Cloner cloner) : base(orig, cloner) { }
38    public VarProGrammar() : base("VarProGrammar", "") {
39      Initialize();
40    }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new VarProGrammar(this, cloner);
43    }
44
45    private void Initialize() {
46      Symbol sumForLogSy = new Addition();
47      sumForLogSy.Name = "SimpleAdd";
48      Symbol mulSy = new Multiplication();
49      Symbol simpleMulSy = new Multiplication();
50      simpleMulSy.Name = "SimpleMul";
51      Symbol aqSy = new AnalyticQuotient();
52      Symbol logSy = new Logarithm();
53      Symbol absSy = new Absolute();
54      Symbol expSy = new Exponential();
55
56      var constSy = new Constant();
57      constSy.MinValue = -1;
58      constSy.MaxValue = 1;
59
60      var constOneSy = new Constant();
61      constOneSy.Name = "<1.0>";
62      constOneSy.MinValue = 1;
63      constOneSy.MaxValue = 1;
64      constOneSy.ManipulatorMu = 0.0;
65      constOneSy.ManipulatorSigma = 0.0;
66      constOneSy.MultiplicativeManipulatorSigma = 0.0;
67
68      var varSy = new DataAnalysis.Symbolic.Variable();
69      varSy.WeightMu = 1.0;
70      varSy.WeightSigma = 0.0;
71
72      var allSymbols = new List<Symbol>() { sumForLogSy, mulSy, simpleMulSy, aqSy, logSy, absSy, expSy, constSy, constOneSy, varSy };
73
74      foreach (var symb in allSymbols)
75        AddSymbol(symb);
76
77      SetSubtreeCount(sumForLogSy, 2, 5);
78      SetSubtreeCount(simpleMulSy, 2, 5);
79      SetSubtreeCount(mulSy, 2, 4);
80
81
82      foreach (var funSymb in new[] { logSy, expSy, absSy }) {
83        SetSubtreeCount(funSymb, 1, 1);
84      }
85
86      SetSubtreeCount(aqSy, 2, 2);
87      SetSubtreeCount(constSy, 0, 0);
88      SetSubtreeCount(constOneSy, 0, 0);
89      SetSubtreeCount(varSy, 0, 0);
90
91      // allowed root symbols
92      foreach (var childSy in new[] { mulSy, varSy, logSy, expSy, aqSy }) {
93        AddAllowedChildSymbol(StartSymbol, childSy);
94        AddAllowedChildSymbol(DefunSymbol, childSy);
95      }
96
97      // allowed under mul
98      foreach (var childSy in new[] { varSy, logSy, expSy }) {
99        AddAllowedChildSymbol(mulSy, childSy);
100      }
101
102      // log(abs(sum))
103      // allowed for log:
104      AddAllowedChildSymbol(logSy, absSy);
105      // allowed for abs:
106      AddAllowedChildSymbol(absSy, sumForLogSy);
107
108      // allowed for exp:
109      AddAllowedChildSymbol(expSy, simpleMulSy);
110
111      // allowed for simpleAdd arg 0:
112      AddAllowedChildSymbol(sumForLogSy, constOneSy, 0); // enforce log ( 1 + ...)
113
114      // allowed for simpleAdd ars 1 - n:
115      for (int arg = 1; arg < this.GetMaximumSubtreeCount(sumForLogSy); arg++)
116        AddAllowedChildSymbol(sumForLogSy, simpleMulSy, arg);
117
118      // allowed for simpleMul arg 0:
119      AddAllowedChildSymbol(simpleMulSy, constSy, 0);
120
121      // allowed for simpleMul ars 1 - n:
122      for (int arg = 1; arg < this.GetMaximumSubtreeCount(simpleMulSy); arg++)
123        AddAllowedChildSymbol(simpleMulSy, varSy, arg);
124
125      // allowed numerators for AQ:
126      foreach (var child in new[] { constOneSy, varSy, mulSy })
127        AddAllowedChildSymbol(aqSy, child, 0);
128
129      // allowed denominator for AQ:
130      foreach (var child in new[] { varSy, sumForLogSy })
131        AddAllowedChildSymbol(aqSy, child, 1);
132    }
133  }
134}
Note: See TracBrowser for help on using the repository browser.