2 updated to reflect TIO update

# R, score = 4.708859

require(vegan)
solve_mmds<-function(dpf,noise=0,wgs=rep(1,nrow(dpf))){
#MMDS

#center on first point
v = sweep(v,2,v[1,])

alpha = atan2(v[,2],v[,1])
alpha_rot = alpha - alpha

if(v[3,2]<0){
v[,2]=-v[,2]
}

#return
v
}

N_input = length(input_data)
err_runs = rep(0,N_input)

for(i_input in c(1:N_input)){

p = matrix(input_data[[i_input]],ncol=2,byrow=TRUE)
n = nrow(p)

dp = as.matrix(dist(p,upper=TRUE,diag=TRUE))
dpf = floor(dp)

v = solve_mmds(dpf)
err_runs[i_input] = mean(apply( (p-v)^2, 1, sum))

cat("test #", i_input," MSE:", err_runs[i_input],"\n")
}

cat("Average error: ", mean(err_runs)," \n")


Have a look at the code online, but cannot runTry it :(online

The core of the program is based on the Metric Multi-Dimensional Scaling (MDS) approach, which solves precisely the problem described by the OP. The idea is to start from a collection of dissimilarities between entities and infer the coordinates of the system. Some post-processing is required to rotate, translate and flip the solution.

There are at least three functions available in R to perform MDS. There is also one in sklearn in Python, in case. In the code above I settled for the weighted mds variant (function wcmdscale), mostly due to the possibility to add weights and to a slightly better performing correction for negative eigenvalues. There is a core function in R, called cmdscale, which could be used instead, and would result in a score of 5.77.

The code provided is predisposed to accept weights, as well as noise in the floored distance matrix. After testing, it seemed best to not use any of these options.

Sadly, the package "vegan" is not availableSadly, the package "vegan" is not available on TIO. So, no live demonstration: my apologies for this inconvenience. Works on TIO. So, no live demonstration: my apologies for this inconvenience like a charm.

Interestingly, the program significantly underperforms on the last two examples. Adding noise can help, but it worsens the performance on every other test case. It would be interesting to find out what makes these two test cases particularly difficult.

# R, score = 4.708859

require(vegan)
solve_mmds<-function(dpf,noise=0,wgs=rep(1,nrow(dpf))){
#MMDS

#center on first point
v = sweep(v,2,v[1,])

alpha = atan2(v[,2],v[,1])
alpha_rot = alpha - alpha

if(v[3,2]<0){
v[,2]=-v[,2]
}

#return
v
}

N_input = length(input_data)
err_runs = rep(0,N_input)

for(i_input in c(1:N_input)){

p = matrix(input_data[[i_input]],ncol=2,byrow=TRUE)
n = nrow(p)

dp = as.matrix(dist(p,upper=TRUE,diag=TRUE))
dpf = floor(dp)

v = solve_mmds(dpf)
err_runs[i_input] = mean(apply( (p-v)^2, 1, sum))

cat("test #", i_input," MSE:", err_runs[i_input],"\n")
}

cat("Average error: ", mean(err_runs)," \n")


Have a look at the code online, but cannot run it :(

The core of the program is based on the Metric Multi-Dimensional Scaling (MDS) approach, which solves precisely the problem described by the OP. The idea is to start from a collection of dissimilarities between entities and infer the coordinates of the system. Some post-processing is required to rotate, translate and flip the solution.

There are at least three functions available in R to perform MDS. There is also one in sklearn in Python, in case. In the code above I settled for the weighted mds variant (function wcmdscale), mostly due to the possibility to add weights and to a slightly better performing correction for negative eigenvalues. There is a core function in R, called cmdscale, which could be used instead, and would result in a score of 5.77.

The code provided is predisposed to accept weights, as well as noise in the floored distance matrix. After testing, it seemed best to not use any of these options.

Sadly, the package "vegan" is not available on TIO. So, no live demonstration: my apologies for this inconvenience.

Interestingly, the program significantly underperforms on the last two examples. Adding noise can help, but it worsens the performance on every other test case. It would be interesting to find out what makes these two test cases particularly difficult.

# R, score = 4.708859

require(vegan)
solve_mmds<-function(dpf,noise=0,wgs=rep(1,nrow(dpf))){
#MMDS

#center on first point
v = sweep(v,2,v[1,])

alpha = atan2(v[,2],v[,1])
alpha_rot = alpha - alpha

if(v[3,2]<0){
v[,2]=-v[,2]
}

#return
v
}

N_input = length(input_data)
err_runs = rep(0,N_input)

for(i_input in c(1:N_input)){

p = matrix(input_data[[i_input]],ncol=2,byrow=TRUE)
n = nrow(p)

dp = as.matrix(dist(p,upper=TRUE,diag=TRUE))
dpf = floor(dp)

v = solve_mmds(dpf)
err_runs[i_input] = mean(apply( (p-v)^2, 1, sum))

cat("test #", i_input," MSE:", err_runs[i_input],"\n")
}

cat("Average error: ", mean(err_runs)," \n")


Try it online

The core of the program is based on the Metric Multi-Dimensional Scaling (MDS) approach, which solves precisely the problem described by the OP. The idea is to start from a collection of dissimilarities between entities and infer the coordinates of the system. Some post-processing is required to rotate, translate and flip the solution.

There are at least three functions available in R to perform MDS. There is also one in sklearn in Python, in case. In the code above I settled for the weighted mds variant (function wcmdscale), mostly due to the possibility to add weights and to a slightly better performing correction for negative eigenvalues. There is a core function in R, called cmdscale, which could be used instead, and would result in a score of 5.77.

The code provided is predisposed to accept weights, as well as noise in the floored distance matrix. After testing, it seemed best to not use any of these options.

Sadly, the package "vegan" is not available on TIO. So, no live demonstration: my apologies for this inconvenience. Works on TIO like a charm.

Interestingly, the program significantly underperforms on the last two examples. Adding noise can help, but it worsens the performance on every other test case. It would be interesting to find out what makes these two test cases particularly difficult.

1

# R, score = 4.708859

require(vegan)
solve_mmds<-function(dpf,noise=0,wgs=rep(1,nrow(dpf))){
#MMDS

#center on first point
v = sweep(v,2,v[1,])

alpha = atan2(v[,2],v[,1])
alpha_rot = alpha - alpha

if(v[3,2]<0){
v[,2]=-v[,2]
}

#return
v
}

N_input = length(input_data)
err_runs = rep(0,N_input)

for(i_input in c(1:N_input)){

p = matrix(input_data[[i_input]],ncol=2,byrow=TRUE)
n = nrow(p)

dp = as.matrix(dist(p,upper=TRUE,diag=TRUE))
dpf = floor(dp)

v = solve_mmds(dpf)
err_runs[i_input] = mean(apply( (p-v)^2, 1, sum))

cat("test #", i_input," MSE:", err_runs[i_input],"\n")
}

cat("Average error: ", mean(err_runs)," \n")


Have a look at the code online, but cannot run it :(

The core of the program is based on the Metric Multi-Dimensional Scaling (MDS) approach, which solves precisely the problem described by the OP. The idea is to start from a collection of dissimilarities between entities and infer the coordinates of the system. Some post-processing is required to rotate, translate and flip the solution.

There are at least three functions available in R to perform MDS. There is also one in sklearn in Python, in case. In the code above I settled for the weighted mds variant (function wcmdscale), mostly due to the possibility to add weights and to a slightly better performing correction for negative eigenvalues. There is a core function in R, called cmdscale, which could be used instead, and would result in a score of 5.77.

The code provided is predisposed to accept weights, as well as noise in the floored distance matrix. After testing, it seemed best to not use any of these options.

Sadly, the package "vegan" is not available on TIO. So, no live demonstration: my apologies for this inconvenience.

Interestingly, the program significantly underperforms on the last two examples. Adding noise can help, but it worsens the performance on every other test case. It would be interesting to find out what makes these two test cases particularly difficult.