5
$\begingroup$

I have two sets of points, $X$ and $Y$, which are finite and disjoint. I want to compute the distance between them defined by: $$d(X,Y)= \frac{\sum_{x \in X} \|x-Y\| + \sum_{y \in Y} \|y-X\|}{|x|+|y|} $$ where $\|x-Y\|$ represents the distance between the point $x$ in $X$ to its closest point in $Y$, and $|x|$, $|y|$ are the cardinalities of $X$ and $Y$ respectively.

Since both sets are large, the above formula is computationally expensive. How can I calculate it or bound it efficiently?

$\endgroup$
4
  • $\begingroup$ @MattF. Thanks for your help and the edit. I wrote to bound in the original question because it is hard to compute the distance exactly and an algorithm should be used to approximate or bound the distance. Hope it is clear? $\endgroup$
    – Flore
    Commented Jun 29, 2021 at 12:49
  • $\begingroup$ @MattF. As you know, the distance above is used as a metric to compare the similarity between two sets in neural networks. Unfortunately, I can't compute it exactly because of the amount of points since it needs to to search for the closest neighbor in Y for each point in X and to do the same again for each point in Y. Consequently, I am looking in literature for efficient methods to find the nearest neighbor in order to use them and to bound the distances above. $\endgroup$
    – Flore
    Commented Jun 29, 2021 at 13:01
  • $\begingroup$ @MattF. So the most important and interesting is to find a known efficient method to find the nearest neighbor for all points in huge sets then I can work on the bound for the distance $\endgroup$
    – Flore
    Commented Jun 29, 2021 at 13:04
  • $\begingroup$ If all you want is a bound from above, then let $p$ be the minimum of $X\cup Y$ (i.e. the first coordinate of $p$ is the minimum of all the first coordinates), and let $q$ be the maximum, and the distance between $p$ and $q$ provides an upper bound. $\endgroup$
    – user44143
    Commented Jun 29, 2021 at 14:00

1 Answer 1

4
$\begingroup$

Let $d(x,Y):=\min\{\|x-y\|\colon y\in Y\}$ and $d(y,X):=\min\{\|y-x\|\colon x\in X\}$. Then $$d(X,Y)=(1-w)d_X(Y)+wd_Y(X),$$ where $$w:=\frac{|Y|}{|X|+|Y|},$$ $|X|$ and $|Y|$ are the cardinalities of $X$ and $Y$, respectively, and $$d_X(Y):=\frac1{|X|}\sum_{x\in X}d(x,Y)\quad\text{and}\quad d_Y(X):=\frac1{|Y|}\sum_{y\in Y}d(y,X)$$ are the average distances from $X$ to $Y$ and from $Y$ to $X$, respectively.

Let $X_1$ and $Y_1$ be (say random) subsets of $X$ and $Y$, respectively, of large but not overly large sizes. Then, obviously, $d(x,Y)\le d(x,Y_1)$ for all $x$ and hence $d_X(Y)\le d_X(Y_1)$. Similarly, $d_Y(X)\le d_Y(X_1)$. So, $$d(X,Y)\le(1-w)d_X(Y_1)+wd_Y(X_1).$$ One could also take some large enough (say random) subsets $X_2$ and $Y_2$ of $X$ and $Y$ such that $w_2:=\frac{|Y_2|}{|X_2|+|Y_2|}\approx w$ and thus get a presumably upper estimate $$(1-w_2)d_{X_2}(Y_1)+w_2d_{Y_2}(X_1)$$ of $d(X,Y)$.

These methods should work well if $X$ and $Y$ are well enough separated from each other on an average and if $w$ is known or can be estimated well enough.

$\endgroup$
3
  • $\begingroup$ Many thanks for your efforts. If I understand your work correctly, I think your method to compute the distance will also be computationally expensive as it needs additionally to calculate the distance between a huge number of points $x$ in $X$ to their nearest neighbors in $Y$. Apart from this, I don't understand why it is obvious that $d(x,Y) \leq d(x,Y_1)$? if the random set $Y_1$ contains the closest values of $Y$ to $X$ then $d(x,Y) \geq d(x,Y_1)$! Am I missing something? $\endgroup$
    – Flore
    Commented Jun 30, 2021 at 8:59
  • $\begingroup$ @Flore : (i) "your method to compute the distance will also be computationally expensive as it needs additionally to calculate the distance between a huge number of points $x$ in $X$ to their nearest neighbors in $Y$. -- No, you only need to compute the nearest distance from the points in $X_2$ to $Y_1$ and from the points in $X_1$ to $Y_2$, and you can take these subsets of $X$ and $Y$ as moderate as you like (albeit paying the unavoidable price of lesser accuracy for the gain in the efficiency.) $\endgroup$ Commented Jun 30, 2021 at 12:43
  • $\begingroup$ @Flore : (ii) "why it is obvious that $d(x,Y)\le d(x,Y_1)$?" -- Because the minimum of any function over a subset $Y_1$ of $Y$ is always no less than the minimum of that function over the entire finite set $Y$. (iii) "if the random set $Y_1$ contains the closest values of $Y$ to $X$ then $d(x,Y)\ge d(x,Y_1)$!" -- If $Y_1$ contains the closest values of $Y$ to $x$ then $d(x,Y)=d(x,Y_1)$, so that $d(x,Y)\le d(x,Y_1)$ holds. $\endgroup$ Commented Jun 30, 2021 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .