private static double computeApproxBinoUB(final long numSamplesI, final double theta,
      final int numSDev) {
    if (theta == 1.0) {
      return (numSamplesI);
    }

    else if (numSamplesI == 0) {
      final double delta = deltaOfNumSDev[numSDev];
      final double rawUB = (Math.log(delta)) / (Math.log(1.0 - theta));
      return (Math.ceil(rawUB)); // round up
    }

    else if (numSamplesI > 120) {
      // plenty of samples, so gaussian approximation to binomial distribution isn't too bad
      final double rawUB = contClassicUB(numSamplesI, theta, numSDev);
      return (rawUB + 0.5); // fake round up
    }

    // at this point we know 1 <= numSamplesI <= 120

    else if (theta > (1.0 - 1e-5)) { // empirically-determined threshold
      return (numSamplesI + 1);
    }

    else if (theta < ((numSamplesI) / 360.0)) {  // empirically-determined threshold
      // here we use the gaussian approximation, but with a modified "numSDev"
      final int index;
      final double rawUB;
      index = (3 * ((int) numSamplesI)) + (numSDev - 1);
      rawUB = contClassicUB(numSamplesI, theta, EquivTables.getUB(index));
      return (rawUB + 0.5); // fake round up
    }

    else { // This is the most difficult range to approximate; we will compute an "exact" UB.
      // We know that est <= 360, so specialNPrimeF() shouldn't be ridiculously slow.
      final double delta = deltaOfNumSDev[numSDev];
      final long nprimef = specialNPrimeF(numSamplesI, theta, delta);
      return (nprimef); // don't need to round
    }
  }
private static double computeApproxBinoUB ( final long numSamplesI , final double theta , final int numSDev ) { if ( theta == 1.0 ) { return ( numSamplesI ) ; } else if ( numSamplesI == 0 ) { final double delta = deltaOfNumSDev [ numSDev ] ; final double rawUB = ( Math . log ( delta ) ) / ( Math . log ( 1.0 - theta ) ) ; return ( Math . ceil ( rawUB ) ) ; } else if ( numSamplesI > 120 ) { final double rawUB = contClassicUB ( numSamplesI , theta , numSDev ) ; return ( rawUB + 0.5 ) ; } else if ( theta > ( 1.0 - 1e-5 ) ) { return ( numSamplesI + 1 ) ; } else if ( theta < ( ( numSamplesI ) / 360.0 ) ) { final int index ; final double rawUB ; index = ( 3 * ( ( int ) numSamplesI ) ) + ( numSDev - 1 ) ; rawUB = contClassicUB ( numSamplesI , theta , EquivTables . getUB ( index ) ) ; return ( rawUB + 0.5 ) ; } else { final double delta = deltaOfNumSDev [ numSDev ] ; final long nprimef = specialNPrimeF ( numSamplesI , theta , delta ) ; return ( nprimef ) ; } }
a Frequentist confidence interval based on the tails of the Binomial distribution.