Generating vertices of a simplex

For a model I’ve been working on I needed to generate points (cluster centres) that were located equidistant from each other. Not a terribly hard problem, but I happen to come across this answer on mathoverflow that I found pretty neat. I readily admit that I don’t understand exactly how it works, but here is the equivalent julia code:

"""
Return the vertices of a regular simplex in `n` dimenions.
"""
function get_simplex_vertices(n)
    q,r = qr(fill(1.0, n+1))
    points = permutedims(q[:,2:end],[2,1])
    #rescale so that the distance is 1
    points ./= sqrt(2)
end

Just thought I’d put it out there in case anyone else finds it useful at some point.

q,r = qr(fill(1.0, n+1))

  • q is a unitary matrix, with the first column having constant entries (n+1)^{-1/2}
  • All columns of q are pairwise orthogonal, and of norm 1.
  • Let c_1, c_2 be two columns, since they are orthogonal, dist(c_1,c_2)= \sqrt{1+1}=\sqrt{2}

points ./= sqrt(2)

  • Thus the above line is just to make sure that the pair-wise distances are 1.

I don’t think dropping the first column is special, you could drop any of the columns.

1 Like

Thanks for the explanation! Now it makes sense : )