import math


def _compute_dcg(s, k):
    """
    A function to compute dcg
    :param s: sequence of ground truth in the rank order to use for calculating dcg
    :param k: top k at which to evaluate ndcg
    :return: dcg for this ordering of ground truth
    :rtype: numeric
    """
    dcg = 0.0
    for i in range(min(k, len(s))):
        dcg += (math.pow(2, s[i]) - 1) / math.log(i + 2, 2)
    return dcg