code: public double approximationDistanceAlphabet(double[] ts, int winSize, int paaSize,
        int alphabetSize, double normThreshold) throws Exception {
  
      double resDistance = 0d;
      int windowCounter = 0;
  
      double[] centralLines = na.getCentralCuts(alphabetSize);
      double[] cuts = na.getCuts(alphabetSize);
  
      for (int i = 0; i < ts.length - winSize + 1; i++) {
  
        double[] subseries = Arrays.copyOfRange(ts, i, i + winSize);
        double subsequenceDistance = 0.;
  
        if (tsProcessor.stDev(subseries) > normThreshold) {
          subseries = tsProcessor.znorm(subseries, normThreshold);
        }
  
        double[] paa = tsProcessor.paa(subseries, paaSize);
        int[] leterIndexes = tsProcessor.ts2Index(paa, cuts);
  
        windowCounter++;
  
        // essentially the distance here is the distance between the segment's
        // PAA value and the real TS value
        //
        for (int j = 0; j < paa.length; j++) {
          // compute the alphabet central cut line
          int letterIdx = leterIndexes[j];
          double cLine = centralLines[letterIdx];
          subsequenceDistance = subsequenceDistance + ed.distance(cLine, paa[j]);
        }
  
        resDistance = resDistance + subsequenceDistance / paa.length;
      }
  
      return resDistance / (double) windowCounter;
    }
docs: Computes the distance between approximated values and the real TS.
  
  @param ts the timeseries.
  @param winSize SAX window size.
  @param paaSize SAX PAA size.
  @param alphabetSize SAX alphabet size.
  @param normThreshold the normalization threshold.
  @return the distance value.
  @throws Exception if error occurs.