Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs @ 16749

Last change on this file since 16749 was 16360, checked in by gkronber, 6 years ago

#2915 renamed class AnalyticalQuotient -> AnalyticQuotient

File size: 7.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
30  [StorableClass]
31  [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
32  public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
33    [StorableConstructor]
34    protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { }
35    protected FullFunctionalExpressionGrammar(FullFunctionalExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
36    public FullFunctionalExpressionGrammar()
37      : base(ItemAttribute.GetName(typeof(FullFunctionalExpressionGrammar)), ItemAttribute.GetDescription(typeof(FullFunctionalExpressionGrammar))) {
38      Initialize();
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new FullFunctionalExpressionGrammar(this, cloner);
43    }
44
45    private void Initialize() {
46      var add = new Addition();
47      var sub = new Subtraction();
48      var mul = new Multiplication();
49      var div = new Division();
50      var aq = new AnalyticQuotient();
51      var mean = new Average();
52      var sin = new Sine();
53      var cos = new Cosine();
54      var tan = new Tangent();
55      var log = new Logarithm();
56      var abs = new Absolute();
57      var pow = new Power();
58      pow.InitialFrequency = 0.0;
59      var square = new Square();
60      square.InitialFrequency = 0.0;
61      var cube = new Cube();
62      cube.InitialFrequency = 0.0;
63      var root = new Root();
64      root.InitialFrequency = 0.0;
65      var sqrt = new SquareRoot();
66      sqrt.InitialFrequency = 0.0;
67      var cubeRoot = new CubeRoot();
68      cubeRoot.InitialFrequency = 0.0;
69      var airyA = new AiryA();
70      airyA.InitialFrequency = 0.0;
71      var airyB = new AiryB();
72      airyB.InitialFrequency = 0.0;
73      var bessel = new Bessel();
74      bessel.InitialFrequency = 0.0;
75      var cosineIntegral = new CosineIntegral();
76      cosineIntegral.InitialFrequency = 0.0;
77      var dawson = new Dawson();
78      dawson.InitialFrequency = 0.0;
79      var erf = new Erf();
80      erf.InitialFrequency = 0.0;
81      var expIntegralEi = new ExponentialIntegralEi();
82      expIntegralEi.InitialFrequency = 0.0;
83      var fresnelCosineIntegral = new FresnelCosineIntegral();
84      fresnelCosineIntegral.InitialFrequency = 0.0;
85      var fresnelSineIntegral = new FresnelSineIntegral();
86      fresnelSineIntegral.InitialFrequency = 0.0;
87      var gamma = new Gamma();
88      gamma.InitialFrequency = 0.0;
89      var hypCosineIntegral = new HyperbolicCosineIntegral();
90      hypCosineIntegral.InitialFrequency = 0.0;
91      var hypSineIntegral = new HyperbolicSineIntegral();
92      hypSineIntegral.InitialFrequency = 0.0;
93      var norm = new Norm();
94      norm.InitialFrequency = 0.0;
95      var psi = new Psi();
96      psi.InitialFrequency = 0.0;
97      var sineIntegral = new SineIntegral();
98      sineIntegral.InitialFrequency = 0.0;
99
100      var exp = new Exponential();
101      var @if = new IfThenElse();
102      var gt = new GreaterThan();
103      var lt = new LessThan();
104      var and = new And();
105      var or = new Or();
106      var not = new Not();
107      var xor = new Xor();
108
109      var timeLag = new TimeLag();
110      timeLag.InitialFrequency = 0.0;
111      var integral = new Integral();
112      integral.InitialFrequency = 0.0;
113      var derivative = new Derivative();
114      derivative.InitialFrequency = 0.0;
115
116      var variableCondition = new VariableCondition();
117      variableCondition.InitialFrequency = 0.0;
118
119      var constant = new Constant();
120      constant.MinValue = -20;
121      constant.MaxValue = 20;
122      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
123      var binFactorVariable = new BinaryFactorVariable();
124      var factorVariable = new FactorVariable();
125      var laggedVariable = new LaggedVariable();
126      laggedVariable.InitialFrequency = 0.0;
127      var autoregressiveVariable = new AutoregressiveTargetVariable();
128      autoregressiveVariable.InitialFrequency = 0.0;
129      autoregressiveVariable.Enabled = false;
130
131      var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp,
132        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
133        @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };
134      var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
135        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
136      };
137
138      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition };
139      var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor };
140      var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, laggedVariable, autoregressiveVariable };
141
142      foreach (var symb in allSymbols)
143        AddSymbol(symb);
144
145      foreach (var funSymb in ternarySymbols) {
146        SetSubtreeCount(funSymb, 1, 3);
147      }
148      foreach (var funSymb in unaryFunctionSymbols) {
149        SetSubtreeCount(funSymb, 1, 1);
150      }
151      foreach (var funSymb in binaryFunctionSymbols) {
152        SetSubtreeCount(funSymb, 2, 2);
153      }
154      foreach (var terminalSymbol in terminalSymbols) {
155        SetSubtreeCount(terminalSymbol, 0, 0);
156      }
157
158      SetSubtreeCount(@if, 3, 3);
159
160
161      // allow each symbol as child of the start symbol
162      foreach (var symb in allSymbols) {
163        AddAllowedChildSymbol(StartSymbol, symb);
164        AddAllowedChildSymbol(DefunSymbol, symb);
165      }
166
167      // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0)
168      foreach (var parent in allSymbols.Except(terminalSymbols)) {
169        foreach (var child in allSymbols)
170          AddAllowedChildSymbol(parent, child);
171      }
172    }
173  }
174}
Note: See TracBrowser for help on using the repository browser.