已知mAP代码怎么写Precision和recall的代码啊

已知mAP代码怎么写Precision和recall的代码啊


def calc_map(qB, rB, query_L, retrieval_L):
    # qB:查询集  范围{-1,+1}
    # rB:检索集  范围{-1,+1}
    # query_label: 查询标签
    # retrieval_label: 检索标签
    num_query = query_L.shape[0]
    map = 0
    for iter in xrange(num_query):
        gnd2 = (np.dot(query_L[iter, :], retrieval_L.transpose()) > 0).astype(np.float32)
        hamm = calc_hammingDist(qB[iter, :], rB)
        aaa = np.arange(0,retrieval_L.shape[0])
        ind = np.lexsort((aaa,hamm))
        gnd = gnd2[ind[:]]
        tsum = np.sum(gnd)
        if tsum == 0:
            continue
        count = np.linspace(1, int(tsum), int(tsum))

        tindex = np.asarray(np.where(gnd == 1)) + 1.0
        map = map + np.mean(count / (tindex))
    map = map / num_query
    return map