Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/22/21 13:55:10 (3 years ago)
Author:
pfleck
Message:

#3040 Switched from offset-length sub-vector to "start-end with wrapping" subvector.

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

Legend:

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

    r17930 r18058  
    369369      Func<DoubleVector, double> vFunc = null) {
    370370
    371       var offset = node.Offset;
    372       var length = node.Length;
     371      // Parameters are interpreted as start and end with wrapping
     372      var start = node.Offset;
     373      var end = node.Length;
    373374
    374375      DoubleVector SubVector(DoubleVector v) {
    375         int index = (int)(offset * v.Count);
    376         int count = (int)(length * (v.Count - index));
    377         return v.SubVector(index, count);
    378       };
     376        int startIdx = (int)Math.Round(start * v.Count);
     377        int endIdx = (int)Math.Round(end * v.Count);
     378        int size = v.Count;
     379        if (startIdx < endIdx) {
     380          return v.SubVector(startIdx, count: endIdx - startIdx);
     381        } else { // wrap around
     382          var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx));
     383          v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
     384          v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx);   // copy [0:endIdx]      to [size-startIdx:size]
     385          return resultVector;
     386        }
     387      }
    379388
    380389      if (val.IsScalar && sFunc != null) return new EvaluationResult(sFunc(val.Scalar));
     
    385394      Func<double, double> sFunc = null,
    386395      Func<DoubleVector, DoubleVector> vFunc = null) {
    387       var offset = node.Offset;
    388       var length = node.Length;
     396      // Parameters are interpreted as start and end with wrapping
     397      var start = node.Offset;
     398      var end = node.Length;
    389399
    390400      DoubleVector SubVector(DoubleVector v) {
    391         int index = (int)(offset * v.Count);
    392         int count = (int)(length * (v.Count - index));
    393         return v.SubVector(index, count);
    394       };
     401        int startIdx = (int)Math.Round(start * v.Count);
     402        int endIdx = (int)Math.Round(end * v.Count);
     403        int size = v.Count;
     404        if (startIdx < endIdx) {
     405          return v.SubVector(startIdx, count: endIdx - startIdx);
     406        } else { // wrap around
     407          var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx));
     408          v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
     409          v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx);   // copy [0:endIdx]      to [size-startIdx:size]
     410          return resultVector;
     411        }
     412      }
    395413
    396414      if (val.IsScalar && sFunc != null) return new EvaluationResult(sFunc(val.Scalar));
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/WindowedSymbolTreeNode.cs

    r17573 r18058  
    3737    public double Offset {
    3838      get { return offset; }
    39       set { offset = Math.Min(Math.Max(value, 0.0), 1.0); }     
     39      set { offset = Math.Min(Math.Max(value, 0.0), 1.0); }
    4040    }
    4141    [Storable]
     
    8888    public override string ToString() {
    8989      return Symbol.EnableWindowing
    90         ? base.ToString() + $"[{Offset} : {Length}]"
     90        ? base.ToString() + $"[{Offset:f3} : {Length:f3}]"
    9191        : base.ToString();
    9292    }
Note: See TracChangeset for help on using the changeset viewer.