def map_score(testres):
    "\n        For each query compute a precision recall curve.\n        Then, for each query compute the average precision.\n        Then take the mean of all average precisions to obtain the mAP.\n\n        Script:\n            >>> #ibs = wbia.opendb('Oxford')\n            >>> #ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True]')\n            >>> import wbia\n            >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True],can_match_sameimg=True')\n            >>> import wbia\n            >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False],can_match_sameimg=True')\n        "
    import sklearn.metrics
    qaids = testres.get_test_qaids()
    ibs = testres.ibs
    PLOT = True
    PLOT = False
    cfgx2_cms = []
    for qreq_ in testres.cfgx2_qreq_:
        cm_list = qreq_.execute(qaids)
        cm_list = [cm.extend_results(qreq_) for cm in cm_list]
        for cm in cm_list:
            cm.score_annot_csum(qreq_)
        cfgx2_cms.append(cm_list)
    map_list = []
    (unique_names, groupxs) = ut.group_indices(ibs.annots(qaids).names)
    for (cm_list, qreq_) in zip(cfgx2_cms, testres.cfgx2_qreq_):
        if PLOT:
            import wbia.plottool as pt
            pt.qt4ensure()
            fnum = pt.ensure_fnum(None)
            pt.figure(fnum=fnum)
        avep_list = []
        for cm in cm_list:
            flags = (np.array(ibs.annots(cm.daid_list).quality_texts) != 'junk')
            assert np.all(flags)
            daid_list = cm.daid_list
            dnid_list = cm.dnid_list
            y_true = (cm.qnid == dnid_list).compress(flags).astype(np.int)
            y_score = cm.annot_score_list.compress(flags)
            y_score[(~ np.isfinite(y_score))] = 0
            y_score = np.nan_to_num(y_score)
            sortx = np.argsort(y_score)[::(- 1)]
            daid_list = daid_list.take(sortx)
            dnid_list = dnid_list.take(sortx)
            y_true = y_true.take(sortx)
            y_score = y_score.take(sortx)
            (precision, recall, thresholds) = sklearn.metrics.precision_recall_curve(y_true, y_score)
            if PLOT:
                pt.plot2(recall, precision, marker='', linestyle='-', x_label='recall', y_label='precision')
            avep = sklearn.metrics.average_precision_score(y_true, y_score)
            avep_list.append(avep)
        name_to_ave = [np.mean(a) for a in ut.apply_grouping(avep_list, groupxs)]
        name_to_ave_ = dict(zip(unique_names, name_to_ave))
        logger.info(('name_to_ave_ = %s' % ut.align(ut.repr3(name_to_ave_, precision=3), ':')))
        mean_ave_precision = np.mean(name_to_ave)
        logger.info(('mean_ave_precision = %r' % (mean_ave_precision,)))
        map_list.append(mean_ave_precision)
    return map_list
For each query compute a precision recall curve.
Then, for each query compute the average precision.
Then take the mean of all average precisions to obtain the mAP.

Script:
    >>> #ibs = wbia.opendb('Oxford')
    >>> #ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True]')
    >>> import wbia
    >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True],can_match_sameimg=True')
    >>> import wbia
    >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False],can_match_sameimg=True')
def map_score(testres):
    "\n        For each query compute a precision recall curve.\n        Then, for each query compute the average precision.\n        Then take the mean of all average precisions to obtain the mAP.\n\n        Script:\n            >>> #ibs = wbia.opendb('Oxford')\n            >>> #ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True]')\n            >>> import wbia\n            >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False,True],can_match_sameimg=True')\n            >>> import wbia\n            >>> ibs, testres = wbia.testdata_expts('Oxford', a='oxford', p='smk:nWords=[64000],nAssign=[1],SV=[False],can_match_sameimg=True')\n        "
    import sklearn.metrics
    qaids = testres.get_test_qaids()
    ibs = testres.ibs
    PLOT = True
    PLOT = False
    cfgx2_cms = []
    for qreq_ in testres.cfgx2_qreq_:
        cm_list = qreq_.execute(qaids)
        cm_list = [cm.extend_results(qreq_) for cm in cm_list]
        for cm in cm_list:
            cm.score_annot_csum(qreq_)
        cfgx2_cms.append(cm_list)
    map_list = []
    (unique_names, groupxs) = ut.group_indices(ibs.annots(qaids).names)
    for (cm_list, qreq_) in zip(cfgx2_cms, testres.cfgx2_qreq_):
        if PLOT:
            import wbia.plottool as pt
            pt.qt4ensure()
            fnum = pt.ensure_fnum(None)
            pt.figure(fnum=fnum)
        avep_list = []
        for cm in cm_list:
            flags = (np.array(ibs.annots(cm.daid_list).quality_texts) != 'junk')
            assert np.all(flags)
            daid_list = cm.daid_list
            dnid_list = cm.dnid_list
            y_true = (cm.qnid == dnid_list).compress(flags).astype(np.int)
            y_score = cm.annot_score_list.compress(flags)
            y_score[(~ np.isfinite(y_score))] = 0
            y_score = np.nan_to_num(y_score)
            sortx = np.argsort(y_score)[::(- 1)]
            daid_list = daid_list.take(sortx)
            dnid_list = dnid_list.take(sortx)
            y_true = y_true.take(sortx)
            y_score = y_score.take(sortx)
            (precision, recall, thresholds) = sklearn.metrics.precision_recall_curve(y_true, y_score)
            if PLOT:
                pt.plot2(recall, precision, marker=, linestyle='-', x_label='recall', y_label='precision')
            avep = sklearn.metrics.average_precision_score(y_true, y_score)
            avep_list.append(avep)
        name_to_ave = [np.mean(a) for a in ut.apply_grouping(avep_list, groupxs)]
        name_to_ave_ = dict(zip(unique_names, name_to_ave))
        logger.info(('name_to_ave_ = %s' % ut.align(ut.repr3(name_to_ave_, precision=3), ':')))
        mean_ave_precision = np.mean(name_to_ave)
        logger.info(('mean_ave_precision = %r' % (mean_ave_precision,)))
        map_list.append(mean_ave_precision)
    return map_list