<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _compare_frame_rankings(ref, est, transitive=False):
    '''Compute the number of ranking disagreements in two lists.

    Parameters
    ----------
    ref : np.ndarray, shape=(n,)
    est : np.ndarray, shape=(n,)
        Reference and estimate ranked lists.
        `ref[i]` is the relevance score for point `i`.

    transitive : bool
        If true, all pairs of reference levels are compared.
        If false, only adjacent pairs of reference levels are compared.

    Returns
    -------
    inversions : int
        The number of pairs of indices `i, j` where
        `ref[i] < ref[j]` but `est[i] >= est[j]`.

    normalizer : float
        The total number of pairs (i, j) under consideration.
        If transitive=True, then this is |{(i,j) : ref[i] < ref[j]}|
        If transitive=False, then this is |{i,j) : ref[i] +1 = ref[j]}|
    '''

    idx = np.argsort(ref)
    ref_sorted = ref[idx]
    est_sorted = est[idx]

    # Find the break-points in ref_sorted
    levels, positions, counts = np.unique(ref_sorted,
                                          return_index=True,
                                          return_counts=True)

    positions = list(positions)
    positions.append(len(ref_sorted))

    index = collections.defaultdict(lambda: slice(0))
    ref_map = collections.defaultdict(lambda: 0)

    for level, cnt, start, end in zip(levels, counts,
                                      positions[:-1], positions[1:]):
        index[level] = slice(start, end)
        ref_map[level] = cnt

    # Now that we have values sorted, apply the inversion-counter to
    # pairs of reference values
    if transitive:
        level_pairs = itertools.combinations(levels, 2)
    else:
        level_pairs = [(i, i+1) for i in levels]

    level_pairs, lcounter = itertools.tee(level_pairs)

    normalizer = float(sum([ref_map[i] * ref_map[j] for (i, j) in lcounter]))

    if normalizer == 0:
        return 0, 0.0

    inversions = 0

    for level_1, level_2 in level_pairs:
        inversions += _count_inversions(est_sorted[index[level_1]],
                                        est_sorted[index[level_2]])

    return inversions, float(normalizer)