Distance metrics¶

Distance metrics¶

Several distance metrics not available in scipy are provided below.

metrics.hellinger(x, y)[source]

Computes the Hellinger distance between two sum-normalized vectors

$$d_h(x,y) = \frac{1}{2} \sqrt{\sum_{i} \left(\sqrt{x_i} - \sqrt{y_i}\right)^2}$$

Equivalently, for sum-normalized vectors

$$d_h(x,y) = 1 - \sum_{i} \left(\sqrt{x_i} - \sqrt{y_i}\right)$$

Parameters: x (ndarray) – The first vector y (ndarray) – The second vector hellinger(x,y) = np.sqrt( 1 - np.dot(np.sqrt(x),np.sqrt(y)) )
metrics.hellinger_hyp(x, y)[source]

Computes the hyperbolic Hellinger distance metric between two vectors

$d_{hy} = \log \left(\frac{1 + d_h}{1 - d_h}\right)$
Parameters: x (ndarray) – The first vector y (ndarray) – The second vector hellinger_hyp(x,y) = math.log( (1+hellinger(x,y))/(1 - hellinger(x,y)) )
metrics.jeffries(x, y)[source]

Computes the Jeffries divergence between two vectors

$d_{SKL}(x,y) = \frac{1}{2} \left( \sum_{i} \left( x_i - y_i \right) \log \frac{x_i}{y_i} \right)$
Parameters: x (ndarray) – The first vector y (ndarray) – The second vector jeffries(x,y) = (1/2) * ( entropy(x,y) + entropy(y,x) )
metrics.jensen(x, y)[source]

Computes the Jensen-Shannon metric between two vectors

$d^2_j = \sum_{i} \left( x_i \log_2 \frac{2x_i}{x_i + y_i} + y_i \log_2 \frac{2y_i}{x_i + y_i} \right)$
Parameters: x (ndarray) – The first vector y (ndarray) – The second vector jensen(x,y) = entropy(x,m) + entropy(y,m) where m = (1/2) * (x + y)
metrics.jensen_hyp(x, y)[source]

Computes the hyperbolic Jensen-Shannon metric between two vectors

$d_{hy} = \log \left(\frac{1 + d_j}{1 - d_j}\right)$
Parameters: x (ndarray) – The first vector y (ndarray) – The second vector jensen_hyp(x,y) = math.log( (1+jensen_distance(x,y))/(1 - jensen_distance(x,y)) )