(condmv)
return iou
Given a RunningConditionalVariance containing mean values of
    indictors, estimates all-pairs IoU statistics for all units
    between the conditions and the indicators.
    The result is a tensor of dimension (units, conditions)
    containing IoU estimates for each combination.
Given a RunningConditionalVariance containing mean values of
    indictors, estimates all-pairs IoU statistics for all units
    between the conditions and the indicators.
    The result is a tensor of dimension (units, conditions)
    containing IoU estimates for each combination.
Given a RunningConditionalVariance containing mean values of indictors estimates all - pairs IoU statistics for all units between the conditions and the indicators . The result is a tensor of dimension ( units conditions ) containing IoU estimates for each combination .
def iou_from_conditional_indicator_mean(condmv):
    '''
    Given a RunningConditionalVariance containing mean values of
    indictors, estimates all-pairs IoU statistics for all units
    between the conditions and the indicators.
    The result is a tensor of dimension (units, conditions)
    containing IoU estimates for each combination.
    '''
    # Old code using python loops.
    # gt = {k: condi99.conditional(k).size() /
    #      condi99.conditional(0).size() for k in condi99.keys()}
    # act = condi99.conditional(0).mean()
    # isect = {k: condi99.conditional(k).mean() * gt[k] for k in condi99.keys()}
    # union = {k: act + gt[k] - isect[k] for k in condi99.keys()}
    # iou = {k: isect[k] / union[k] for k in condi99.keys()}

    # New code arranging with pytorch tensors
    uncond_size = condmv.conditional(0).size()
    units = condmv.conditional(0).mean().shape[0]
    conditions = max(condmv.keys()) + 1
    act = condmv.conditional(0).mean()
    gt = torch.zeros(conditions)
    isect = torch.zeros(conditions, units)
    for k in condmv.keys():
        gt[k] = condmv.conditional(k).size() / condmv.conditional(0).size()
        isect[k] = condmv.conditional(k).mean() * gt[k]
    union = act[None,:] + gt[:,None] - isect
    iou = isect / union
    return iou
def iou_from_conditional_indicator_mean ( condmv ) : # Old code using python loops. # gt = {k: condi99.conditional(k).size() / #      condi99.conditional(0).size() for k in condi99.keys()} # act = condi99.conditional(0).mean() # isect = {k: condi99.conditional(k).mean() * gt[k] for k in condi99.keys()} # union = {k: act + gt[k] - isect[k] for k in condi99.keys()} # iou = {k: isect[k] / union[k] for k in condi99.keys()} # New code arranging with pytorch tensors uncond_size = condmv . conditional ( 0 ) . size ( ) units = condmv . conditional ( 0 ) . mean ( ) . shape [ 0 ] conditions = max ( condmv . keys ( ) ) + 1 act = condmv . conditional ( 0 ) . mean ( ) gt = torch . zeros ( conditions ) isect = torch . zeros ( conditions , units ) for k in condmv . keys ( ) : gt [ k ] = condmv . conditional ( k ) . size ( ) / condmv . conditional ( 0 ) . size ( ) isect [ k ] = condmv . conditional ( k ) . mean ( ) * gt [ k ] union = act [ None , : ] + gt [ : , None ] - isect iou = isect / union return iou