// Non-transitive: count comparisons only across immediate levels
ref_rank = np.equal.outer(ref_score, ref_score + 1)
est_rank = np.greater.outer(est_score, est_score)
// Don"t count the query as a result
// when query < window, query itself is the index within the slice
// otherwise, query is located at the center of the slice, window
// (this also holds when the slice goes off the end of the array.)
idx = min(query, window)
ref_rank[idx, :] = False
ref_rank[:, idx] = False
// Compute normalization constant
normalizer = float(ref_rank.sum())
// Add up agreement for frames
if normalizer > 0:
score += np.sum(np.logical_and(ref_rank, est_rank)) / normalizer
num_frames += 1
// Normalize by the number of frames counted.
// If no frames are counted, take the convention 0/0 -> 0