def get_proportion_nns_with_same_coarse_codes(data, model, nns=None):
    """
    """
    N = data.shape[0]

    # Compute nearest neighbors if not provided
    if nns is None:
        nns = compute_all_neighbors(data)

    # Compute coarse codes for data
    coarse_codes = []
    for d in data:
        c = model.predict_coarse(d)
        coarse_codes.append(c)

    # Count the number of NNs that share the same coarse codes
    count = 0
    for i in xrange(N):
        nn = nns[i]
        if coarse_codes[i] == coarse_codes[nn]:
            count += 1

    return float(count) / N
dataset/ETHPy150Open yahoo/lopq/python/lopq/eval.py/get_proportion_nns_with_same_coarse_codes/original