def print_config_overlap(testres, with_plot=True):
    (truth2_prop, prop2_mat) = testres.get_truth2_prop()
    qx2_gt_ranks = truth2_prop['gt']['rank']
    qx2_success = (qx2_gt_ranks == 0)
    cfgx2_num_correct = np.nansum(qx2_success, axis=0)
    best_cfgx = cfgx2_num_correct.argmax()
    logger.info('Config Overlap')
    isect_mat = np.zeros((testres.nConfig, testres.nConfig), dtype=np.int32)
    union_mat = np.zeros((testres.nConfig, testres.nConfig), dtype=np.int32)
    for cfgx1 in range(testres.nConfig):
        for cfgx2 in range(testres.nConfig):
            if (cfgx1 == cfgx2):
                success_qx1 = np.where(qx2_success.T[cfgx1])[0]
                isect_mat[cfgx1][cfgx2] = len(success_qx1)
                union_mat[cfgx1][cfgx2] = len(success_qx1)
                continue
            success_qx1 = np.where(qx2_success.T[cfgx1])[0]
            success_qx2 = np.where(qx2_success.T[cfgx2])[0]
            union_ = np.union1d(success_qx1, success_qx2)
            isect_ = np.intersect1d(success_qx1, success_qx2)
            isect_mat[cfgx1][cfgx2] = len(isect_)
            union_mat[cfgx1][cfgx2] = len(union_)
    n_success_list = np.array([qx2_success.T[cfgx1].sum() for cfgx1 in range(testres.nConfig)])
    improves_mat = (n_success_list[:, None] - isect_mat)
    disjoint_mat = (union_mat - isect_mat)
    logger.info(('n_success_list = %r' % (n_success_list,)))
    logger.info(('union_mat =\n%s' % (union_mat,)))
    logger.info(('isect_mat =\n%s' % (isect_mat,)))
    logger.info('cfgx1 and cfgx2 have <x> not in common')
    logger.info(('disjoint_mat =\n%s' % (disjoint_mat,)))
    logger.info('cfgx1 helps cfgx2 by <x>')
    logger.info(('improves_mat =\n%s' % (improves_mat,)))
    logger.info(('improves_mat.sum(axis=1) = \n%s' % (improves_mat.sum(axis=1),)))
    bestx_by_improves = improves_mat.sum(axis=1).argmax()
    logger.info(('bestx_by_improves = %r' % (bestx_by_improves,)))
    logger.info(('best_cfgx = %r' % (best_cfgx,)))
    for cfgx in range(testres.nConfig):
        if (cfgx == best_cfgx):
            continue
        pipelbl = testres.cfgx2_lbl[cfgx]
        qx2_anysuccess = np.logical_or(qx2_success.T[cfgx], qx2_success.T[best_cfgx])
        qx2_othersuccess = np.logical_and(qx2_anysuccess, np.logical_not(qx2_success.T[best_cfgx]))
        logger.info(('cfgx %d) has %d success cases that that the best config does not have -- %s' % (cfgx, qx2_othersuccess.sum(), pipelbl)))
    qx2_success.T[cfgx]
    if with_plot:
        if False:
            ave_dlen = [np.sqrt(np.array(testres.ibs.get_annot_chip_dlensqrd(testres.qaids, config2_=qreq_.query_config2_))).mean() for qreq_ in testres.cfgx2_qreq_]
            ave_width_inimg = [np.array(testres.ibs.get_annot_bboxes(testres.qaids, config2_=qreq_.query_config2_))[:, (2 + 0)].mean() for qreq_ in testres.cfgx2_qreq_]
            ave_width = [np.array(testres.ibs.get_annot_chip_sizes(testres.qaids, config2_=qreq_.query_config2_))[:, 0].mean() for qreq_ in testres.cfgx2_qreq_]
        import wbia.plottool as pt

        def label_ticks():
            import wbia.plottool as pt
            ax = pt.gca()
            labels = testres.get_varied_labels()
            ax.set_xticks(list(range(len(labels))))
            ax.set_xticklabels([lbl[0:100] for lbl in labels])
            [lbl.set_rotation((- 25)) for lbl in ax.get_xticklabels()]
            [lbl.set_horizontalalignment('left') for lbl in ax.get_xticklabels()]
            ax.set_yticks(list(range(len(labels))))
            ax.set_yticklabels([lbl[0:100] for lbl in labels])
            [lbl.set_horizontalalignment('right') for lbl in ax.get_yticklabels()]
            [lbl.set_verticalalignment('center') for lbl in ax.get_yticklabels()]
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(union_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('union mat: cfg<x> and cfg<y> have <z> success cases in in total')
        label_ticks()
        label_ticks()
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(isect_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('isect mat: cfg<x> and cfg<y> have <z> success cases in common')
        label_ticks()
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(disjoint_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('disjoint mat (union - isect): cfg<x> and cfg<y> have <z> success cases not in common')
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(improves_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('improves mat (diag.T - isect): cfg<x> got <z> qaids that cfg <y> missed')
        label_ticks()
def print_config_overlap(testres, with_plot=True):
    (truth2_prop, prop2_mat) = testres.get_truth2_prop()
    qx2_gt_ranks = truth2_prop['gt']['rank']
    qx2_success = (qx2_gt_ranks == 0)
    cfgx2_num_correct = np.nansum(qx2_success, axis=0)
    best_cfgx = cfgx2_num_correct.argmax()
    logger.info('Config Overlap')
    isect_mat = np.zeros((testres.nConfig, testres.nConfig), dtype=np.int32)
    union_mat = np.zeros((testres.nConfig, testres.nConfig), dtype=np.int32)
    for cfgx1 in range(testres.nConfig):
        for cfgx2 in range(testres.nConfig):
            if (cfgx1 == cfgx2):
                success_qx1 = np.where(qx2_success.T[cfgx1])[0]
                isect_mat[cfgx1][cfgx2] = len(success_qx1)
                union_mat[cfgx1][cfgx2] = len(success_qx1)
                continue
            success_qx1 = np.where(qx2_success.T[cfgx1])[0]
            success_qx2 = np.where(qx2_success.T[cfgx2])[0]
            union_ = np.union1d(success_qx1, success_qx2)
            isect_ = np.intersect1d(success_qx1, success_qx2)
            isect_mat[cfgx1][cfgx2] = len(isect_)
            union_mat[cfgx1][cfgx2] = len(union_)
    n_success_list = np.array([qx2_success.T[cfgx1].sum() for cfgx1 in range(testres.nConfig)])
    improves_mat = (n_success_list[:, None] - isect_mat)
    disjoint_mat = (union_mat - isect_mat)
    logger.info(('n_success_list = %r' % (n_success_list,)))
    logger.info(('union_mat =\n%s' % (union_mat,)))
    logger.info(('isect_mat =\n%s' % (isect_mat,)))
    logger.info('cfgx1 and cfgx2 have <x> not in common')
    logger.info(('disjoint_mat =\n%s' % (disjoint_mat,)))
    logger.info('cfgx1 helps cfgx2 by <x>')
    logger.info(('improves_mat =\n%s' % (improves_mat,)))
    logger.info(('improves_mat.sum(axis=1) = \n%s' % (improves_mat.sum(axis=1),)))
    bestx_by_improves = improves_mat.sum(axis=1).argmax()
    logger.info(('bestx_by_improves = %r' % (bestx_by_improves,)))
    logger.info(('best_cfgx = %r' % (best_cfgx,)))
    for cfgx in range(testres.nConfig):
        if (cfgx == best_cfgx):
            continue
        pipelbl = testres.cfgx2_lbl[cfgx]
        qx2_anysuccess = np.logical_or(qx2_success.T[cfgx], qx2_success.T[best_cfgx])
        qx2_othersuccess = np.logical_and(qx2_anysuccess, np.logical_not(qx2_success.T[best_cfgx]))
        logger.info(('cfgx %d) has %d success cases that that the best config does not have -- %s' % (cfgx, qx2_othersuccess.sum(), pipelbl)))
    qx2_success.T[cfgx]
    if with_plot:
        if False:
            ave_dlen = [np.sqrt(np.array(testres.ibs.get_annot_chip_dlensqrd(testres.qaids, config2_=qreq_.query_config2_))).mean() for qreq_ in testres.cfgx2_qreq_]
            ave_width_inimg = [np.array(testres.ibs.get_annot_bboxes(testres.qaids, config2_=qreq_.query_config2_))[:, (2 + 0)].mean() for qreq_ in testres.cfgx2_qreq_]
            ave_width = [np.array(testres.ibs.get_annot_chip_sizes(testres.qaids, config2_=qreq_.query_config2_))[:, 0].mean() for qreq_ in testres.cfgx2_qreq_]
        import wbia.plottool as pt

        def label_ticks():
            import wbia.plottool as pt
            ax = pt.gca()
            labels = testres.get_varied_labels()
            ax.set_xticks(list(range(len(labels))))
            ax.set_xticklabels([lbl[0:100] for lbl in labels])
            [lbl.set_rotation((- 25)) for lbl in ax.get_xticklabels()]
            [lbl.set_horizontalalignment('left') for lbl in ax.get_xticklabels()]
            ax.set_yticks(list(range(len(labels))))
            ax.set_yticklabels([lbl[0:100] for lbl in labels])
            [lbl.set_horizontalalignment('right') for lbl in ax.get_yticklabels()]
            [lbl.set_verticalalignment('center') for lbl in ax.get_yticklabels()]
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(union_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('union mat: cfg<x> and cfg<y> have <z> success cases in in total')
        label_ticks()
        label_ticks()
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(isect_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('isect mat: cfg<x> and cfg<y> have <z> success cases in common')
        label_ticks()
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(disjoint_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('disjoint mat (union - isect): cfg<x> and cfg<y> have <z> success cases not in common')
        pt.figure(fnum=pt.next_fnum())
        pt.plt.imshow(improves_mat, interpolation='none', cmap='hot')
        pt.plt.colorbar()
        pt.set_title('improves mat (diag.T - isect): cfg<x> got <z> qaids that cfg <y> missed')
        label_ticks()