Skip to main content
. 2024 Aug 14;24(16):5265. doi: 10.3390/s24165265
Algorithm 2 Expanded Computation of Euclidean Distance Matrix
  • 1:

    Input: XRd×n

  • 2:

    GZeroMatrix(n,n)            ▹ Initialize the Gram matrix

  • 3:

    for i=1 to n do

  • 4:

        for j=1ton do

  • 5:

            G[i,j]k=1dX[k,i]×X[k,j]      ▹ Compute the Gram matrix

  • 6:

        end for

  • 7:

    end for

  • 8:

    DZeroMatrix(n,n)           ▹ Initialize the distance matrix

  • 9:

    for i=1 to n do

  • 10:

        for j=1ton do

  • 11:

            D[i,j]G[i,i]+G[j,j]2×G[i,j]   ▹ Compute the distance matrix

  • 12:

        end for

  • 13:

    end for

  • 14:

    Output: D