spd_learn.functional.distance_kullback#

spd_learn.functional.distance_kullback(A, B, squared=False)[source]#

Kullback-Leibler divergence between SPD/HPD matrices.

The left Kullback-Leibler divergence between two SPD/HPD matrices \(\mathbf{A}\) and \(\mathbf{B}\) is [1]:

\[d(\mathbf{A},\mathbf{B}) = \frac{1}{2} \left( \text{tr}(\mathbf{B}^{-1}\mathbf{A}) - n + \log \left( \frac{\det(\mathbf{B})}{\det(\mathbf{A})}\right) \right)\]
Parameters:
  • A (ndarray, shape (..., n, n)) – First SPD/HPD matrices.

  • B (ndarray, shape (..., n, n)) – Second SPD/HPD matrices, same dimensions as A.

  • squared (bool, default=False) –

    Return squared distance.

    Added in version 0.5.

Returns:

d – Left Kullback-Leibler divergence between A and B.

Return type:

float or ndarray, shape (…,)

Notes

Changed in version 0.12: Add support for NumPy and PyTorch.

See also

distance

References

[1]

On information and sufficiency S. Kullback S, R. Leibler. The Annals of Mathematical Statistics, 1951, 22 (1), pp. 79-86