public static double computeKSDelta(final DoublesSketch sketch1,
      final DoublesSketch sketch2) {
    final DoublesAuxiliary p = new DoublesAuxiliary(sketch1);
    final DoublesAuxiliary q = new DoublesAuxiliary(sketch2);

    final double[] pSamplesArr = p.auxSamplesArr_;
    final double[] qSamplesArr = q.auxSamplesArr_;
    final long[] pCumWtsArr = p.auxCumWtsArr_;
    final long[] qCumWtsArr = q.auxCumWtsArr_;
    final int pSamplesArrLen = pSamplesArr.length;
    final int qSamplesArrLen = qSamplesArr.length;

    final double n1 = sketch1.getN();
    final double n2 = sketch2.getN();

    //Compute D from the two distributions
    double deltaArea = 0.0;
    int i = getNextIndex(pSamplesArr, -1);
    int j = getNextIndex(qSamplesArr, -1);

    // We're done if either array reaches the end
    while ((i < pSamplesArrLen) && (j < qSamplesArrLen)) {
      final double pSample = pSamplesArr[i];
      final double qSample = qSamplesArr[j];
      final long pWt = pCumWtsArr[i];
      final long qWt = qCumWtsArr[j];
      final double pNormWt = pWt / n1;
      final double qNormWt = qWt / n2;
      final double pMinusQ = Math.abs(pNormWt - qNormWt);
      final double curD = deltaArea;
      deltaArea = Math.max(curD, pMinusQ);

      //Increment i or j or both
      if (pSample == qSample) {
        i = getNextIndex(pSamplesArr, i);
        j = getNextIndex(qSamplesArr, j);
      } else if (pSample < qSample) {
        i = getNextIndex(pSamplesArr, i);
      } else {
        j = getNextIndex(qSamplesArr, j);
      }
    }

    //This is D, the delta difference in area of the two distributions
    deltaArea = Math.max(deltaArea, Math.abs((pCumWtsArr[i] / n1) - (qCumWtsArr[j] / n2)));
    return deltaArea;
  }
public static double computeKSDelta ( final DoublesSketch sketch1 , final DoublesSketch sketch2 ) { final DoublesAuxiliary p = new DoublesAuxiliary ( sketch1 ) ; final DoublesAuxiliary q = new DoublesAuxiliary ( sketch2 ) ; final double [ ] pSamplesArr = p . auxSamplesArr_ ; final double [ ] qSamplesArr = q . auxSamplesArr_ ; final long [ ] pCumWtsArr = p . auxCumWtsArr_ ; final long [ ] qCumWtsArr = q . auxCumWtsArr_ ; final int pSamplesArrLen = pSamplesArr . length ; final int qSamplesArrLen = qSamplesArr . length ; final double n1 = sketch1 . getN ( ) ; final double n2 = sketch2 . getN ( ) ; double deltaArea = 0.0 ; int i = getNextIndex ( pSamplesArr , - 1 ) ; int j = getNextIndex ( qSamplesArr , - 1 ) ; while ( ( i < pSamplesArrLen ) && ( j < qSamplesArrLen ) ) { final double pSample = pSamplesArr [ i ] ; final double qSample = qSamplesArr [ j ] ; final long pWt = pCumWtsArr [ i ] ; final long qWt = qCumWtsArr [ j ] ; final double pNormWt = pWt / n1 ; final double qNormWt = qWt / n2 ; final double pMinusQ = Math . abs ( pNormWt - qNormWt ) ; final double curD = deltaArea ; deltaArea = Math . max ( curD , pMinusQ ) ; if ( pSample == qSample ) { i = getNextIndex ( pSamplesArr , i ) ; j = getNextIndex ( qSamplesArr , j ) ; } else if ( pSample < qSample ) { i = getNextIndex ( pSamplesArr , i ) ; } else { j = getNextIndex ( qSamplesArr , j ) ; } } deltaArea = Math . max ( deltaArea , Math . abs ( ( pCumWtsArr [ i ] / n1 ) - ( qCumWtsArr [ j ] / n2 ) ) ) ; return deltaArea ; }
Computes the raw delta area between two quantile sketches for the
{@link #kolmogorovSmirnovTest(DoubleSketch, DoubleSketch, double)
Kolmogorov-Smirnov Test}
method.
@param sketch1 Input DoubleSketch 1
@param sketch2 Input DoubleSketch 2
@return the raw delta area between two quantile sketches