[3841] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9835] | 3 | * Copyright (C) 2002-2013 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[5686] | 23 | using System.Linq;
|
---|
[4722] | 24 | using HeuristicLab.Common;
|
---|
[3841] | 25 | using HeuristicLab.Core;
|
---|
[4068] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3841] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5574] | 28 |
|
---|
[3841] | 29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 30 | [StorableClass]
|
---|
| 31 | [Item("FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]
|
---|
[5686] | 32 | public class FullFunctionalExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
|
---|
[4722] | 33 | [StorableConstructor]
|
---|
| 34 | protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { }
|
---|
| 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();
|
---|
| 50 | var mean = new Average();
|
---|
| 51 | var sin = new Sine();
|
---|
| 52 | var cos = new Cosine();
|
---|
| 53 | var tan = new Tangent();
|
---|
| 54 | var log = new Logarithm();
|
---|
[5288] | 55 | var pow = new Power();
|
---|
[5384] | 56 | pow.InitialFrequency = 0.0;
|
---|
[7695] | 57 | var square = new Square();
|
---|
| 58 | square.InitialFrequency = 0.0;
|
---|
[5384] | 59 | var root = new Root();
|
---|
| 60 | root.InitialFrequency = 0.0;
|
---|
[7695] | 61 | var sqrt = new SquareRoot();
|
---|
| 62 | sqrt.InitialFrequency = 0.0;
|
---|
[7696] | 63 | var airyA = new AiryA();
|
---|
[7707] | 64 | airyA.InitialFrequency = 0.0;
|
---|
[7696] | 65 | var airyB = new AiryB();
|
---|
[7707] | 66 | airyB.InitialFrequency = 0.0;
|
---|
[7696] | 67 | var bessel = new Bessel();
|
---|
[7707] | 68 | bessel.InitialFrequency = 0.0;
|
---|
[7696] | 69 | var cosineIntegral = new CosineIntegral();
|
---|
[7707] | 70 | cosineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 71 | var dawson = new Dawson();
|
---|
[7707] | 72 | dawson.InitialFrequency = 0.0;
|
---|
[7696] | 73 | var erf = new Erf();
|
---|
[7707] | 74 | erf.InitialFrequency = 0.0;
|
---|
[7696] | 75 | var expIntegralEi = new ExponentialIntegralEi();
|
---|
[7707] | 76 | expIntegralEi.InitialFrequency = 0.0;
|
---|
[7696] | 77 | var fresnelCosineIntegral = new FresnelCosineIntegral();
|
---|
[7707] | 78 | fresnelCosineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 79 | var fresnelSineIntegral = new FresnelSineIntegral();
|
---|
[7707] | 80 | fresnelSineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 81 | var gamma = new Gamma();
|
---|
[7707] | 82 | gamma.InitialFrequency = 0.0;
|
---|
[7696] | 83 | var hypCosineIntegral = new HyperbolicCosineIntegral();
|
---|
[7707] | 84 | hypCosineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 85 | var hypSineIntegral = new HyperbolicSineIntegral();
|
---|
[7707] | 86 | hypSineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 87 | var norm = new Norm();
|
---|
[7707] | 88 | norm.InitialFrequency = 0.0;
|
---|
[7696] | 89 | var psi = new Psi();
|
---|
[7707] | 90 | psi.InitialFrequency = 0.0;
|
---|
[7696] | 91 | var sineIntegral = new SineIntegral();
|
---|
[7707] | 92 | sineIntegral.InitialFrequency = 0.0;
|
---|
[7696] | 93 |
|
---|
[3841] | 94 | var exp = new Exponential();
|
---|
| 95 | var @if = new IfThenElse();
|
---|
| 96 | var gt = new GreaterThan();
|
---|
| 97 | var lt = new LessThan();
|
---|
| 98 | var and = new And();
|
---|
| 99 | var or = new Or();
|
---|
| 100 | var not = new Not();
|
---|
[5373] | 101 |
|
---|
| 102 | var timeLag = new TimeLag();
|
---|
| 103 | timeLag.InitialFrequency = 0.0;
|
---|
| 104 | var integral = new Integral();
|
---|
| 105 | integral.InitialFrequency = 0.0;
|
---|
| 106 | var derivative = new Derivative();
|
---|
| 107 | derivative.InitialFrequency = 0.0;
|
---|
| 108 |
|
---|
[5467] | 109 | var variableCondition = new VariableCondition();
|
---|
| 110 | variableCondition.InitialFrequency = 0.0;
|
---|
| 111 |
|
---|
[3841] | 112 | var constant = new Constant();
|
---|
| 113 | constant.MinValue = -20;
|
---|
| 114 | constant.MaxValue = 20;
|
---|
[5574] | 115 | var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
|
---|
[4249] | 116 | var laggedVariable = new LaggedVariable();
|
---|
| 117 | laggedVariable.InitialFrequency = 0.0;
|
---|
[9241] | 118 | var autoregressiveVariable = new AutoregressiveTargetVariable();
|
---|
| 119 | autoregressiveVariable.InitialFrequency = 0.0;
|
---|
| 120 | autoregressiveVariable.Enabled = false;
|
---|
[3841] | 121 |
|
---|
[7696] | 122 | var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp,
|
---|
| 123 | airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
|
---|
[9241] | 124 | @if, gt, lt, and, or, not, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition };
|
---|
[7696] | 125 | var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
|
---|
| 126 | airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
|
---|
| 127 | };
|
---|
[5373] | 128 |
|
---|
[5467] | 129 | var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition };
|
---|
[7696] | 130 | var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
|
---|
[9241] | 131 | var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, autoregressiveVariable };
|
---|
[3841] | 132 |
|
---|
| 133 | foreach (var symb in allSymbols)
|
---|
| 134 | AddSymbol(symb);
|
---|
| 135 |
|
---|
[7696] | 136 | foreach (var funSymb in ternarySymbols) {
|
---|
[5686] | 137 | SetSubtreeCount(funSymb, 1, 3);
|
---|
[3841] | 138 | }
|
---|
| 139 | foreach (var funSymb in unaryFunctionSymbols) {
|
---|
[5686] | 140 | SetSubtreeCount(funSymb, 1, 1);
|
---|
[3841] | 141 | }
|
---|
| 142 | foreach (var funSymb in binaryFunctionSymbols) {
|
---|
[5686] | 143 | SetSubtreeCount(funSymb, 2, 2);
|
---|
[3841] | 144 | }
|
---|
[4249] | 145 | foreach (var terminalSymbol in terminalSymbols) {
|
---|
[5686] | 146 | SetSubtreeCount(terminalSymbol, 0, 0);
|
---|
[4249] | 147 | }
|
---|
| 148 |
|
---|
[5686] | 149 | SetSubtreeCount(@if, 3, 3);
|
---|
[3841] | 150 |
|
---|
[4249] | 151 |
|
---|
[3841] | 152 | // allow each symbol as child of the start symbol
|
---|
| 153 | foreach (var symb in allSymbols) {
|
---|
[5686] | 154 | AddAllowedChildSymbol(StartSymbol, symb);
|
---|
[5726] | 155 | AddAllowedChildSymbol(DefunSymbol, symb);
|
---|
[3841] | 156 | }
|
---|
| 157 |
|
---|
| 158 | // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0)
|
---|
[5686] | 159 | foreach (var parent in allSymbols.Except(terminalSymbols)) {
|
---|
| 160 | foreach (var child in allSymbols)
|
---|
| 161 | AddAllowedChildSymbol(parent, child);
|
---|
[3841] | 162 | }
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|