Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #Get similarity matrix all_cc, which is a list of list, where all_cc[i][j] is the correlation coefficient between data i and j. It is an upper trangular matrix.
  2. ...
  3. #to use hierarchy module, condensed distance matrix should be available.
  4.  
  5. nmodel=10000
  6. q=lambda i,j,n: i*n+j-i*(i+1)/2-i-1
  7. condensed_cc=[0]*int(nmodel*(nmodel-1)/2)
  8. for i in range(nmodel-1):
  9. for j in range(i+1,nmodel):
  10. index=int(q(i,j,nmodel)):
  11. condensed_cc[index]=all_cc[i][j]
  12.  
  13. numpy.save("cc10000",condensed_cc)
  14.  
  15. condensed_cc=numpy.load("condensed_cc")
  16. #get condensed distance matrix using formula distance=1-c.c.
  17. condensed_dist=1-condensed_cc
  18. #cluster
  19. z=linkage(condensed_dist, 'average', 'correlation')
  20. nc=500 #number of groups
  21. f=fcluster(z,nc,'maxclust')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement