def scaling_term(k, n):
    """Term that scales measure between zero and one
    k  size of the neighbourhood
    n  number of datapoints
    """
    if k < (n / 2.0):
        return 2.0 / ((n * k) * (2 * n - 3 * k - 1))
    else:
        return 2.0 / (n * (n - k) * (n - k - 1))