private int extend(SimpleRegression regression, int start, int end) {
    boolean horizon = Double.isNaN(regression.getRSquare());
    double standard = regression.getIntercept();
    int bindex = start;
    while (bindex > 0) {
      bindex--;
      regression.addData((double) getTime().get(bindex) - startTime, getValue().get(bindex));
      double alpha = regression.getRSquare();
      if ((horizon && getValue().get(bindex) != standard) || (!horizon && alpha < threshold)) {
        break;
      }
    }
    regression.removeData((double) getTime().get(bindex) - startTime, getValue().get(bindex));
    if (bindex == 0) {
      return end;
    }
    int findex = end;
    while (findex < getLen()) {
      regression.addData((double) getTime().get(findex) - startTime, getValue().get(findex));
      double alpha = regression.getRSquare();
      if ((horizon && getValue().get(findex) != standard) || (!horizon && alpha < threshold)) {
        break;
      }
      findex++;
    }
    if (findex == getLen()) {
      return end;
    }
    MissingSubSeries m = new MissingSubSeries(bindex + 1, findex);
    anomalyList.add(m);
    return findex;
  }
Anomaly detection for anomalies of data missing.
library-udf/src/main/java/org/apache/iotdb/library/anomaly/util/MissDetector.java