I am calculating the Euclidean distances of a few pairs feature vectors $p, q$. Usually, I get distances in the range $[0, 2]$ however I've had some occasions (outliers) when the distance was more than $2$. I want to find a similarity metric between that depends on the distance between the two vectors and differentiates the distances considerably ranging in this range. For instance, something like

$$\frac{1}{1+dist(p, q)}$$



Although it doesn't give that much 'spread' I would hope for. How can I generate a function that gives the most spread for $[0,2]$ but at the same time maintains that for any distance, it is between $0$ and $1$?


An example of such similarity would be, for a given small $\epsilon >0$, the similarity score is $\in [\epsilon, 1]$ when $dist(p,q)\in [0,2]$ and $ \in [0, \epsilon]$ when $dist(p, q)\in [2, +\infty]$.


You can use the Gaussian function: $e^{-||p - q||^2 / 2\sigma^2}$. Whenever the distance (in the exponent) is 0, the result is 1. Larger distances result in smaller results, and the decreasing speed is controlled by the variance $\sigma^2$. Just set it according to your problem to get a reasonable range of values and achieve your desired spread.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.