(
        condq, statistic=lambda x: x[0,0], cutoff=0.95, min_batches=2)
return scores
There are a variety of ways of scoring the intersection between a
    prediction (a) and a true variable (b) that are all expressions of
    [[p(a&b), p(a&!b)], [p(!a&b), p(!a&!b)]].  This computes any of
    them by passing the above array to a 'statistic' function.
    By default it returns p(a&b).
There are a variety of ways of scoring the intersection between a
    prediction (a) and a true variable (b) that are all expressions of
    [[p(a&b), p(a&!b)], [p(!a&b), p(!a&!b)]].  This computes any of
    them by passing the above array to a 'statistic' function.
    By default it returns p(a&b).
There are a variety of ways of scoring the intersection between a prediction ( a ) and a true variable ( b ) that are all expressions of [[ p ( a&b ) p ( a&!b ) ] [ p ( !a&b ) p ( !a&!b ) ]] . This computes any of them by passing the above array to a statistic function . By default it returns p ( a&b ) .
def intersection_from_conditional_quantile(
        condq, statistic=lambda x: x[0,0], cutoff=0.95, min_batches=2):
    '''
    There are a variety of ways of scoring the intersection between a
    prediction (a) and a true variable (b) that are all expressions of
    [[p(a&b), p(a&!b)], [p(!a&b), p(!a&!b)]].  This computes any of
    them by passing the above array to a 'statistic' function.
    By default it returns p(a&b).
    '''
    with warnings.catch_warnings():
        warnings.simplefilter('ignore', UserWarning)
        cutoff = torch.tensor(cutoff)
    uncond_size = condq.conditional(0).size()
    units = condq.conditional(0).depth
    scores = torch.zeros((units, max(condq.keys()) + 1) + cutoff.shape)
    # math: actlevel = level such that p(x > level) = cutoff
    actlevel = condq.conditional(0).quantiles(cutoff)
    # use a progress bar if it's going to be more than a few seconds.
    prog = pbar if cutoff.numel() * units > 1e5 else lambda x: x
    for c in prog(sorted(condq.keys())):
        rq = condq.conditional(c)
        if c == 0 or rq.batchcount < min_batches:
            continue
        # math: condp = p(x > actlevel | cond)
        condp = rq.normalize(actlevel)
        truth = float(rq.size()) / uncond_size
        isect = truth * (1 - condp)
        pred = (1 - cutoff)
        union = pred + truth - isect
        # Compute relative mutual information directly.
        arr = torch.stack([
            isect,         pred - isect,
            truth - isect, 1 - union]).view((2, 2) + isect.shape)
        scores[:,c,...] = statistic(arr)
    return scores
def intersection_from_conditional_quantile ( condq , statistic = lambda x : x [ 0 , 0 ] , cutoff = 0.95 , min_batches = 2 ) : with warnings . catch_warnings ( ) : warnings . simplefilter ( 'ignore' , UserWarning ) cutoff = torch . tensor ( cutoff ) uncond_size = condq . conditional ( 0 ) . size ( ) units = condq . conditional ( 0 ) . depth scores = torch . zeros ( ( units , max ( condq . keys ( ) ) + 1 ) + cutoff . shape ) # math: actlevel = level such that p(x > level) = cutoff actlevel = condq . conditional ( 0 ) . quantiles ( cutoff ) # use a progress bar if it's going to be more than a few seconds. prog = pbar if cutoff . numel ( ) * units > 1e5 else lambda x : x for c in prog ( sorted ( condq . keys ( ) ) ) : rq = condq . conditional ( c ) if c == 0 or rq . batchcount < min_batches : continue # math: condp = p(x > actlevel | cond) condp = rq . normalize ( actlevel ) truth = float ( rq . size ( ) ) / uncond_size isect = truth * ( 1 - condp ) pred = ( 1 - cutoff ) union = pred + truth - isect # Compute relative mutual information directly. arr = torch . stack ( [ isect , pred - isect , truth - isect , 1 - union ] ) . view ( ( 2 , 2 ) + isect . shape ) scores [ : , c , ... ] = statistic ( arr ) return scores