This repository implements the distance measure metric: DIEM.
source: https://arxiv.org/abs/2407.08623
Note: Please cite the original paper.
Please feel free to suggest code & math fixes if found.
make all
For the full proof refer: Euclidean Distance: Expectation, Variance & Std. Deviation
The normalized Euclidean distance ( D_{\text{norm}}(\mathbf{X}, \mathbf{Y}) ) is computed as follows:
[ D_{\text{norm}}(\mathbf{X}, \mathbf{Y}) = \frac{D(\mathbf{X}, \mathbf{Y}) - \mathbb{E}[D(\mathbf{X}, \mathbf{Y})]}{\sigma(D(\mathbf{X}, \mathbf{Y}))} ]
Where:
The DIEM
function computes the normalized Euclidean distance between two tensors, accounting for the dimensionality of the input vectors, which ensures that the distance metric remains robust and interpretable in high-dimensional spaces. The function accepts the following arguments:
source
: The source tensor of shape (N, D)
.target
: The target tensor of shape (M, D)
.v_max
: Maximum element value of the tensors.v_min
: Minimum element value of the tensors.
import torch
from diem import DIEM
# Example tensors
source = torch.rand(100, 50) # 100 vectors of dimension 50
target = torch.rand(200, 50) # 200 vectors of dimension 50
# Compute DIEM distance
diem_distance = DIEM(source, target)
print(diem_distance)