Created
July 3, 2017 12:30
-
-
Save Pseudomanifold/2b1490f9447c1435d890f9960782a7fe to your computer and use it in GitHub Desktop.
A simple example script that embeds a matrix of distances into 2D using MDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Embeds a distance matrix into 2D using MDS. Distances are normalized | |
# to [0,1] in order to facilitate comparing embedded matrices. | |
import numpy | |
import sys | |
from sklearn.manifold import MDS | |
M = numpy.loadtxt(sys.argv[1]) | |
M = ( M - M.min() ) / ( M.max() - M.min() ) | |
mds = MDS(dissimilarity="precomputed", n_init=10, eps=1e-9, max_iter=3000) | |
points = mds.fit_transform(M) | |
for point in points: | |
x,y = point | |
print(x,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment