code: function constrainedMDSGradient(x, fxprime, distances, constraints) {
          var loss = 0, i;
          for (i = 0; i < fxprime.length; ++i) {
              fxprime[i] = 0;
          }
  
          for (i = 0; i < distances.length; ++i) {
              var xi = x[2 * i], yi = x[2 * i + 1];
              for (var j = i + 1; j < distances.length; ++j) {
                  var xj = x[2 * j], yj = x[2 * j + 1],
                      dij = distances[i][j],
                      constraint = constraints[i][j];
  
                  var squaredDistance = (xj - xi) * (xj - xi) + (yj - yi) * (yj - yi),
                      distance$$1 = Math.sqrt(squaredDistance),
                      delta = squaredDistance - dij * dij;
  
                  if (((constraint > 0) && (distance$$1 <= dij)) ||
                      ((constraint < 0) && (distance$$1 >= dij))) {
                      continue;
                  }
  
                  loss += 2 * delta * delta;
  
                  fxprime[2*i]     += 4 * delta * (xi - xj);
                  fxprime[2*i + 1] += 4 * delta * (yi - yj);
  
                  fxprime[2*j]     += 4 * delta * (xj - xi);
                  fxprime[2*j + 1] += 4 * delta * (yj - yi);
              }
          }
          return loss;
      }
docs: / computes the gradient and loss simulatenously for our constrained MDS optimizer