Sorting a matrix by similarity

跟風遠走 提交于 2020-12-11 05:10:16

问题


I have 100 matrices in which each row corresponds to an individual and column refers to sites. I want to sort the row by a measure of similarity such that the most similar individuals are next to each other in a matrix. I used k-nearest neighbours to sort the matrices by rows and I give these sorted matrices to a convolutional neural network. I want to know if there are other measures by which I can achieve the task in hand. The code I use for k-nearest neighbour is:

def sort_min_diff(amat):
    mb = NearestNeighbors(len(amat), metric='manhattan').fit(amat)
    v = mb.kneighbors(amat)
    smallest = np.argmin(v[0].sum(axis=1))
    return amat[v[1][smallest]]


X_snp = np.array(snp_matrix)

q = []
for i in range(len(X_snp)):
    q.append((sort_min_diff(X_snp[i])))

q = np.array(q)

My X_snp matrix is of shape (100,60,4500) that is I have 100 such matrices. Also, my matrices are filled with 0 and 1. Suggestions would be appreciated.

来源:https://stackoverflow.com/questions/55452586/sorting-a-matrix-by-similarity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!