Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/28/21 13:37:43 (3 years ago)
Author:
pfleck
Message:

#3040 Added a subvector symbol with ranges as subtrees.

Location:
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r17830 r18060  
    9090    Covariance = 63,
    9191    SubVector = 64,
     92    SubVectorSubtree = 65,
    9293
    9394    #region Time Series Symbols
     
    195196    public const byte Covariance = (byte)OpCode.Covariance;
    196197    public const byte SubVector = (byte)OpCode.SubVector;
     198    public const byte SubVectorSubtree = (byte)OpCode.SubVectorSubtree;
    197199    #region Time Series Symbols
    198200    public const byte Median = (byte)OpCode.Median;
     
    300302      { typeof(Covariance), OpCodes.Covariance },
    301303      { typeof(SubVector), OpCodes.SubVector },
     304      { typeof(SubVectorSubtree), OpCodes.SubVectorSubtree },
    302305
    303306      #region Time Series Symbols
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs

    r18058 r18060  
    728728          }
    729729        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        }
    735777        case OpCodes.Variable: {
    736778            if (row < 0 || row >= dataset.Rows) return EvaluationResult.NaN;
Note: See TracChangeset for help on using the changeset viewer.