Changeset 17367
- Timestamp:
- 11/22/19 16:31:11 (5 years ago)
- Location:
- branches/3040_VectorBasedGP
- Files:
-
- 4 edited
- 8 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17180 r17367 79 79 CubeRoot = 51, 80 80 Tanh = 52, 81 VectorVariable = 53, 82 VectorAdd = 54, 83 VectorSub = 55, 84 VectorMul = 56, 85 VectorDiv = 57, 86 VectorSum = 58, 87 VectorAvg = 59 81 88 }; 82 89 public static class OpCodes { 83 90 // constants for API compatibility only 84 91 public const byte Add = (byte)OpCode.Add; 85 public const byte Sub = (byte)OpCode.Sub;86 public const byte Mul = (byte)OpCode.Mul;87 public const byte Div = (byte)OpCode.Div;88 public const byte Sin = (byte)OpCode.Sin;89 public const byte Cos = (byte)OpCode.Cos;90 public const byte Tan = (byte)OpCode.Tan;91 public const byte Log = (byte)OpCode.Log;92 public const byte Sub = (byte)OpCode.Sub; 93 public const byte Mul = (byte)OpCode.Mul; 94 public const byte Div = (byte)OpCode.Div; 95 public const byte Sin = (byte)OpCode.Sin; 96 public const byte Cos = (byte)OpCode.Cos; 97 public const byte Tan = (byte)OpCode.Tan; 98 public const byte Log = (byte)OpCode.Log; 92 99 public const byte Exp = (byte)OpCode.Exp; 93 100 public const byte IfThenElse = (byte)OpCode.IfThenElse; … … 134 141 public const byte CubeRoot = (byte)OpCode.CubeRoot; 135 142 public const byte Tanh = (byte)OpCode.Tanh; 143 public const byte VectorVariable = (byte)OpCode.VectorVariable; 144 public const byte VectorAdd = (byte)OpCode.VectorAdd; 145 public const byte VectorSub = (byte)OpCode.VectorSub; 146 public const byte VectorMul = (byte)OpCode.VectorMul; 147 public const byte VectorDiv = (byte)OpCode.VectorDiv; 148 public const byte VectorSum = (byte)OpCode.VectorSum; 149 public const byte VectorAvg = (byte)OpCode.VectorAvg; 136 150 137 151 138 152 private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() { 139 153 { typeof(Addition), OpCodes.Add }, 140 154 { typeof(Subtraction), OpCodes.Sub }, 141 155 { typeof(Multiplication), OpCodes.Mul }, … … 189 203 { typeof(AnalyticQuotient), OpCodes.AnalyticQuotient }, 190 204 { typeof(Cube), OpCodes.Cube }, 191 { typeof(CubeRoot), OpCodes.CubeRoot } 205 { typeof(CubeRoot), OpCodes.CubeRoot }, 206 { typeof(VectorVariable), OpCodes.VectorVariable }, 207 { typeof(VectorAddition), OpCodes.VectorAdd }, 208 { typeof(VectorSubtraction), OpCodes.VectorSub }, 209 { typeof(VectorMultiplication), OpCodes.VectorMul }, 210 { typeof(VectorDivision), OpCodes.VectorDiv }, 211 { typeof(VectorSum), OpCodes.VectorSum }, 212 { typeof(VectorAverage), OpCodes.VectorAvg } 192 213 }; 193 214 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r17180 r17367 149 149 var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode; 150 150 instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName); 151 } else if (instr.opCode == OpCodes.VectorVariable) { 152 var vectorVariableTreeNode = (VectorVariableTreeNode)instr.dynamicNode; 153 instr.data = dataset.GetReadOnlyDoubleVectorValues(vectorVariableTreeNode.VariableName); 151 154 } else if (instr.opCode == OpCodes.LagVariable) { 152 155 var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode; … … 528 531 } 529 532 } 533 534 case OpCodes.VectorSum: { 535 DoubleVector v = VectorEvaluate(dataset, ref row, state); 536 return v.Sum(); 537 } 538 case OpCodes.VectorAvg: { 539 DoubleVector v = VectorEvaluate(dataset, ref row, state); 540 return v.Average(); 541 } 542 530 543 default: 531 544 throw new NotSupportedException(); 532 545 } 533 546 } 547 548 public virtual DoubleVector VectorEvaluate(IDataset dataset, ref int row, InterpreterState state) { 549 Instruction currentInstr = state.NextInstruction(); 550 switch (currentInstr.opCode) { 551 case OpCodes.VectorAdd: { 552 DoubleVector s = VectorEvaluate(dataset, ref row, state); 553 for (int i = 1; i < currentInstr.nArguments; i++) { 554 s += Evaluate(dataset, ref row, state); 555 } 556 return s; 557 } 558 case OpCodes.VectorSub: { 559 DoubleVector s = VectorEvaluate(dataset, ref row, state); 560 for (int i = 1; i < currentInstr.nArguments; i++) { 561 s -= Evaluate(dataset, ref row, state); 562 } 563 return s; 564 } 565 case OpCodes.VectorMul: { 566 DoubleVector s = VectorEvaluate(dataset, ref row, state); 567 for (int i = 1; i < currentInstr.nArguments; i++) { 568 s *= Evaluate(dataset, ref row, state); 569 } 570 return s; 571 } 572 case OpCodes.VectorDiv: { 573 DoubleVector s = VectorEvaluate(dataset, ref row, state); 574 for (int i = 1; i < currentInstr.nArguments; i++) { 575 s /= Evaluate(dataset, ref row, state); 576 } 577 return s; 578 } 579 580 case OpCodes.VectorVariable: { 581 if (row < 0 || row >= dataset.Rows) return new DoubleVector(new[] { double.NaN }); 582 var vectorVarTreeNode = currentInstr.dynamicNode as VectorVariableTreeNode; 583 return ((IList<DoubleVector>)currentInstr.data)[row] * vectorVarTreeNode.Weight; 584 } 585 default: 586 throw new NotSupportedException(); 587 } 588 } 534 589 } 535 590 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorAddition.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" 483AAB50-D2E9-472E-A2FA-625F621B7CA9")]28 [Item(" Addition", "Symbol that represents the + operator.")]29 public sealed class Addition : Symbol {27 [StorableType("FD0FD140-7AED-483F-ACFC-A65FFCD4216A")] 28 [Item("VectorAddition", "Symbol that represents the + operator.")] 29 public sealed class VectorAddition : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = byte.MaxValue; … … 39 39 40 40 [StorableConstructor] 41 private Addition(StorableConstructorFlag _) : base(_) { }42 private Addition(Addition original, Cloner cloner) : base(original, cloner) { }41 private VectorAddition(StorableConstructorFlag _) : base(_) { } 42 private VectorAddition(VectorAddition original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Addition(this, cloner);44 return new VectorAddition(this, cloner); 45 45 } 46 public Addition() : base("Addition", "Symbol that represents the + operator.") { }46 public VectorAddition() : base("VectorAddition", "Symbol that represents the + operator.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorAverage.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType("8 234F316-1816-41C5-94A9-11A5F3D36A77")]28 [Item(" Sine", "Symbol that represents the sine function.")]29 public sealed class Sine : Symbol {27 [StorableType("85FF9A2E-207C-4008-BB8B-0C0363885443")] 28 [Item("VectorAverage", "Symbol that represents the average function.")] 29 public sealed class VectorAverage : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = 1; … … 39 39 40 40 [StorableConstructor] 41 private Sine(StorableConstructorFlag _) : base(_) { }42 private Sine(Sine original, Cloner cloner) : base(original, cloner) { }41 private VectorAverage(StorableConstructorFlag _) : base(_) { } 42 private VectorAverage(VectorAverage original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Sine(this, cloner);44 return new VectorAverage(this, cloner); 45 45 } 46 public Sine() : base("Sine", "Symbol that represents the sine function.") { }46 public VectorAverage() : base("VectorAverage", "Symbol that represents the average function.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorDivision.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" EE4A9CF4-483A-4671-AEA2-03E3DAF2F976")]28 [Item(" Division", "Symbol that represents the / operator.")]29 public sealed class Division : Symbol {27 [StorableType("AC2706D7-40FF-4BB2-A7C9-1EE83EFF2D83")] 28 [Item("VectorDivision", "Symbol that represents the / operator.")] 29 public sealed class VectorDivision : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = byte.MaxValue; … … 39 39 40 40 [StorableConstructor] 41 private Division(StorableConstructorFlag _) : base(_) { }42 private Division(Division original, Cloner cloner) : base(original, cloner) { }41 private VectorDivision(StorableConstructorFlag _) : base(_) { } 42 private VectorDivision(VectorDivision original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Division(this, cloner);44 return new VectorDivision(this, cloner); 45 45 } 46 public Division() : base("Division", "Symbol that represents the / operator.") { }46 public VectorDivision() : base("VectorDivision", "Symbol that represents the / operator.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorMultiplication.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" 8F054D7F-82D0-400A-BAE3-8C90EA709C34")]28 [Item(" Multiplication", "Symbol that represents the * operator.")]29 public sealed class Multiplication : Symbol {27 [StorableType("B3CD0680-162D-49F6-9D23-0F8730704050")] 28 [Item("VectorMultiplication", "Symbol that represents the * operator.")] 29 public sealed class VectorMultiplication : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = byte.MaxValue; … … 39 39 40 40 [StorableConstructor] 41 private Multiplication(StorableConstructorFlag _) : base(_) { }42 private Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { }41 private VectorMultiplication(StorableConstructorFlag _) : base(_) { } 42 private VectorMultiplication(VectorMultiplication original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Multiplication(this, cloner);44 return new VectorMultiplication(this, cloner); 45 45 } 46 public Multiplication() : base("Multiplication", "Symbol that represents the * operator.") { }46 public VectorMultiplication() : base("VectorMultiplication", "Symbol that represents the * operator.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorSubtraction.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" F50263D4-2B07-42C8-8AB6-297A54AE00CC")]28 [Item(" Subtraction", "Symbol that represents the - operator.")]29 public sealed class Subtraction : Symbol {27 [StorableType("8700841D-3303-42E5-A71A-A941B4CF707E")] 28 [Item("VectorSubtraction", "Symbol that represents the - operator.")] 29 public sealed class VectorSubtraction : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = byte.MaxValue; … … 39 39 40 40 [StorableConstructor] 41 private Subtraction(StorableConstructorFlag _) : base(_) { }42 private Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { }41 private VectorSubtraction(StorableConstructorFlag _) : base(_) { } 42 private VectorSubtraction(VectorSubtraction original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Subtraction(this, cloner);44 return new VectorSubtraction(this, cloner); 45 45 } 46 public Subtraction() : base("Subtraction", "Symbol that represents the - operator.") { }46 public VectorSubtraction() : base("VectorSubtraction", "Symbol that represents the - operator.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorSum.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" 8234F316-1816-41C5-94A9-11A5F3D36A77")]28 [Item(" Sine", "Symbol that represents the sinefunction.")]29 public sealed class Sine: Symbol {27 [StorableType("FD700096-C848-4841-BAF3-B89C4200EE5C")] 28 [Item("VectorSum", "Symbol that represents the sum function.")] 29 public sealed class VectorSum : Symbol { 30 30 private const int minimumArity = 1; 31 31 private const int maximumArity = 1; … … 39 39 40 40 [StorableConstructor] 41 private Sine(StorableConstructorFlag _) : base(_) { }42 private Sine(Sineoriginal, Cloner cloner) : base(original, cloner) { }41 private VectorSum(StorableConstructorFlag _) : base(_) { } 42 private VectorSum(VectorSum original, Cloner cloner) : base(original, cloner) { } 43 43 public override IDeepCloneable Clone(Cloner cloner) { 44 return new Sine(this, cloner);44 return new VectorSum(this, cloner); 45 45 } 46 public Sine() : base("Sine", "Symbol that represents the sinefunction.") { }46 public VectorSum() : base("VectorSum", "Symbol that represents the sum function.") { } 47 47 } 48 48 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorVariable.cs
r17362 r17367 25 25 using HEAL.Attic; 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 [StorableType(" 9072AE0E-FA62-48D2-A416-F678D6CC2CBC")]27 [StorableType("B7E7393D-95BC-434D-862C-670C9FCF8328")] 28 28 [Item("Variable", "Represents a variable value.")] 29 public sealed class V ariable : VariableBase {29 public sealed class VectorVariable : VariableBase { 30 30 31 31 [StorableConstructor] 32 private V ariable(StorableConstructorFlag _) : base(_) {32 private VectorVariable(StorableConstructorFlag _) : base(_) { 33 33 } 34 private V ariable(Variable original, Cloner cloner)34 private VectorVariable(Variable original, Cloner cloner) 35 35 : base(original, cloner) { 36 36 } 37 public V ariable() : base("Variable", "Represents a variable value.") { }38 public V ariable(string name, string description) : base(name, description) { }37 public VectorVariable() : base("VectorVariable", "Represents a variable value.") { } 38 public VectorVariable(string name, string description) : base(name, description) { } 39 39 40 40 public override ISymbolicExpressionTreeNode CreateTreeNode() { 41 return new V ariableTreeNode(this);41 return new VectorVariableTreeNode(this); 42 42 } 43 43 44 44 public override IDeepCloneable Clone(Cloner cloner) { 45 return new V ariable(this, cloner);45 return new VectorVariable(this, cloner); 46 46 } 47 47 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VectorVariableTreeNode.cs
r17362 r17367 23 23 using HEAL.Attic; 24 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 25 [StorableType(" E60C4216-A6BA-48DE-BA66-389B9946B70A")]26 public sealed class V ariableTreeNode : VariableTreeNodeBase {27 public new V ariable Symbol {28 get { return (V ariable)base.Symbol; }25 [StorableType("C0C60572-E014-43D5-B06C-53F3DE6FD54A")] 26 public sealed class VectorVariableTreeNode : VariableTreeNodeBase { 27 public new VectorVariable Symbol { 28 get { return (VectorVariable)base.Symbol; } 29 29 } 30 30 [StorableConstructor] 31 private V ariableTreeNode(StorableConstructorFlag _) : base(_) { }32 private V ariableTreeNode(VariableTreeNode original, Cloner cloner)31 private VectorVariableTreeNode(StorableConstructorFlag _) : base(_) { } 32 private VectorVariableTreeNode(VectorVariableTreeNode original, Cloner cloner) 33 33 : base(original, cloner) { 34 34 } 35 private V ariableTreeNode() { }36 public V ariableTreeNode(Variable variableSymbol) : base(variableSymbol) { }35 private VectorVariableTreeNode() { } 36 public VectorVariableTreeNode(VectorVariable variableSymbol) : base(variableSymbol) { } 37 37 38 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new V ariableTreeNode(this, cloner);39 return new VectorVariableTreeNode(this, cloner); 40 40 } 41 41 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/DoubleVector.cs
r17365 r17367 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Windows.Markup; 23 26 using HEAL.Attic; 24 27 … … 35 38 : base(_) { } 36 39 40 public static DoubleVector operator +(DoubleVector lhs, DoubleVector rhs) { 41 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l + r)); 42 } 43 public static DoubleVector operator -(DoubleVector lhs, DoubleVector rhs) { 44 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l - r)); 45 } 46 public static DoubleVector operator *(DoubleVector lhs, DoubleVector rhs) { 47 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l * r)); 48 } 49 public static DoubleVector operator /(DoubleVector lhs, DoubleVector rhs) { 50 return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l / r)); 51 } 52 private static IEnumerable<double> VecCalc(IReadOnlyList<double> lhs, IReadOnlyList<double> rhs, Func<double, double, double> resultFunc) { 53 if (lhs.Count != rhs.Count) throw new InvalidOperationException("Vectors are not of equal length."); 54 return lhs.Zip(rhs, resultFunc); 55 } 56 57 public static DoubleVector operator +(DoubleVector lhs, double rhs) { 58 return new DoubleVector(lhs.Select(l => l + rhs)); 59 } 60 public static DoubleVector operator -(DoubleVector lhs, double rhs) { 61 return new DoubleVector(lhs.Select(l => l - rhs)); 62 } 63 public static DoubleVector operator *(DoubleVector lhs, double rhs) { 64 return new DoubleVector(lhs.Select(l => l * rhs)); 65 } 66 public static DoubleVector operator /(DoubleVector lhs, double rhs) { 67 return new DoubleVector(lhs.Select(l => l / rhs)); 68 } 69 70 public double Sum() { 71 return values.Sum(); 72 } 73 74 public double Average() { 75 return values.Average(); 76 } 37 77 } 38 78 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/Vector.cs
r17365 r17367 28 28 [StorableType("3574E222-1167-4F1B-93D2-01B15A7F1E84")] 29 29 public abstract class Vector<T> : IVector<T> { 30 private readonly List<T> values; 30 [Storable] 31 protected readonly List<T> values; 31 32 32 33 protected Vector(IEnumerable<T> values) {
Note: See TracChangeset
for help on using the changeset viewer.