cv_euclidean#

mvpy.math.cv_euclidean(x: ndarray | Tensor, y: ndarray | Tensor) ndarray | Tensor[source]#

Computes cross-validated euclidean distances between vectors in x and y.

Parameters:
xUnion[np.ndarray, torch.Tensor]

Tensor ([[samples x ]samples x ]features)

yUnion[np.ndarray, torch.Tensor]

Tensor ([[samples x ]samples x ]features)

Returns:
Union[np.ndarray, torch.Tensor]

Cross-validated distances

Notes

Cross-validated euclidean distances are defined as:

\[d(x, y)^2 = \sum (x_{i} - y_{i})(x_{j} - y_{j})\]

where \(i\) and \(j\) refer to the indices in the cross-validation folds. Note that this is, therefore, technically a squared measure. For more information, see [1].

References

[1]

Walther, A., Nili, H., Ejaz, N., Alink, A., Kriegeskorte, N., & Diedrichsen, J. (2016). Reliability of dissimilarity measures for multi-voxel pattern analysis. NeuroImage, 137, 188-200. 10.1016/j.neuroimage.2015.12.012

Examples

>>> import torch
>>> from mvpy.math import cv_euclidean
>>> x = torch.randn(100, 10)
>>> y = torch.randn(100, 10)
>>> d = cv_euclidean(x, y)
>>> d.shape
torch.Size([100])