function inversMDS(dataHDpart, data2Dnew){
let MAX = 500;
let col = dataHDpart[0].length;
let row = dataHDpart.length;
let curWeights = Array(col).fill(1/col);
let newWeights = Array(col).fill(1/col);
let flag = Array(col).fill(0);
let direction = Array(col).fill(1);
let step = Array(col).fill(1/col);
let dataHDw = apply_weights(dataHDpart, curWeights);
let distHD = pairwise_distance(dataHDw, "manhattan");
let curStress = stress(distHD, dist2D);
for(let i = 0; i < MAX; ++i){
for (let dim = 0; dim < col; dim++) {
let nw = new_proposal(curWeights[dim], step[dim], direction[dim]);
let s = 1 + nw - curWeights[dim]
for (let index = 0; index < curWeights.length; index++) {
let temp = curWeights[index]/s;
newWeights[index] = curWeights[index]/s;
}
newWeights[dim] = nw/s;
dataHDw = apply_weights(dataHDpart, newWeights);
distHD = pairwise_distance(dataHDw, "manhattan");
let newStress = stress(distHD, dist2D);
if (newStress < curStress){
let temp = curWeights;
curWeights = newWeights;
newWeights = temp;
curStress = newStress;
flag[dim] = flag[dim] + 1;
}
else {
flag[dim] = flag[dim] - 1;
direction[dim] = -direction[dim];
}
if (flag[dim] >= 5){
step[dim] = step[dim] * 2;
flag[dim] = 0;
}
else if (flag[dim] <= -5) {
step[dim] = step[dim] / 2;
flag[dim] = 0;
}
}
}
return curWeights;
}