Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18237 was 18237, checked in by pfleck, 3 years ago

#3040 Added sub-vector, std dev and variance support for Tree to Tensor converter.

File size: 15.7 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    SubVectorSubtree = 65,
93
94    #region Time Series Symbols
95    Median = 100,
96    Quantile = 101,
97
98    AbsoluteEnergy = 102,
99    BinnedEntropy = 103,
100    HasLargeStandardDeviation = 104,
101    HasVarianceLargerThanStd = 105,
102    IsSymmetricLooking = 106,
103    NumberDataPointsAboveMean = 107,
104    NumberDataPointsAboveMedian = 108,
105    NumberDataPointsBelowMean = 109,
106    NumberDataPointsBelowMedian = 110,
107
108    ArimaModelCoefficients = 111,
109    ContinuousWaveletTransformationCoefficients = 112,
110    FastFourierTransformationCoefficient = 113,
111    FirstIndexMax = 124,
112    FirstIndexMin = 125,
113    LastIndexMax = 126,
114    LastIndexMin = 127,
115    LongestStrikeAboveMean = 128,
116    LongestStrikeAboveMedian = 129,
117    LongestStrikeBelowMean = 130,
118    LongestStrikeBelowMedian = 131,
119    LongestStrikePositive = 132,
120    LongestStrikeNegative = 133,
121    LongestStrikeZero = 134,
122    MeanAbsoluteChange = 135,
123    MeanAbsoluteChangeQuantiles = 136,
124    MeanAutocorrelation = 137,
125    LaggedAutocorrelation = 138,
126    MeanSecondDerivateCentral = 139,
127    NumberPeaksOfSize = 140,
128    LargeNumberOfPeaks = 141,
129    TimeReversalAsymmetryStatistic = 142
130    #endregion
131  }
132  public static class OpCodes {
133    // constants for API compatibility only
134    public const byte Add = (byte)OpCode.Add;
135    public const byte Sub = (byte)OpCode.Sub;
136    public const byte Mul = (byte)OpCode.Mul;
137    public const byte Div = (byte)OpCode.Div;
138    public const byte Sin = (byte)OpCode.Sin;
139    public const byte Cos = (byte)OpCode.Cos;
140    public const byte Tan = (byte)OpCode.Tan;
141    public const byte Log = (byte)OpCode.Log;
142    public const byte Exp = (byte)OpCode.Exp;
143    public const byte IfThenElse = (byte)OpCode.IfThenElse;
144    public const byte GT = (byte)OpCode.GT;
145    public const byte LT = (byte)OpCode.LT;
146    public const byte AND = (byte)OpCode.AND;
147    public const byte OR = (byte)OpCode.OR;
148    public const byte NOT = (byte)OpCode.NOT;
149    public const byte Average = (byte)OpCode.Average;
150    public const byte Call = (byte)OpCode.Call;
151    public const byte Variable = (byte)OpCode.Variable;
152    public const byte LagVariable = (byte)OpCode.LagVariable;
153    public const byte Constant = (byte)OpCode.Constant;
154    public const byte Arg = (byte)OpCode.Arg;
155    public const byte Power = (byte)OpCode.Power;
156    public const byte Root = (byte)OpCode.Root;
157    public const byte TimeLag = (byte)OpCode.TimeLag;
158    public const byte Integral = (byte)OpCode.Integral;
159    public const byte Derivative = (byte)OpCode.Derivative;
160    public const byte VariableCondition = (byte)OpCode.VariableCondition;
161    public const byte Square = (byte)OpCode.Square;
162    public const byte SquareRoot = (byte)OpCode.SquareRoot;
163    public const byte Gamma = (byte)OpCode.Gamma;
164    public const byte Psi = (byte)OpCode.Psi;
165    public const byte Dawson = (byte)OpCode.Dawson;
166    public const byte ExponentialIntegralEi = (byte)OpCode.ExponentialIntegralEi;
167    public const byte CosineIntegral = (byte)OpCode.CosineIntegral;
168    public const byte SineIntegral = (byte)OpCode.SineIntegral;
169    public const byte HyperbolicCosineIntegral = (byte)OpCode.HyperbolicCosineIntegral;
170    public const byte HyperbolicSineIntegral = (byte)OpCode.HyperbolicSineIntegral;
171    public const byte FresnelCosineIntegral = (byte)OpCode.FresnelCosineIntegral;
172    public const byte FresnelSineIntegral = (byte)OpCode.FresnelSineIntegral;
173    public const byte AiryA = (byte)OpCode.AiryA;
174    public const byte AiryB = (byte)OpCode.AiryB;
175    public const byte Norm = (byte)OpCode.Norm;
176    public const byte Erf = (byte)OpCode.Erf;
177    public const byte Bessel = (byte)OpCode.Bessel;
178    public const byte XOR = (byte)OpCode.XOR;
179    public const byte FactorVariable = (byte)OpCode.FactorVariable;
180    public const byte BinaryFactorVariable = (byte)OpCode.BinaryFactorVariable;
181    public const byte Absolute = (byte)OpCode.Absolute;
182    public const byte AnalyticQuotient = (byte)OpCode.AnalyticQuotient;
183    public const byte Cube = (byte)OpCode.Cube;
184    public const byte CubeRoot = (byte)OpCode.CubeRoot;
185    public const byte Tanh = (byte)OpCode.Tanh;
186    public const byte Mean = (byte)OpCode.Mean;
187    public const byte StandardDeviation = (byte)OpCode.StandardDeviation;
188    public const byte Sum = (byte)OpCode.Sum;
189    public const byte Length = (byte)OpCode.Length;
190    public const byte Min = (byte)OpCode.Min;
191    public const byte Max = (byte)OpCode.Max;
192    public const byte Variance = (byte)OpCode.Variance;
193    public const byte Skewness = (byte)OpCode.Skewness;
194    public const byte Kurtosis = (byte)OpCode.Kurtosis;
195    public const byte EuclideanDistance = (byte)OpCode.EuclideanDistance;
196    public const byte Covariance = (byte)OpCode.Covariance;
197    public const byte SubVector = (byte)OpCode.SubVector;
198    public const byte SubVectorSubtree = (byte)OpCode.SubVectorSubtree;
199    #region Time Series Symbols
200    public const byte Median = (byte)OpCode.Median;
201    public const byte Quantile = (byte)OpCode.Quantile;
202
203    public const byte AbsoluteEnergy = (byte)OpCode.AbsoluteEnergy;
204    public const byte BinnedEntropy = (byte)OpCode.BinnedEntropy;
205    public const byte HasLargeStandardDeviation = (byte)OpCode.HasLargeStandardDeviation;
206    public const byte HasVarianceLargerThanStd = (byte)OpCode.HasVarianceLargerThanStd;
207    public const byte IsSymmetricLooking = (byte)OpCode.IsSymmetricLooking;
208    public const byte NumberDataPointsAboveMean = (byte)OpCode.NumberDataPointsAboveMean;
209    public const byte NumberDataPointsAboveMedian = (byte)OpCode.NumberDataPointsAboveMedian;
210    public const byte NumberDataPointsBelowMean = (byte)OpCode.NumberDataPointsBelowMean;
211    public const byte NumberDataPointsBelowMedian = (byte)OpCode.NumberDataPointsBelowMedian;
212
213    public const byte ArimaModelCoefficients = (byte)OpCode.ArimaModelCoefficients;
214    public const byte ContinuousWaveletTransformationCoefficients = (byte)OpCode.ContinuousWaveletTransformationCoefficients;
215    public const byte FastFourierTransformationCoefficient = (byte)OpCode.FastFourierTransformationCoefficient;
216    public const byte FirstIndexMax = (byte)OpCode.FirstIndexMax;
217    public const byte FirstIndexMin = (byte)OpCode.FirstIndexMin;
218    public const byte LastIndexMax = (byte)OpCode.LastIndexMax;
219    public const byte LastIndexMin = (byte)OpCode.LastIndexMin;
220    public const byte LongestStrikeAboveMean = (byte)OpCode.LongestStrikeAboveMean;
221    public const byte LongestStrikeAboveMedian = (byte)OpCode.LongestStrikeAboveMedian;
222    public const byte LongestStrikeBelowMean = (byte)OpCode.LongestStrikeBelowMean;
223    public const byte LongestStrikeBelowMedian = (byte)OpCode.LongestStrikeBelowMedian;
224    public const byte LongestStrikePositive = (byte)OpCode.LongestStrikePositive;
225    public const byte LongestStrikeNegative = (byte)OpCode.LongestStrikeNegative;
226    public const byte LongestStrikeZero = (byte)OpCode.LongestStrikeZero;
227    public const byte MeanAbsoluteChange = (byte)OpCode.MeanAbsoluteChange;
228    public const byte MeanAbsoluteChangeQuantiles = (byte)OpCode.MeanAbsoluteChangeQuantiles;
229    public const byte MeanAutocorrelation = (byte)OpCode.MeanAutocorrelation;
230    public const byte LaggedAutocorrelation = (byte)OpCode.LaggedAutocorrelation;
231    public const byte MeanSecondDerivateCentral = (byte)OpCode.MeanSecondDerivateCentral;
232    public const byte NumberPeaksOfSize = (byte)OpCode.NumberPeaksOfSize;
233    public const byte LargeNumberOfPeaks = (byte)OpCode.LargeNumberOfPeaks;
234    public const byte TimeReversalAsymmetryStatistic = (byte)OpCode.TimeReversalAsymmetryStatistic;
235    #endregion
236
237
238    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
239      { typeof(Addition), OpCodes.Add },
240      { typeof(Subtraction), OpCodes.Sub },
241      { typeof(Multiplication), OpCodes.Mul },
242      { typeof(Division), OpCodes.Div },
243      { typeof(Sine), OpCodes.Sin },
244      { typeof(Cosine), OpCodes.Cos },
245      { typeof(Tangent), OpCodes.Tan },
246      { typeof (HyperbolicTangent), OpCodes.Tanh},
247      { typeof(Logarithm), OpCodes.Log },
248      { typeof(Exponential), OpCodes.Exp },
249      { typeof(IfThenElse), OpCodes.IfThenElse },
250      { typeof(GreaterThan), OpCodes.GT },
251      { typeof(LessThan), OpCodes.LT },
252      { typeof(And), OpCodes.AND },
253      { typeof(Or), OpCodes.OR },
254      { typeof(Not), OpCodes.NOT},
255      { typeof(Xor),OpCodes.XOR},
256      { typeof(Average), OpCodes.Average},
257      { typeof(InvokeFunction), OpCodes.Call },
258      { typeof(Variable), OpCodes.Variable },
259      { typeof(LaggedVariable), OpCodes.LagVariable },
260      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
261      { typeof(Constant), OpCodes.Constant },
262      { typeof(Argument), OpCodes.Arg },
263      { typeof(Power),OpCodes.Power},
264      { typeof(Root),OpCodes.Root},
265      { typeof(TimeLag), OpCodes.TimeLag},
266      { typeof(Integral), OpCodes.Integral},
267      { typeof(Derivative), OpCodes.Derivative},
268      { typeof(VariableCondition),OpCodes.VariableCondition},
269      { typeof(Square),OpCodes.Square},
270      { typeof(SquareRoot),OpCodes.SquareRoot},
271      { typeof(Gamma), OpCodes.Gamma },
272      { typeof(Psi), OpCodes.Psi },
273      { typeof(Dawson), OpCodes.Dawson},
274      { typeof(ExponentialIntegralEi), OpCodes.ExponentialIntegralEi },
275      { typeof(CosineIntegral), OpCodes.CosineIntegral },
276      { typeof(SineIntegral), OpCodes.SineIntegral },
277      { typeof(HyperbolicCosineIntegral), OpCodes.HyperbolicCosineIntegral },
278      { typeof(HyperbolicSineIntegral), OpCodes.HyperbolicSineIntegral },
279      { typeof(FresnelCosineIntegral), OpCodes.FresnelCosineIntegral },
280      { typeof(FresnelSineIntegral), OpCodes.FresnelSineIntegral },
281      { typeof(AiryA), OpCodes.AiryA },
282      { typeof(AiryB), OpCodes.AiryB },
283      { typeof(Norm), OpCodes.Norm},
284      { typeof(Erf), OpCodes.Erf},
285      { typeof(Bessel), OpCodes.Bessel},
286      { typeof(FactorVariable), OpCodes.FactorVariable },
287      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
288      { typeof(Absolute), OpCodes.Absolute },
289      { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient },
290      { typeof(Cube), OpCodes.Cube },
291      { typeof(CubeRoot), OpCodes.CubeRoot },
292      { typeof(Mean), OpCodes.Mean },
293      { typeof(StandardDeviation), OpCodes.StandardDeviation },
294      { typeof(Sum), OpCodes.Sum },
295      { typeof(Length), OpCodes.Length },
296      { typeof(Min), OpCodes.Min },
297      { typeof(Max), OpCodes.Max },
298      { typeof(Variance), OpCodes.Variance },
299      { typeof(Skewness), OpCodes.Skewness },
300      { typeof(Kurtosis), OpCodes.Kurtosis },
301      { typeof(EuclideanDistance), OpCodes.EuclideanDistance },
302      { typeof(Covariance), OpCodes.Covariance },
303      { typeof(SubVector), OpCodes.SubVector },
304      { typeof(SubVectorSubtree), OpCodes.SubVectorSubtree },
305
306      #region Time Series Symbols
307      { typeof(Median), OpCodes.Median },
308      { typeof(Quantile), OpCodes.Quantile },
309
310      { typeof(AbsoluteEnergy), OpCodes.AbsoluteEnergy },
311      { typeof(BinnedEntropy), OpCodes.BinnedEntropy },
312      { typeof(HasLargeStandardDeviation), OpCodes.HasLargeStandardDeviation },
313      { typeof(HasVarianceLargerThanStd), OpCodes.HasVarianceLargerThanStd },
314      { typeof(IsSymmetricLooking), OpCodes.IsSymmetricLooking },
315      { typeof(NumberDataPointsAboveMean), OpCodes.NumberDataPointsAboveMean },
316      { typeof(NumberDataPointsAboveMedian), OpCodes.NumberDataPointsAboveMedian },
317      { typeof(NumberDataPointsBelowMean), OpCodes.NumberDataPointsBelowMean },
318      { typeof(NumberDataPointsBelowMedian), OpCodes.NumberDataPointsBelowMedian },
319
320      { typeof(ArimaModelCoefficients), OpCodes.ArimaModelCoefficients },
321      { typeof(ContinuousWaveletTransformationCoefficients), OpCodes.ContinuousWaveletTransformationCoefficients },
322      { typeof(FastFourierTransformationCoefficient), OpCodes.FastFourierTransformationCoefficient },
323      { typeof(FirstIndexMax), OpCodes.FirstIndexMax },
324      { typeof(FirstIndexMin), OpCodes.FirstIndexMin },
325      { typeof(LastIndexMax), OpCodes.LastIndexMax },
326      { typeof(LastIndexMin), OpCodes.LastIndexMin },
327      { typeof(LongestStrikeAboveMean), OpCodes.LongestStrikeAboveMean },
328      { typeof(LongestStrikeAboveMedian), OpCodes.LongestStrikeAboveMedian },
329      { typeof(LongestStrikeBelowMean), OpCodes.LongestStrikeBelowMean },
330      { typeof(LongestStrikeBelowMedian), OpCodes.LongestStrikeBelowMedian },
331      { typeof(LongestStrikePositive), OpCodes.LongestStrikePositive },
332      { typeof(LongestStrikeNegative), OpCodes.LongestStrikeNegative },
333      { typeof(LongestStrikeZero), OpCodes.LongestStrikeZero },
334      { typeof(MeanAbsoluteChange), OpCodes.MeanAbsoluteChange },
335      { typeof(MeanAbsoluteChangeQuantiles), OpCodes.MeanAbsoluteChangeQuantiles },
336      { typeof(MeanAutocorrelation), OpCodes.MeanAutocorrelation },
337      { typeof(LaggedAutocorrelation), OpCodes.LaggedAutocorrelation },
338      { typeof(MeanSecondDerivateCentral), OpCodes.MeanSecondDerivateCentral },
339      { typeof(NumberPeaksOfSize), OpCodes.NumberPeaksOfSize },
340      { typeof(LargeNumberOfPeaks), OpCodes.LargeNumberOfPeaks },
341      { typeof(TimeReversalAsymmetryStatistic), OpCodes.TimeReversalAsymmetryStatistic },
342      #endregion
343    };
344
345    public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
346      if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out byte opCode)) return opCode;
347      else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
348    }
349  }
350}
Note: See TracBrowser for help on using the repository browser.