Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs @ 16722

Last change on this file since 16722 was 16722, checked in by msemenki, 5 years ago

#2988: Add first version of GP for Evolvment models of models.

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