def computeEER(rates, withthresh=0):
    """Computes equal error rates from the list of (true pos, false pos) values.
    If withthresh is true (not the default), then returns (eer, index at which eer occurs)."""
    det, fpos = zip(*rates)
    fpos = map(float, fpos)
    npos = [1.0-f for f in fpos]
    difs = [(abs(d-n), i) for i, (d, n) in enumerate(zip(det, npos))]
    mval, mindex = min(difs)
    if withthresh:
        return det[mindex], mindex
    else:
        return det[mindex]