— found the difference between my code and the code in R.

needs to add row standardization for the inverse distance matrix.

But I’m thinking about another way to use a “fake matrix” to imitate the matrix structure to save RAM and speed up computation.