def hellinger(Ks, dim, required, clamp=True, to_self=False):
bc = required<EOL>est = <NUM_LIT:1> - bc<EOL>np.maximum(est, <NUM_LIT:0>, out=est)<EOL>if clamp:<EOL><INDENT>np.minimum(est, <NUM_LIT:1>, out=est)<EOL><DEDENT>np.sqrt(est, out=est)<EOL>return est<EOL>
r'''
    Estimate the Hellinger distance between distributions, based on kNN
    distances:  \sqrt{1 - \int \sqrt{p q}}

    Always enforces 0 <= H, to be able to sqrt; if clamp, also enforces
    H <= 1.

    Returns a vector: one element for each K.