public void detect() {
    getPredictLabel().addAll(new int[getLen()]);
    this.startTime = getTime().get(0);
    int i = 0;
    int windowSize = minLength / 2;
    double[][] data = new double[windowSize][2];
    SimpleRegression regression = new SimpleRegression();
    while (i + windowSize < getLen()) {
      for (int j = 0; j < windowSize; j++) {
        data[j][0] = (double) getTime().get(i + j) - startTime;
        data[j][1] = getValue().get(i + j);
      }
      regression.addData(data);
      double alpha = regression.getRSquare();
      if (Double.isNaN(alpha) || alpha >= threshold) {
        i = extend(regression, i, i + windowSize);
      } else {
        i += windowSize;
      }
      regression.clear();
      r2 += Double.isNaN(alpha) ? 1 : alpha;
      windowCnt++;
    }
    label();
  }
Anomaly detection for anomalies of data missing.
library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java