KanishkNavale / DIEM

Dimension Insensitive Euclidean Metric (DIEM)
GNU Affero General Public License v3.0
0 stars 0 forks source link

DIEM: Dimension Insensitive Euclidean Metric (DIEM)

This repository implements the distance measure metric: DIEM.

source: https://arxiv.org/abs/2407.08623

Note: Please cite the original paper.

Development

Please feel free to suggest code & math fixes if found.

make all

Proof

For the full proof refer: Euclidean Distance: Expectation, Variance & Std. Deviation

Proposed Fix: Normalized Euclidean Distance Formula

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:

Usage

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:

Example


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)