def test_zhang(): xyz1 = np.array([[0,0,0],[1,0,0],[2,0,0],[3,0,0]]) xyz2 = np.array([[0,1,1],[1,0,1],[2,3,-2]]) # dm=array([[ 2, 2, 17], [ 3, 1, 14], [6, 2, 13], [11, 5, 14]]) # this is the distance matrix between points of xyz1 # and points of xyz2 zd = tm.zhang_distances(xyz1,xyz2) # {'average_mean_closest_distance': 3.9166666666666665, # 'maximum_mean_closest_distance': 5.333333333333333, # 'minimum_mean_closest_distance': 2.5} yield assert_almost_equal, zd['average_mean_closest_distance'], \ 1.76135602742
def test_zhang_distances(): xyz1 = np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [3, 0, 0]]) xyz2 = np.array([[0, 1, 1], [1, 0, 1], [2, 3, -2]]) # dm=array([[ 2, 2, 17], [ 3, 1, 14], [6, 2, 13], [11, 5, 14]]) # this is the distance matrix between points of xyz1 # and points of xyz2 zd = tm.zhang_distances(xyz1, xyz2) # {'average_mean_closest_distance': 3.9166666666666665, # 'maximum_mean_closest_distance': 5.333333333333333, # 'minimum_mean_closest_distance': 2.5} yield assert_almost_equal, zd[0], 1.76135602742 xyz1 = xyz1.astype('float32') xyz2 = xyz2.astype('float32') zd2 = pf.zhang_distances(xyz1, xyz2) yield assert_almost_equal, zd2[0], 1.76135602742
def merge(C,thr): k=C.keys() #print 'k', k to_be_deleted=np.zeros(len(k)) if len(k)<=1: return C for i in range(1,len(k)-1): c=k[i] for j in range(i+1,len(k)): h=k[j] #print i,j t1=C[c]['rep3']/C[c]['N'] t2=C[h]['rep3']/C[h]['N'] #print 'yo',tm.zhang_distances(t1,t2,'avg') if tm.zhang_distances(t1,t2,'avg') < thr: C[h]['indices']+=C[c]['indices'] C[h]['N']+=C[c]['N'] C[h]['rep3']+=C[c]['rep3'] to_be_deleted[i]=1 for i in np.where(to_be_deleted>0)[0]: del C[k[i]] return C