'Computes Average precision and precision at 50.'

def ScoreOneLabel(self, preds, targets):

    targets_sorted = targets[(- preds.T).argsort().flatten(), :]
    cumsum = targets_sorted.cumsum()
    prec = (cumsum / np.arange(1.0, (1 + targets.shape[0])))
    total_pos = float(sum(targets))
    if (total_pos == 0):
        total_pos = 1e-10
    recall = (cumsum / total_pos)
    ap = (np.dot(prec, targets_sorted) / total_pos)
    prec50 = prec[50]
    return (ap, prec50)
