public double approximationDistancePAA(double[] ts,int winSize,int paaSize,double normThreshold) throws Exception {
  double resDistance=0d;
  int windowCounter=0;
  double pointsPerWindow=(double)winSize / (double)paaSize;
  for (int i=0; i < ts.length - winSize + 1; i++) {
    double[] subseries=Arrays.copyOfRange(ts,i,i + winSize);
    if (tsProcessor.stDev(subseries) > normThreshold) {
      subseries=tsProcessor.znorm(subseries,normThreshold);
    }
    double[] paa=tsProcessor.paa(subseries,paaSize);
    windowCounter++;
    double subsequenceDistance=0.;
    for (int j=0; j < subseries.length; j++) {
      int paaIdx=(int)Math.floor(((double)j + 0.5) / (double)pointsPerWindow);
      if (paaIdx < 0) {
        paaIdx=0;
      }
      if (paaIdx > paa.length) {
        paaIdx=paa.length - 1;
      }
      subsequenceDistance=subsequenceDistance + ed.distance(paa[paaIdx],subseries[j]);
    }
    resDistance=resDistance + subsequenceDistance / subseries.length;
  }
  return resDistance / (double)windowCounter;
}

public double approximationDistancePAA ( double [ ] ts , int winSize , int paaSize , double normThreshold ) throws Exception { double resDistance = 0d ; int windowCounter = 0 ; double pointsPerWindow = ( double ) winSize / ( double ) paaSize ; for ( int i = 0 ; i < ts . length - winSize + 1 ; i ++ ) { double [ ] subseries = Arrays . copyOfRange ( ts , i , i + winSize ) ; if ( tsProcessor . stDev ( subseries ) > normThreshold ) { subseries = tsProcessor . znorm ( subseries , normThreshold ) ; } double [ ] paa = tsProcessor . paa ( subseries , paaSize ) ; windowCounter ++ ; double subsequenceDistance = 0. ; for ( int j = 0 ; j < subseries . length ; j ++ ) { int paaIdx = ( int ) Math . floor ( ( ( double ) j + 0.5 ) / ( double ) pointsPerWindow ) ; if ( paaIdx < 0 ) { paaIdx = 0 ; } if ( paaIdx > paa . length ) { paaIdx = paa . length - 1 ; } subsequenceDistance = subsequenceDistance + ed . distance ( paa [ paaIdx ] , subseries [ j ] ) ; } resDistance = resDistance + subsequenceDistance / subseries . length ; } return resDistance / ( double ) windowCounter ; }
computes the distance between approximated values and the real ts .
