#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
public enum OpCode : byte {
Add = 1,
Sub = 2,
Mul = 3,
Div = 4,
Sin = 5,
Cos = 6,
Tan = 7,
Log = 8,
Exp = 9,
IfThenElse = 10,
GT = 11,
LT = 12,
AND = 13,
OR = 14,
NOT = 15,
Average = 16,
Call = 17,
Variable = 18,
LagVariable = 19,
Constant = 20,
Arg = 21,
Power = 22,
Root = 23,
TimeLag = 24,
Integral = 25,
Derivative = 26,
VariableCondition = 27,
Square = 28,
SquareRoot = 29,
Gamma = 30,
Psi = 31,
Dawson = 32,
ExponentialIntegralEi = 33,
CosineIntegral = 34,
SineIntegral = 35,
HyperbolicCosineIntegral = 36,
HyperbolicSineIntegral = 37,
FresnelCosineIntegral = 38,
FresnelSineIntegral = 39,
AiryA = 40,
AiryB = 41,
Norm = 42,
Erf = 43,
Bessel = 44,
XOR = 45,
FactorVariable = 46,
BinaryFactorVariable = 47,
Absolute = 48,
AnalyticQuotient = 49,
Cube = 50,
CubeRoot = 51,
Tanh = 52,
Mean = 53,
StandardDeviation = 54,
Sum = 55,
Length = 56,
Min = 57,
Max = 58,
Variance = 59,
Skewness = 60,
Kurtosis = 61,
EuclideanDistance = 62,
Covariance = 63,
SubVector = 64,
SubVectorSubtree = 65,
#region Time Series Symbols
Median = 100,
Quantile = 101,
AbsoluteEnergy = 102,
BinnedEntropy = 103,
HasLargeStandardDeviation = 104,
HasVarianceLargerThanStd = 105,
IsSymmetricLooking = 106,
NumberDataPointsAboveMean = 107,
NumberDataPointsAboveMedian = 108,
NumberDataPointsBelowMean = 109,
NumberDataPointsBelowMedian = 110,
ArimaModelCoefficients = 111,
ContinuousWaveletTransformationCoefficients = 112,
FastFourierTransformationCoefficient = 113,
FirstIndexMax = 124,
FirstIndexMin = 125,
LastIndexMax = 126,
LastIndexMin = 127,
LongestStrikeAboveMean = 128,
LongestStrikeAboveMedian = 129,
LongestStrikeBelowMean = 130,
LongestStrikeBelowMedian = 131,
LongestStrikePositive = 132,
LongestStrikeNegative = 133,
LongestStrikeZero = 134,
MeanAbsoluteChange = 135,
MeanAbsoluteChangeQuantiles = 136,
MeanAutocorrelation = 137,
LaggedAutocorrelation = 138,
MeanSecondDerivateCentral = 139,
NumberPeaksOfSize = 140,
LargeNumberOfPeaks = 141,
TimeReversalAsymmetryStatistic = 142
#endregion
}
public static class OpCodes {
// constants for API compatibility only
public const byte Add = (byte)OpCode.Add;
public const byte Sub = (byte)OpCode.Sub;
public const byte Mul = (byte)OpCode.Mul;
public const byte Div = (byte)OpCode.Div;
public const byte Sin = (byte)OpCode.Sin;
public const byte Cos = (byte)OpCode.Cos;
public const byte Tan = (byte)OpCode.Tan;
public const byte Log = (byte)OpCode.Log;
public const byte Exp = (byte)OpCode.Exp;
public const byte IfThenElse = (byte)OpCode.IfThenElse;
public const byte GT = (byte)OpCode.GT;
public const byte LT = (byte)OpCode.LT;
public const byte AND = (byte)OpCode.AND;
public const byte OR = (byte)OpCode.OR;
public const byte NOT = (byte)OpCode.NOT;
public const byte Average = (byte)OpCode.Average;
public const byte Call = (byte)OpCode.Call;
public const byte Variable = (byte)OpCode.Variable;
public const byte LagVariable = (byte)OpCode.LagVariable;
public const byte Constant = (byte)OpCode.Constant;
public const byte Arg = (byte)OpCode.Arg;
public const byte Power = (byte)OpCode.Power;
public const byte Root = (byte)OpCode.Root;
public const byte TimeLag = (byte)OpCode.TimeLag;
public const byte Integral = (byte)OpCode.Integral;
public const byte Derivative = (byte)OpCode.Derivative;
public const byte VariableCondition = (byte)OpCode.VariableCondition;
public const byte Square = (byte)OpCode.Square;
public const byte SquareRoot = (byte)OpCode.SquareRoot;
public const byte Gamma = (byte)OpCode.Gamma;
public const byte Psi = (byte)OpCode.Psi;
public const byte Dawson = (byte)OpCode.Dawson;
public const byte ExponentialIntegralEi = (byte)OpCode.ExponentialIntegralEi;
public const byte CosineIntegral = (byte)OpCode.CosineIntegral;
public const byte SineIntegral = (byte)OpCode.SineIntegral;
public const byte HyperbolicCosineIntegral = (byte)OpCode.HyperbolicCosineIntegral;
public const byte HyperbolicSineIntegral = (byte)OpCode.HyperbolicSineIntegral;
public const byte FresnelCosineIntegral = (byte)OpCode.FresnelCosineIntegral;
public const byte FresnelSineIntegral = (byte)OpCode.FresnelSineIntegral;
public const byte AiryA = (byte)OpCode.AiryA;
public const byte AiryB = (byte)OpCode.AiryB;
public const byte Norm = (byte)OpCode.Norm;
public const byte Erf = (byte)OpCode.Erf;
public const byte Bessel = (byte)OpCode.Bessel;
public const byte XOR = (byte)OpCode.XOR;
public const byte FactorVariable = (byte)OpCode.FactorVariable;
public const byte BinaryFactorVariable = (byte)OpCode.BinaryFactorVariable;
public const byte Absolute = (byte)OpCode.Absolute;
public const byte AnalyticQuotient = (byte)OpCode.AnalyticQuotient;
public const byte Cube = (byte)OpCode.Cube;
public const byte CubeRoot = (byte)OpCode.CubeRoot;
public const byte Tanh = (byte)OpCode.Tanh;
public const byte Mean = (byte)OpCode.Mean;
public const byte StandardDeviation = (byte)OpCode.StandardDeviation;
public const byte Sum = (byte)OpCode.Sum;
public const byte Length = (byte)OpCode.Length;
public const byte Min = (byte)OpCode.Min;
public const byte Max = (byte)OpCode.Max;
public const byte Variance = (byte)OpCode.Variance;
public const byte Skewness = (byte)OpCode.Skewness;
public const byte Kurtosis = (byte)OpCode.Kurtosis;
public const byte EuclideanDistance = (byte)OpCode.EuclideanDistance;
public const byte Covariance = (byte)OpCode.Covariance;
public const byte SubVector = (byte)OpCode.SubVector;
public const byte SubVectorSubtree = (byte)OpCode.SubVectorSubtree;
#region Time Series Symbols
public const byte Median = (byte)OpCode.Median;
public const byte Quantile = (byte)OpCode.Quantile;
public const byte AbsoluteEnergy = (byte)OpCode.AbsoluteEnergy;
public const byte BinnedEntropy = (byte)OpCode.BinnedEntropy;
public const byte HasLargeStandardDeviation = (byte)OpCode.HasLargeStandardDeviation;
public const byte HasVarianceLargerThanStd = (byte)OpCode.HasVarianceLargerThanStd;
public const byte IsSymmetricLooking = (byte)OpCode.IsSymmetricLooking;
public const byte NumberDataPointsAboveMean = (byte)OpCode.NumberDataPointsAboveMean;
public const byte NumberDataPointsAboveMedian = (byte)OpCode.NumberDataPointsAboveMedian;
public const byte NumberDataPointsBelowMean = (byte)OpCode.NumberDataPointsBelowMean;
public const byte NumberDataPointsBelowMedian = (byte)OpCode.NumberDataPointsBelowMedian;
public const byte ArimaModelCoefficients = (byte)OpCode.ArimaModelCoefficients;
public const byte ContinuousWaveletTransformationCoefficients = (byte)OpCode.ContinuousWaveletTransformationCoefficients;
public const byte FastFourierTransformationCoefficient = (byte)OpCode.FastFourierTransformationCoefficient;
public const byte FirstIndexMax = (byte)OpCode.FirstIndexMax;
public const byte FirstIndexMin = (byte)OpCode.FirstIndexMin;
public const byte LastIndexMax = (byte)OpCode.LastIndexMax;
public const byte LastIndexMin = (byte)OpCode.LastIndexMin;
public const byte LongestStrikeAboveMean = (byte)OpCode.LongestStrikeAboveMean;
public const byte LongestStrikeAboveMedian = (byte)OpCode.LongestStrikeAboveMedian;
public const byte LongestStrikeBelowMean = (byte)OpCode.LongestStrikeBelowMean;
public const byte LongestStrikeBelowMedian = (byte)OpCode.LongestStrikeBelowMedian;
public const byte LongestStrikePositive = (byte)OpCode.LongestStrikePositive;
public const byte LongestStrikeNegative = (byte)OpCode.LongestStrikeNegative;
public const byte LongestStrikeZero = (byte)OpCode.LongestStrikeZero;
public const byte MeanAbsoluteChange = (byte)OpCode.MeanAbsoluteChange;
public const byte MeanAbsoluteChangeQuantiles = (byte)OpCode.MeanAbsoluteChangeQuantiles;
public const byte MeanAutocorrelation = (byte)OpCode.MeanAutocorrelation;
public const byte LaggedAutocorrelation = (byte)OpCode.LaggedAutocorrelation;
public const byte MeanSecondDerivateCentral = (byte)OpCode.MeanSecondDerivateCentral;
public const byte NumberPeaksOfSize = (byte)OpCode.NumberPeaksOfSize;
public const byte LargeNumberOfPeaks = (byte)OpCode.LargeNumberOfPeaks;
public const byte TimeReversalAsymmetryStatistic = (byte)OpCode.TimeReversalAsymmetryStatistic;
#endregion
private static Dictionary symbolToOpcode = new Dictionary() {
{ typeof(Addition), OpCodes.Add },
{ typeof(Subtraction), OpCodes.Sub },
{ typeof(Multiplication), OpCodes.Mul },
{ typeof(Division), OpCodes.Div },
{ typeof(Sine), OpCodes.Sin },
{ typeof(Cosine), OpCodes.Cos },
{ typeof(Tangent), OpCodes.Tan },
{ typeof (HyperbolicTangent), OpCodes.Tanh},
{ typeof(Logarithm), OpCodes.Log },
{ typeof(Exponential), OpCodes.Exp },
{ typeof(IfThenElse), OpCodes.IfThenElse },
{ typeof(GreaterThan), OpCodes.GT },
{ typeof(LessThan), OpCodes.LT },
{ typeof(And), OpCodes.AND },
{ typeof(Or), OpCodes.OR },
{ typeof(Not), OpCodes.NOT},
{ typeof(Xor),OpCodes.XOR},
{ typeof(Average), OpCodes.Average},
{ typeof(InvokeFunction), OpCodes.Call },
{ typeof(Variable), OpCodes.Variable },
{ typeof(LaggedVariable), OpCodes.LagVariable },
{ typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
{ typeof(Constant), OpCodes.Constant },
{ typeof(Argument), OpCodes.Arg },
{ typeof(Power),OpCodes.Power},
{ typeof(Root),OpCodes.Root},
{ typeof(TimeLag), OpCodes.TimeLag},
{ typeof(Integral), OpCodes.Integral},
{ typeof(Derivative), OpCodes.Derivative},
{ typeof(VariableCondition),OpCodes.VariableCondition},
{ typeof(Square),OpCodes.Square},
{ typeof(SquareRoot),OpCodes.SquareRoot},
{ typeof(Gamma), OpCodes.Gamma },
{ typeof(Psi), OpCodes.Psi },
{ typeof(Dawson), OpCodes.Dawson},
{ typeof(ExponentialIntegralEi), OpCodes.ExponentialIntegralEi },
{ typeof(CosineIntegral), OpCodes.CosineIntegral },
{ typeof(SineIntegral), OpCodes.SineIntegral },
{ typeof(HyperbolicCosineIntegral), OpCodes.HyperbolicCosineIntegral },
{ typeof(HyperbolicSineIntegral), OpCodes.HyperbolicSineIntegral },
{ typeof(FresnelCosineIntegral), OpCodes.FresnelCosineIntegral },
{ typeof(FresnelSineIntegral), OpCodes.FresnelSineIntegral },
{ typeof(AiryA), OpCodes.AiryA },
{ typeof(AiryB), OpCodes.AiryB },
{ typeof(Norm), OpCodes.Norm},
{ typeof(Erf), OpCodes.Erf},
{ typeof(Bessel), OpCodes.Bessel},
{ typeof(FactorVariable), OpCodes.FactorVariable },
{ typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
{ typeof(Absolute), OpCodes.Absolute },
{ typeof(AnalyticQuotient), OpCodes.AnalyticQuotient },
{ typeof(Cube), OpCodes.Cube },
{ typeof(CubeRoot), OpCodes.CubeRoot },
{ typeof(Mean), OpCodes.Mean },
{ typeof(StandardDeviation), OpCodes.StandardDeviation },
{ typeof(Sum), OpCodes.Sum },
{ typeof(Length), OpCodes.Length },
{ typeof(Min), OpCodes.Min },
{ typeof(Max), OpCodes.Max },
{ typeof(Variance), OpCodes.Variance },
{ typeof(Skewness), OpCodes.Skewness },
{ typeof(Kurtosis), OpCodes.Kurtosis },
{ typeof(EuclideanDistance), OpCodes.EuclideanDistance },
{ typeof(Covariance), OpCodes.Covariance },
{ typeof(SubVector), OpCodes.SubVector },
{ typeof(SubVectorSubtree), OpCodes.SubVectorSubtree },
#region Time Series Symbols
{ typeof(Median), OpCodes.Median },
{ typeof(Quantile), OpCodes.Quantile },
{ typeof(AbsoluteEnergy), OpCodes.AbsoluteEnergy },
{ typeof(BinnedEntropy), OpCodes.BinnedEntropy },
{ typeof(HasLargeStandardDeviation), OpCodes.HasLargeStandardDeviation },
{ typeof(HasVarianceLargerThanStd), OpCodes.HasVarianceLargerThanStd },
{ typeof(IsSymmetricLooking), OpCodes.IsSymmetricLooking },
{ typeof(NumberDataPointsAboveMean), OpCodes.NumberDataPointsAboveMean },
{ typeof(NumberDataPointsAboveMedian), OpCodes.NumberDataPointsAboveMedian },
{ typeof(NumberDataPointsBelowMean), OpCodes.NumberDataPointsBelowMean },
{ typeof(NumberDataPointsBelowMedian), OpCodes.NumberDataPointsBelowMedian },
{ typeof(ArimaModelCoefficients), OpCodes.ArimaModelCoefficients },
{ typeof(ContinuousWaveletTransformationCoefficients), OpCodes.ContinuousWaveletTransformationCoefficients },
{ typeof(FastFourierTransformationCoefficient), OpCodes.FastFourierTransformationCoefficient },
{ typeof(FirstIndexMax), OpCodes.FirstIndexMax },
{ typeof(FirstIndexMin), OpCodes.FirstIndexMin },
{ typeof(LastIndexMax), OpCodes.LastIndexMax },
{ typeof(LastIndexMin), OpCodes.LastIndexMin },
{ typeof(LongestStrikeAboveMean), OpCodes.LongestStrikeAboveMean },
{ typeof(LongestStrikeAboveMedian), OpCodes.LongestStrikeAboveMedian },
{ typeof(LongestStrikeBelowMean), OpCodes.LongestStrikeBelowMean },
{ typeof(LongestStrikeBelowMedian), OpCodes.LongestStrikeBelowMedian },
{ typeof(LongestStrikePositive), OpCodes.LongestStrikePositive },
{ typeof(LongestStrikeNegative), OpCodes.LongestStrikeNegative },
{ typeof(LongestStrikeZero), OpCodes.LongestStrikeZero },
{ typeof(MeanAbsoluteChange), OpCodes.MeanAbsoluteChange },
{ typeof(MeanAbsoluteChangeQuantiles), OpCodes.MeanAbsoluteChangeQuantiles },
{ typeof(MeanAutocorrelation), OpCodes.MeanAutocorrelation },
{ typeof(LaggedAutocorrelation), OpCodes.LaggedAutocorrelation },
{ typeof(MeanSecondDerivateCentral), OpCodes.MeanSecondDerivateCentral },
{ typeof(NumberPeaksOfSize), OpCodes.NumberPeaksOfSize },
{ typeof(LargeNumberOfPeaks), OpCodes.LargeNumberOfPeaks },
{ typeof(TimeReversalAsymmetryStatistic), OpCodes.TimeReversalAsymmetryStatistic },
#endregion
};
public static byte MapSymbolToOpCode(ISymbolicExpressionTreeNode treeNode) {
if (symbolToOpcode.TryGetValue(treeNode.Symbol.GetType(), out byte opCode)) return opCode;
else throw new NotSupportedException("Symbol: " + treeNode.Symbol);
}
}
}