Changeset 17460 for branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalVectorExpressionGrammar.cs
- Timestamp:
- 02/28/20 14:55:58 (5 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalVectorExpressionGrammar.cs
r17456 r17460 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 [StorableType(" 44B0829C-1CB5-4BE9-9514-BBA54FAB2912")]31 [Item("FullFunctional ExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]32 public class FullFunctional ExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar {31 [StorableType("C913F5C6-AF16-4F2C-BA93-2D5AE1F8E68A")] 32 [Item("FullFunctionalVectorExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 33 public class FullFunctionalVectorExpressionGrammar : DataAnalysisGrammar, ISymbolicDataAnalysisGrammar { 33 34 [StorableConstructor] 34 protected FullFunctional ExpressionGrammar(StorableConstructorFlag _) : base(_) { }35 protected FullFunctional ExpressionGrammar(FullFunctionalExpressionGrammar original, Cloner cloner) : base(original, cloner) { }36 public FullFunctional ExpressionGrammar()37 : base(ItemAttribute.GetName(typeof(FullFunctional ExpressionGrammar)), ItemAttribute.GetDescription(typeof(FullFunctionalExpressionGrammar))) {35 protected FullFunctionalVectorExpressionGrammar(StorableConstructorFlag _) : base(_) { } 36 protected FullFunctionalVectorExpressionGrammar(FullFunctionalVectorExpressionGrammar original, Cloner cloner) : base(original, cloner) { } 37 public FullFunctionalVectorExpressionGrammar() 38 : base(ItemAttribute.GetName(typeof(FullFunctionalVectorExpressionGrammar)), ItemAttribute.GetDescription(typeof(FullFunctionalVectorExpressionGrammar))) { 38 39 Initialize(); 39 40 } 40 41 41 42 public override IDeepCloneable Clone(Cloner cloner) { 42 return new FullFunctional ExpressionGrammar(this, cloner);43 return new FullFunctionalVectorExpressionGrammar(this, cloner); 43 44 } 44 45 … … 48 49 var mul = new Multiplication(); 49 50 var div = new Division(); 50 var aq = new AnalyticQuotient(); 51 var mean = new Average(); 51 52 52 var sin = new Sine(); 53 53 var cos = new Cosine(); 54 54 var tan = new Tangent(); 55 55 56 var log = new Logarithm(); 56 var abs = new Absolute(); 57 var tanh = new HyperbolicTangent(); 58 var pow = new Power(); 59 pow.InitialFrequency = 0.0; 60 var square = new Square(); 61 square.InitialFrequency = 0.0; 62 var cube = new Cube(); 63 cube.InitialFrequency = 0.0; 64 var root = new Root(); 65 root.InitialFrequency = 0.0; 66 var sqrt = new SquareRoot(); 67 sqrt.InitialFrequency = 0.0; 68 var cubeRoot = new CubeRoot(); 69 cubeRoot.InitialFrequency = 0.0; 70 var airyA = new AiryA(); 71 airyA.InitialFrequency = 0.0; 72 var airyB = new AiryB(); 73 airyB.InitialFrequency = 0.0; 74 var bessel = new Bessel(); 75 bessel.InitialFrequency = 0.0; 76 var cosineIntegral = new CosineIntegral(); 77 cosineIntegral.InitialFrequency = 0.0; 78 var dawson = new Dawson(); 79 dawson.InitialFrequency = 0.0; 80 var erf = new Erf(); 81 erf.InitialFrequency = 0.0; 82 var expIntegralEi = new ExponentialIntegralEi(); 83 expIntegralEi.InitialFrequency = 0.0; 84 var fresnelCosineIntegral = new FresnelCosineIntegral(); 85 fresnelCosineIntegral.InitialFrequency = 0.0; 86 var fresnelSineIntegral = new FresnelSineIntegral(); 87 fresnelSineIntegral.InitialFrequency = 0.0; 88 var gamma = new Gamma(); 89 gamma.InitialFrequency = 0.0; 90 var hypCosineIntegral = new HyperbolicCosineIntegral(); 91 hypCosineIntegral.InitialFrequency = 0.0; 92 var hypSineIntegral = new HyperbolicSineIntegral(); 93 hypSineIntegral.InitialFrequency = 0.0; 94 var norm = new Norm(); 95 norm.InitialFrequency = 0.0; 96 var psi = new Psi(); 97 psi.InitialFrequency = 0.0; 98 var sineIntegral = new SineIntegral(); 99 sineIntegral.InitialFrequency = 0.0; 57 var exp = new Exponential(); 100 58 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();108 var xor = new Xor();109 59 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;60 var pow = new Power { InitialFrequency = 0.0 }; 61 var root = new Root { InitialFrequency = 0.0 }; 62 var square = new Square { InitialFrequency = 0.0 }; 63 var sqrt = new SquareRoot { InitialFrequency = 0.0 }; 64 var cube = new Cube { InitialFrequency = 0.0 }; 65 var cubeRoot = new CubeRoot { InitialFrequency = 0.0 }; 116 66 117 var variableCondition = new VariableCondition(); 118 variableCondition.InitialFrequency = 0.0; 119 120 var constant = new Constant(); 121 constant.MinValue = -20; 122 constant.MaxValue = 20; 123 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 67 var constant = new Constant { MinValue = -20, MaxValue = 20 }; 68 var variable = new Variable(); 124 69 var binFactorVariable = new BinaryFactorVariable(); 125 70 var factorVariable = new FactorVariable(); 126 var laggedVariable = new LaggedVariable(); 127 laggedVariable.InitialFrequency = 0.0; 128 var autoregressiveVariable = new AutoregressiveTargetVariable(); 129 autoregressiveVariable.InitialFrequency = 0.0; 130 autoregressiveVariable.Enabled = false; 71 var vectorVariable = new Variable() { Name = "Vector Variable" }; 131 72 132 var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, tanh, 133 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 134 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition }; 135 var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, tanh, not, timeLag, integral, derivative, 136 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral 73 var sum = new Sum(); 74 var mean = new Average() { Name = "Mean" }; 75 76 77 var allSymbols = new List<Symbol>() { 78 add, sub, mul, div, 79 sin, cos, tan, 80 log, exp, 81 square, sqrt, cube, cubeRoot, pow, root, 82 constant, variable, binFactorVariable, factorVariable, vectorVariable, 83 sum, mean 84 }; 85 var unaryFunctionSymbols = new List<Symbol>() { 86 sin, cos, tan, 87 log, exp 137 88 }; 138 89 139 var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition }; 140 var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor }; 141 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, laggedVariable, autoregressiveVariable }; 90 var binaryFunctionSymbols = new List<Symbol>() { pow, root }; 91 var ternarySymbols = new List<Symbol>() { add, sub, mul, div }; 92 var terminalSymbols = new List<Symbol>() { variable, binFactorVariable, factorVariable, vectorVariable, constant }; 93 94 var aggregationSymbols = new List<Symbol>() { sum, mean }; 142 95 143 96 foreach (var symb in allSymbols) … … 156 109 SetSubtreeCount(terminalSymbol, 0, 0); 157 110 } 158 159 SetSubtreeCount(@if, 3, 3); 111 foreach (var aggrSymb in aggregationSymbols) { 112 SetSubtreeCount(aggrSymb, 1, 1); 113 } 160 114 161 115 … … 172 126 } 173 127 } 128 129 public override void ConfigureVariableSymbols(IDataAnalysisProblemData problemData) { 130 base.ConfigureVariableSymbols(problemData); 131 132 var dataset = problemData.Dataset; 133 foreach (var varSymbol in Symbols.OfType<VariableBase>().Where(sym => sym.Name == "Variable")) { 134 if (!varSymbol.Fixed) { 135 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<double>(x)); 136 varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<double>(x)); 137 } 138 } 139 foreach (var varSymbol in Symbols.OfType<VariableBase>().Where(sym => sym.Name == "Vector Variable")) { 140 if (!varSymbol.Fixed) { 141 varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<DoubleVector>(x)); 142 varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<DoubleVector>(x)); 143 } 144 } 145 } 174 146 } 175 147 }
Note: See TracChangeset
for help on using the changeset viewer.