Changeset 18060
- Timestamp:
- 09/28/21 13:37:43 (3 years ago)
- Location:
- branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/VectorTreeSimplifier.cs
r17629 r18060 66 66 private static readonly StandardDeviation standardDeviationSymbol = new StandardDeviation(); 67 67 private static readonly Variance varianceSymbol = new Variance(); 68 private static readonly Min minSymbol = new Min(); 69 private static readonly Max maxSymbol = new Max(); 68 70 69 71 private readonly SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter; … … 281 283 private static bool IsVariance(ISymbolicExpressionTreeNode node) { 282 284 return node.Symbol is Variance; 285 } 286 287 private static bool IsMin(ISymbolicExpressionTreeNode node) { 288 return node.Symbol is Min; 289 } 290 291 private static bool IsMax(ISymbolicExpressionTreeNode node) { 292 return node.Symbol is Max; 283 293 } 284 294 #endregion … … 363 373 } else if (IsVariance(original)) { 364 374 return SimplifyVarianceAggregation(original); 375 } else if (IsMin(original)) { 376 return SimplifyMinAggregation(original); 377 } else if (IsMax(original)) { 378 return SimplifyMaxAggregation(original); 365 379 } else { 366 380 return SimplifyAny(original); … … 574 588 private ISymbolicExpressionTreeNode SimplifyVarianceAggregation(ISymbolicExpressionTreeNode original) { 575 589 return MakeVarianceAggregation(GetSimplifiedTree(original.GetSubtree(0))); 590 } 591 592 private ISymbolicExpressionTreeNode SimplifyMinAggregation(ISymbolicExpressionTreeNode original) { 593 return MakeMinAggregation(GetSimplifiedTree(original.GetSubtree(0))); 594 } 595 596 private ISymbolicExpressionTreeNode SimplifyMaxAggregation(ISymbolicExpressionTreeNode original) { 597 return MakeMaxAggregation(GetSimplifiedTree(original.GetSubtree(0))); 576 598 } 577 599 #endregion … … 1508 1530 }); 1509 1531 } 1532 1533 private ISymbolicExpressionTreeNode MakeMinAggregation(ISymbolicExpressionTreeNode node) { 1534 return MakeAggregation(node, meanSymbol, 1535 simplifyScalar: n => n, 1536 simplifyAdditiveTerms: (vectorNode, scalarNode) => { 1537 var minNode = MakeMinAggregation(vectorNode); 1538 return MakeSum(scalarNode, minNode); 1539 }, 1540 simplifyMultiplicativeFactors: (vectorNode, scalarNode) => { 1541 var minNode = MakeMinAggregation(vectorNode); 1542 return MakeProduct(scalarNode, minNode); 1543 }); 1544 } 1545 1546 private ISymbolicExpressionTreeNode MakeMaxAggregation(ISymbolicExpressionTreeNode node) { 1547 return MakeAggregation(node, meanSymbol, 1548 simplifyScalar: n => n, 1549 simplifyAdditiveTerms: (vectorNode, scalarNode) => { 1550 var maxNode = MakeMaxAggregation(vectorNode); 1551 return MakeSum(scalarNode, maxNode); 1552 }, 1553 simplifyMultiplicativeFactors: (vectorNode, scalarNode) => { 1554 var maxNode = MakeMaxAggregation(vectorNode); 1555 return MakeProduct(scalarNode, maxNode); 1556 }); 1557 } 1510 1558 #endregion 1511 1559 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentVectorExpressionGrammar.cs
r17752 r18060 50 50 51 51 private const string VectorManipulationSymbolsName = "Vector Manipulation Symbols"; 52 private const string VectorSubVectorSymbolsName = "Vector SubVector Symbols"; 52 53 53 54 private const string RealValuedSymbolsName = "Real Valued Symbols"; … … 127 128 128 129 #region vector manipulation symbol declaration 129 var subvector = new SubVector() { EnableWindowing = true }; 130 var subvectorLocal = new SubVector(); 131 var subvectorSubtree = new SubVectorSubtree(); 130 132 #endregion 131 133 … … 148 150 var vectorSymbols = new GroupSymbol(VectorSymbolsName, new List<ISymbol>() { vectorarithmeticSymbols, vectortrigonometricSymbols, vectorexponentialAndLogarithmicSymbols, vectorpowerSymbols, vectorterminalSymbols }); 149 151 150 var vectorManipulationSymbols = new GroupSymbol(VectorManipulationSymbolsName, new List<ISymbol>() { subvector }); 152 var vectorSubVectorSymbols = new GroupSymbol(VectorSubVectorSymbolsName, new List<ISymbol>() { subvectorLocal, subvectorSubtree }); 153 var vectorManipulationSymbols = new GroupSymbol(VectorManipulationSymbolsName, new List<ISymbol>() { vectorSubVectorSymbols }); 154 151 155 152 156 //var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol> { scalarSymbols, vectorSymbols }); … … 185 189 SetSubtreeCount(vectorterminalSymbols, 0, 0); 186 190 187 SetSubtreeCount(subvector, 1, 1); 191 SetSubtreeCount(subvectorLocal, 1, 1); 192 SetSubtreeCount(subvectorSubtree, 3, 3); 188 193 #endregion 189 194 … … 198 203 AddAllowedChildSymbol(root, constant, 1); 199 204 AddAllowedChildSymbol(aggregationSymbols, vectorSymbols); 200 AddAllowedChildSymbol(statisticsSymbols, subvector);205 AddAllowedChildSymbol(statisticsSymbols, vectorSubVectorSymbols); 201 206 202 207 AddAllowedChildSymbol(vectorarithmeticSymbols, vectorSymbols); … … 208 213 AddAllowedChildSymbol(vectorroot, constant, 1); 209 214 210 AddAllowedChildSymbol(subvector, vectorSymbols); 215 AddAllowedChildSymbol(subvectorLocal, vectorSymbols); 216 AddAllowedChildSymbol(subvectorSubtree, vectorSymbols, 0); 217 AddAllowedChildSymbol(subvectorSubtree, scalarSymbols, 1); 218 AddAllowedChildSymbol(subvectorSubtree, scalarSymbols, 2); 211 219 #endregion 212 220 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentVectorTimeSeriesExpressionGrammar.cs
r17830 r18060 52 52 53 53 private const string VectorManipulationSymbolsName = "Vector Manipulation Symbols"; 54 private const string VectorSubVectorSymbolsName = "Vector SubVector Symbols"; 54 55 55 56 private const string RealValuedSymbolsName = "Real Valued Symbols"; … … 167 168 168 169 #region vector manipulation symbol declaration 169 var subvector = new SubVector() { EnableWindowing = true }; 170 var subvectorLocal = new SubVector(); 171 var subvectorSubtree = new SubVectorSubtree(); 170 172 #endregion 171 173 … … 199 201 var vectorSymbols = new GroupSymbol(VectorSymbolsName, new List<ISymbol>() { vectorarithmeticSymbols, vectortrigonometricSymbols, vectorexponentialAndLogarithmicSymbols, vectorpowerSymbols, vectorterminalSymbols }); 200 202 201 var vectorManipulationSymbols = new GroupSymbol(VectorManipulationSymbolsName, new List<ISymbol>() { subvector }); 203 var vectorSubVectorSymbols = new GroupSymbol(VectorSubVectorSymbolsName, new List<ISymbol>() { subvectorLocal, subvectorSubtree }); 204 var vectorManipulationSymbols = new GroupSymbol(VectorManipulationSymbolsName, new List<ISymbol>() { vectorSubVectorSymbols }); 202 205 203 206 //var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol> { scalarSymbols, vectorSymbols }); … … 260 263 SetSubtreeCount(vectorterminalSymbols, 0, 0); 261 264 262 SetSubtreeCount(subvector, 1, 1); 265 SetSubtreeCount(subvectorLocal, 1, 1); 266 SetSubtreeCount(subvectorSubtree, 3, 3); 263 267 #endregion 264 268 … … 273 277 AddAllowedChildSymbol(root, constant, 1); 274 278 AddAllowedChildSymbol(aggregationSymbols, vectorSymbols, 0); 275 AddAllowedChildSymbol(statisticsSymbols, subvector, 0);279 AddAllowedChildSymbol(statisticsSymbols, vectorSubVectorSymbols, 0); 276 280 AddAllowedChildSymbol(quantile, constantZeroToOne, 1); 277 281 AddAllowedChildSymbol(distancesSymbols, vectorSymbols, 1); 278 282 AddAllowedChildSymbol(distributionCharacteristicsSymbols, vectorSymbols, 0); 279 AddAllowedChildSymbol(distributionCharacteristicsSymbols, subvector, 0);283 AddAllowedChildSymbol(distributionCharacteristicsSymbols, vectorSubVectorSymbols, 0); 280 284 AddAllowedChildSymbol(distributionCharacteristicsSymbols, constantZeroToOne, 1); 281 285 AddAllowedChildSymbol(timeSeriesDynamicsSymbols, vectorSymbols, 0); 282 AddAllowedChildSymbol(timeSeriesDynamicsSymbols, subvector, 0);286 AddAllowedChildSymbol(timeSeriesDynamicsSymbols, vectorSubVectorSymbols, 0); 283 287 AddAllowedChildSymbol(timeSeriesDynamicsSymbols, constantZeroToOne, 1); 284 288 AddAllowedChildSymbol(timeSeriesDynamicsSymbols, constantZeroToOne, 2); … … 292 296 AddAllowedChildSymbol(vectorroot, constantZeroToOne, 1); 293 297 294 AddAllowedChildSymbol(subvector, vectorSymbols); 298 AddAllowedChildSymbol(subvectorLocal, vectorSymbols); 299 AddAllowedChildSymbol(subvectorSubtree, vectorSymbols, 0); 300 AddAllowedChildSymbol(subvectorSubtree, scalarSymbols, 1); 301 AddAllowedChildSymbol(subvectorSubtree, scalarSymbols, 2); 295 302 #endregion 296 303 -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17830 r18060 90 90 Covariance = 63, 91 91 SubVector = 64, 92 SubVectorSubtree = 65, 92 93 93 94 #region Time Series Symbols … … 195 196 public const byte Covariance = (byte)OpCode.Covariance; 196 197 public const byte SubVector = (byte)OpCode.SubVector; 198 public const byte SubVectorSubtree = (byte)OpCode.SubVectorSubtree; 197 199 #region Time Series Symbols 198 200 public const byte Median = (byte)OpCode.Median; … … 300 302 { typeof(Covariance), OpCodes.Covariance }, 301 303 { typeof(SubVector), OpCodes.SubVector }, 304 { typeof(SubVectorSubtree), OpCodes.SubVectorSubtree }, 302 305 303 306 #region Time Series Symbols -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
r18058 r18060 728 728 } 729 729 case OpCodes.SubVector: { 730 var cur = Evaluate(dataset, ref row, state, traceDict); 731 return WindowedFunctionApply(cur, (WindowedSymbolTreeNode)currentInstr.dynamicNode, 732 s => s, 733 v => v); 734 } 730 DoubleVector SubVector(DoubleVector v , double start, double end) { 731 int Mod(int x, int m) => (x % m + m) % m; 732 int startIdx = Mod((int)Math.Round(start * v.Count), v.Count); 733 int endIdx = Mod((int)Math.Round(end * v.Count), v.Count); 734 int size = v.Count; 735 if (startIdx < endIdx) { 736 return v.SubVector(startIdx, count: endIdx - startIdx); 737 } else { // wrap around 738 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx)); 739 v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 740 v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx); // copy [0:endIdx] to [size-startIdx:size] 741 return resultVector; 742 } 743 } 744 var cur = Evaluate(dataset, ref row, state, traceDict); 745 TraceEvaluation(currentInstr, cur); 746 return FunctionApply(cur, 747 s => s, 748 v => { 749 var node = (IWindowedSymbolTreeNode)currentInstr.dynamicNode; 750 return SubVector(v, node.Offset, node.Length); 751 }); 752 } 753 case OpCodes.SubVectorSubtree: { 754 DoubleVector SubVector(DoubleVector v, double start, double end) { 755 int Mod(int x, int m) => (x % m + m) % m; 756 int startIdx = Mod((int)Math.Round(start * v.Count), v.Count); 757 int endIdx = Mod((int)Math.Round(end * v.Count), v.Count); 758 int size = v.Count; 759 if (startIdx < endIdx) { 760 return v.SubVector(startIdx, count: endIdx - startIdx); 761 } else { // wrap around 762 var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx)); 763 v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx] 764 v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx); // copy [0:endIdx] to [size-startIdx:size] 765 return resultVector; 766 } 767 } 768 var cur = Evaluate(dataset, ref row, state, traceDict); 769 var offset = Evaluate(dataset, ref row, state, traceDict); 770 var length = Evaluate(dataset, ref row, state, traceDict); 771 TraceEvaluation(currentInstr, cur); 772 return FunctionApply(cur, 773 s => s, 774 v => SubVector(v, offset.Scalar, length.Scalar) 775 ); 776 } 735 777 case OpCodes.Variable: { 736 778 if (row < 0 || row >= dataset.Rows) return EvaluationResult.NaN; -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubVector.cs
r17726 r18060 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HEAL.Attic; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 27 26 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 29 [StorableType("4E9511C6-0FA4-496D-9610-35D9F779F899")] 28 [Item("SubVector", "Symbol that represents SubVector sum function.")] 29 public sealed class SubVector : WindowedSymbol { 30 private const int minimumArity = 1; 31 private const int maximumArity = 1; 32 33 public override int MinimumArity { 34 get { return minimumArity; } 35 } 36 public override int MaximumArity { 37 get { return maximumArity; } 38 } 30 [Item("SubVector", "Symbol that represent the SubVector function with local parameters.")] 31 public class SubVector : WindowedSymbol { 32 public override int MinimumArity => 1; 33 public override int MaximumArity => 1; 39 34 40 35 [StorableConstructor] 41 private SubVector(StorableConstructorFlag _) : base(_) { } 42 private SubVector(SubVector original, Cloner cloner) : base(original, cloner) { } 36 protected SubVector(StorableConstructorFlag _) : base(_) { } 37 38 protected SubVector(SubVector original, Cloner cloner) : base(original, cloner) { } 39 43 40 public override IDeepCloneable Clone(Cloner cloner) { 44 41 return new SubVector(this, cloner); 45 42 } 46 public SubVector() : base("SubVector", "Symbol that represents the SubVector function.") { } 43 44 public SubVector() : base("SubVector", "Symbol that represent the SubVector function with local parameters.") { 45 EnableWindowing = true; 46 } 47 } 48 49 [StorableType("BA11A829-3236-46C3-AE83-9FA8511D8E8C")] 50 [Item("SubVectorSubtree", "Symbol that represent the SubVector function with subtrees.")] 51 public sealed class SubVectorSubtree : Symbol { 52 public override int MinimumArity => 3; 53 public override int MaximumArity => 3; 54 55 [StorableConstructor] 56 private SubVectorSubtree(StorableConstructorFlag _) : base(_) { } 57 private SubVectorSubtree(SubVectorSubtree original, Cloner cloner) : base(original, cloner) { } 58 public override IDeepCloneable Clone(Cloner cloner) { return new SubVectorSubtree(this, cloner); } 59 public SubVectorSubtree() : base("SubVectorSubtree", "Symbol that represent the SubVector function with subtrees.") { } 47 60 } 48 61 } -
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/WindowedSymbol.cs
r17726 r18060 158 158 159 159 offsetMu = 0.0; 160 offsetSigma = 0. 05;160 offsetSigma = 0.2; 161 161 lengthMu = 1.0; 162 lengthSigma = 0. 05;162 lengthSigma = 0.2; 163 163 164 164 manipulatorOffsetMu = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.