Formalisation of distance algorithm

22 Views Asked by At

I am trying to formalise a small algorithm and I have difficulties writing it in mathematical terms properly.

I have a vector $d$ with $d = 1, \dots, N$ and a vector $c$ with $c = 1, \dots, C$.

What my algorithm is doing is to compute a distance matrix one $d$ at a time, recursively.

I would like to express the idea of

$dist(d_{i},c_{j})$

one $d_{i}$ at a time.

In the end I end up with a matrix ($M = N \times C$).

For instance, would the following notation be correct to express this idea

\begin{equation} M = \sum_{i=1}^{N}\sum_{j=1}^{C} dist(i,j) \end{equation}

From a programming point of view, it is simply

for (i in 1:N) {
  for (j in 1:C){
    mat[i,j] =  dist( t[i], c[j] )
  }
}

Does the sign $\sum$ denotes directly for i in ...? And does the order of the sign $\sum$ matter formally, like it matter in the programming example?

Thank you.

1

There are 1 best solutions below

2
On

$\sum$ means "sum". What you seem to miss here is a proper way to handle indices.

Let's make a parallel with informatic :

  • A vector in $\mathbb{R}^n$ corresponds to a (one dimensional) float array of length $n$. Say this vector is $v$, one writes $v_i$ for the $i$th component of $v$, this corresponds to $v$[$i$] in most computer languages.
  • A $M\times N$ matrix corresponds to a (two dimensional) float array of shape $(M,N)$.
  • In math, the "for" is often implicit. For example, if we want a vector $v$ whose components are the square of numbers up to 10, one will write $$v:=(i^2)_{1\leqslant i \leqslant 10}$$

Likewise for matrices, in your case the matrix will be written $$M := (dist(t_i,c_j))_{{1 \leqslant i \leqslant N},\,{1\leqslant j \leqslant C}}$$