Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs @ 17726

Last change on this file since 17726 was 17726, checked in by pfleck, 4 years ago

#3040 Added a constant opt evaluator for vectors that uses the existing AutoDiff library by unrolling all vector operations.

File size: 9.3 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;
23using System.Collections.Generic;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
25
26namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
27  public enum OpCode : byte {
28    Add = 1,
29    Sub = 2,
30    Mul = 3,
31    Div = 4,
32    Sin = 5,
33    Cos = 6,
34    Tan = 7,
35    Log = 8,
36    Exp = 9,
37    IfThenElse = 10,
38    GT = 11,
39    LT = 12,
40    AND = 13,
41    OR = 14,
42    NOT = 15,
43    Average = 16,
44    Call = 17,
45    Variable = 18,
46    LagVariable = 19,
47    Constant = 20,
48    Arg = 21,
49    Power = 22,
50    Root = 23,
51    TimeLag = 24,
52    Integral = 25,
53    Derivative = 26,
54    VariableCondition = 27,
55    Square = 28,
56    SquareRoot = 29,
57    Gamma = 30,
58    Psi = 31,
59    Dawson = 32,
60    ExponentialIntegralEi = 33,
61    CosineIntegral = 34,
62    SineIntegral = 35,
63    HyperbolicCosineIntegral = 36,
64    HyperbolicSineIntegral = 37,
65    FresnelCosineIntegral = 38,
66    FresnelSineIntegral = 39,
67    AiryA = 40,
68    AiryB = 41,
69    Norm = 42,
70    Erf = 43,
71    Bessel = 44,
72    XOR = 45,
73    FactorVariable = 46,
74    BinaryFactorVariable = 47,
75    Absolute = 48,
76    AnalyticQuotient = 49,
77    Cube = 50,
78    CubeRoot = 51,
79    Tanh = 52,
80    Mean = 53,
81    StandardDeviation = 54,
82    Sum = 55,
83    Length = 56,
84    Min = 57,
85    Max = 58,
86    Variance = 59,
87    Skewness = 60,
88    Kurtosis = 61,
89    EuclideanDistance = 62,
90    Covariance = 63,
91    SubVector = 64,
92
93  }
94  public static class OpCodes {
95    // constants for API compatibility only
96    public const byte Add = (byte)OpCode.Add;
97    public const byte Sub = (byte)OpCode.Sub;
98    public const byte Mul = (byte)OpCode.Mul;
99    public const byte Div = (byte)OpCode.Div;
100    public const byte Sin = (byte)OpCode.Sin;
101    public const byte Cos = (byte)OpCode.Cos;
102    public const byte Tan = (byte)OpCode.Tan;
103    public const byte Log = (byte)OpCode.Log;
104    public const byte Exp = (byte)OpCode.Exp;
105    public const byte IfThenElse = (byte)OpCode.IfThenElse;
106    public const byte GT = (byte)OpCode.GT;
107    public const byte LT = (byte)OpCode.LT;
108    public const byte AND = (byte)OpCode.AND;
109    public const byte OR = (byte)OpCode.OR;
110    public const byte NOT = (byte)OpCode.NOT;
111    public const byte Average = (byte)OpCode.Average;
112    public const byte Call = (byte)OpCode.Call;
113    public const byte Variable = (byte)OpCode.Variable;
114    public const byte LagVariable = (byte)OpCode.LagVariable;
115    public const byte Constant = (byte)OpCode.Constant;
116    public const byte Arg = (byte)OpCode.Arg;
117    public const byte Power = (byte)OpCode.Power;
118    public const byte Root = (byte)OpCode.Root;
119    public const byte TimeLag = (byte)OpCode.TimeLag;
120    public const byte Integral = (byte)OpCode.Integral;
121    public const byte Derivative = (byte)OpCode.Derivative;
122    public const byte VariableCondition = (byte)OpCode.VariableCondition;
123    public const byte Square = (byte)OpCode.Square;
124    public const byte SquareRoot = (byte)OpCode.SquareRoot;
125    public const byte Gamma = (byte)OpCode.Gamma;
126    public const byte Psi = (byte)OpCode.Psi;
127    public const byte Dawson = (byte)OpCode.Dawson;
128    public const byte ExponentialIntegralEi = (byte)OpCode.ExponentialIntegralEi;
129    public const byte CosineIntegral = (byte)OpCode.CosineIntegral;
130    public const byte SineIntegral = (byte)OpCode.SineIntegral;
131    public const byte HyperbolicCosineIntegral = (byte)OpCode.HyperbolicCosineIntegral;
132    public const byte HyperbolicSineIntegral = (byte)OpCode.HyperbolicSineIntegral;
133    public const byte FresnelCosineIntegral = (byte)OpCode.FresnelCosineIntegral;
134    public const byte FresnelSineIntegral = (byte)OpCode.FresnelSineIntegral;
135    public const byte AiryA = (byte)OpCode.AiryA;
136    public const byte AiryB = (byte)OpCode.AiryB;
137    public const byte Norm = (byte)OpCode.Norm;
138    public const byte Erf = (byte)OpCode.Erf;
139    public const byte Bessel = (byte)OpCode.Bessel;
140    public const byte XOR = (byte)OpCode.XOR;
141    public const byte FactorVariable = (byte)OpCode.FactorVariable;
142    public const byte BinaryFactorVariable = (byte)OpCode.BinaryFactorVariable;
143    public const byte Absolute = (byte)OpCode.Absolute;
144    public const byte AnalyticQuotient = (byte)OpCode.AnalyticQuotient;
145    public const byte Cube = (byte)OpCode.Cube;
146    public const byte CubeRoot = (byte)OpCode.CubeRoot;
147    public const byte Tanh = (byte)OpCode.Tanh;
148    public const byte Mean = (byte)OpCode.Mean;
149    public const byte StandardDeviation = (byte)OpCode.StandardDeviation;
150    public const byte Sum = (byte)OpCode.Sum;
151    public const byte Length = (byte)OpCode.Length;
152    public const byte Min = (byte)OpCode.Min;
153    public const byte Max = (byte)OpCode.Max;
154    public const byte Variance = (byte)OpCode.Variance;
155    public const byte Skewness = (byte)OpCode.Skewness;
156    public const byte Kurtosis = (byte)OpCode.Kurtosis;
157    public const byte EuclideanDistance = (byte)OpCode.EuclideanDistance;
158    public const byte Covariance = (byte)OpCode.Covariance;
159    public const byte SubVector = (byte)OpCode.SubVector;
160
161
162    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
163      { typeof(Addition), OpCodes.Add },
164      { typeof(Subtraction), OpCodes.Sub },
165      { typeof(Multiplication), OpCodes.Mul },
166      { typeof(Division), OpCodes.Div },
167      { typeof(Sine), OpCodes.Sin },
168      { typeof(Cosine), OpCodes.Cos },
169      { typeof(Tangent), OpCodes.Tan },
170      { typeof (HyperbolicTangent), OpCodes.Tanh},
171      { typeof(Logarithm), OpCodes.Log },
172      { typeof(Exponential), OpCodes.Exp },
173      { typeof(IfThenElse), OpCodes.IfThenElse },
174      { typeof(GreaterThan), OpCodes.GT },
175      { typeof(LessThan), OpCodes.LT },
176      { typeof(And), OpCodes.AND },
177      { typeof(Or), OpCodes.OR },
178      { typeof(Not), OpCodes.NOT},
179      { typeof(Xor),OpCodes.XOR},
180      { typeof(Average), OpCodes.Average},
181      { typeof(InvokeFunction), OpCodes.Call },
182      { typeof(Variable), OpCodes.Variable },
183      { typeof(LaggedVariable), OpCodes.LagVariable },
184      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
185      { typeof(Constant), OpCodes.Constant },
186      { typeof(Argument), OpCodes.Arg },
187      { typeof(Power),OpCodes.Power},
188      { typeof(Root),OpCodes.Root},
189      { typeof(TimeLag), OpCodes.TimeLag},
190      { typeof(Integral), OpCodes.Integral},
191      { typeof(Derivative), OpCodes.Derivative},
192      { typeof(VariableCondition),OpCodes.VariableCondition},
193      { typeof(Square),OpCodes.Square},
194      { typeof(SquareRoot),OpCodes.SquareRoot},
195      { typeof(Gamma), OpCodes.Gamma },
196      { typeof(Psi), OpCodes.Psi },
197      { typeof(Dawson), OpCodes.Dawson},
198      { typeof(ExponentialIntegralEi), OpCodes.ExponentialIntegralEi },
199      { typeof(CosineIntegral), OpCodes.CosineIntegral },
200      { typeof(SineIntegral), OpCodes.SineIntegral },
201      { typeof(HyperbolicCosineIntegral), OpCodes.HyperbolicCosineIntegral },
202      { typeof(HyperbolicSineIntegral), OpCodes.HyperbolicSineIntegral },
203      { typeof(FresnelCosineIntegral), OpCodes.FresnelCosineIntegral },
204      { typeof(FresnelSineIntegral), OpCodes.FresnelSineIntegral },
205      { typeof(AiryA), OpCodes.AiryA },
206      { typeof(AiryB), OpCodes.AiryB },
207      { typeof(Norm), OpCodes.Norm},
208      { typeof(Erf), OpCodes.Erf},
209      { typeof(Bessel), OpCodes.Bessel},
210      { typeof(FactorVariable), OpCodes.FactorVariable },
211      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
212      { typeof(Absolute), OpCodes.Absolute },
213      { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient },
214      { typeof(Cube), OpCodes.Cube },
215      { typeof(CubeRoot), OpCodes.CubeRoot },
216      { typeof(Mean), OpCodes.Mean },
217      { typeof(StandardDeviation), OpCodes.StandardDeviation },
218      { typeof(Sum), OpCodes.Sum },
219      { typeof(Length), OpCodes.Length },
220      { typeof(Min), OpCodes.Min },
221      { typeof(Max), OpCodes.Max },
222      { typeof(Variance), OpCodes.Variance },
223      { typeof(Skewness), OpCodes.Skewness },
224      { typeof(Kurtosis), OpCodes.Kurtosis },
225      { typeof(EuclideanDistance), OpCodes.EuclideanDistance },
226      { typeof(Covariance), OpCodes.Covariance },
227      { typeof(SubVector), OpCodes.SubVector },
228    };
229
230    public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
231      if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out byte opCode)) return opCode;
232      else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
233    }
234  }
235}
Note: See TracBrowser for help on using the repository browser.