@Override
  public void terminate(PointCollector collector) throws Exception {
    int n = valueArrayList.size();
    if (m <= 0 || m >= n) {
      m = n - 2;
    }
    for (int shift = 1; shift <= m; shift++) {
      double correlation = 0.0;
      for (int i = 0; i < n - shift; i++) {
        if (Double.isFinite(valueArrayList.get(shift + i))
            && Double.isFinite(valueArrayList.get(i))) {
          correlation += valueArrayList.get(shift + i) * valueArrayList.get(i);
        }
      }
      correlation = correlation / n;
      collector.putDouble((long) n + shift, correlation);
      qlb += correlation * correlation / (n - shift) * n * (n + 2);
      ChiSquaredDistribution qlbdist = new ChiSquaredDistribution(shift);
      double qlbprob = 1.0 - qlbdist.cumulativeProbability(qlb);
      collector.putDouble(shift, qlbprob);
    }
  }
This function calculates acf, and then calculates p-value of corresponding Q_LB statistics.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFQLB.java