public static TimeWarpInfo getWarpInfoBetween(final MultivariateTimeSeries tsI, final MultivariateTimeSeries tsJ, int searchRadius, final DistanceFunction distFn) { if (tsI.size() == 0 || tsJ.size() == 0) { return new TimeWarpInfo(0, new WarpPath(0), tsI.size(), tsJ.size()); } return fastDTW(tsI, tsJ, searchRadius, distFn); }
private static TimeWarpInfo fastDTW(final MultivariateTimeSeries tsI, final MultivariateTimeSeries tsJ, int searchRadius, final DistanceFunction distFn) { if (searchRadius < 0) searchRadius = 0; final int minTSsize = searchRadius + 2; if ((tsI.size() <= minTSsize) || (tsJ.size() <= minTSsize)) { // Perform full Dynamic Time Warping. return DTW.getWarpInfoBetween(tsI, tsJ, distFn); } else { final PAA shrunkI = new PAA(tsI, tsI.size() / 2); final PAA shrunkJ = new PAA(tsJ, tsJ.size() / 2); // Determine the search window that constrains the area of the cost matrix that will be evaluated based on // the warp path found at the previous resolution (smaller time series). final WarpPath warpPath = getWarpInfoBetween(shrunkI, shrunkJ, searchRadius, distFn).getPath(); final SearchWindow window = new ExpandedResWindow(tsI, tsJ, shrunkI, shrunkJ, warpPath, searchRadius); // Find the optimal warp path through this search window constraint. return DTW.getWarpInfoBetween(tsI, tsJ, window, distFn); } } }
public void add(long time, double[] values) { if (labels.size() != values.length + 1) // labels include a label for time throw new InternalError("ERROR: The TSValues: " + values + " contains the wrong number of values. " + "expected: " + labels.size() + ", " + "found: " + values.length); if ((this.size() > 0) && (time <= times.get(times.size() - 1))) throw new InternalError("ERROR: The point being inserted at the " + "end of the time series does not have " + "the correct time sequence. "); times.add(time); this.values.add(values); }
public void normalize() { // Calculate the mean of each FD. final double[] mean = new double[this.numOfDimensions()]; for (int col = 0; col < numOfDimensions(); col++) { double currentSum = 0.0; for (int row = 0; row < this.size(); row++) currentSum += this.getMeasurement(row, col); mean[col] = currentSum / this.size(); } // end for loop // Calculate the standard deviation of each FD. final double[] stdDev = new double[numOfDimensions()]; for (int col = 0; col < numOfDimensions(); col++) { double variance = 0.0; for (int row = 0; row < this.size(); row++) variance += Math.abs(getMeasurement(row, col) - mean[col]); stdDev[col] = variance / this.size(); } // end for loop // Normalize the values in the data using the mean and standard deviation // for each FD. => Xrc = (Xrc-Mc)/SDc for (int row = 0; row < this.size(); row++) { for (int col = 0; col < numOfDimensions(); col++) { // Normalize data point. if (stdDev[col] == 0.0) // prevent divide by zero errors setMeasurement(row, col, 0.0); // stdDev is zero means all pts identical else // typical case setMeasurement(row, col, (getMeasurement(row, col) - mean[col]) / stdDev[col]); } // end for loop } // end for loop } // end normalize();
public PAA(MultivariateTimeSeries ts, int shrunkSize) { this.originalLength = ts.size(); this.aggPtSize = new int[shrunkSize]; final double reducedPtSize = ts.size() / (double) shrunkSize; while (ptToReadFrom < ts.size()) { ptToReadTo = (int) Math.round(reducedPtSize * (this.size() + 1)) - 1; // determine end of current range final int ptsToRead = ptToReadTo - ptToReadFrom + 1; this.aggPtSize[super.size()] = ptsToRead; this.add(timeSum, measurementSums);