def pair_distance_centile(X, centile, max_pairs=<NUM_LIT>):
N = X.shape[<NUM_LIT:0>]<EOL>n_pairs = min(max_pairs, N**<NUM_LIT:2>)<EOL>dists = np.zeros(n_pairs)<EOL>for i in range(n_pairs):<EOL><INDENT>pair = np.random.randint(<NUM_LIT:0>, N, <NUM_LIT:2>)<EOL>pairdiff = X[pair[<NUM_LIT:0>], :]-X[pair[<NUM_LIT:1>], :]<EOL>dists[i] = np.dot(pairdiff, pairdiff.T)<EOL><DEDENT>dists.sort()<EOL>out = dists[int(n_pairs*centile/<NUM_LIT>)]<EOL>return np.sqrt(out)<EOL>
Calculate centiles of distances between random pairs in a dataset.

This an alternative to the median kNN distance for setting the kernel
length scale.