1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| d_2 = d.copy()**2
#print d_2
dist=np.zeros((960,8))
dist = d_2[:,:8]+d_2[:,8:]
idx = np.argmax(dist, axis=1)
dxn = d[:,:8]
for ix, shift in enumerate(idx):
dxn[ix,:] = np.roll( dxn[ix,:], shift)
print u"\nTableau 'shifte' :\n", dxn
dyn = d[:,8:]
for iy, shift in enumerate(idx):
dyn[iy,:] = np.roll( dyn[iy,:], shift)
print u"\nTableau 'shifte' :\n", dyn
dgranddis = np.concatenate([dxn,dyn],axis=1)
disgrandtab = np.zeros((960,960))
for zi in range(0,960):
vi = dgranddis[zi,:]
mi = dgranddis[(zi+1):,:]
ni = mi-vi
qi = ni**2
arrays = np.sum(qi[:,0:8]+qi[:,8:16],axis=1)
for zii in range(0, arrays.shape[0]):
disgrandtab[zi,zi+zii+1] = arrays[zii]
disgrandtab[zi+zii+1,zi] = arrays[zii]
print disgrandtab
plt.imshow(disgrandtab)
plt.show()
print disgrandtab.shape
################################################################## hirarchical clustering
import time as time
import mpl_toolkits.mplot3d.axes3d as p3
from sklearn.cluster import Ward
from sklearn.datasets.samples_generator import make_swiss_roll
#################
X = disgrandtab
#################
# Compute clustering
print "Compute unstructured hierarchical clustering..."
st = time.time()
ward = Ward(n_clusters=6).fit(X)
label = ward.labels_
#print label
print "Elapsed time: ", time.time() - st
print "Number of points: ", label.size
######################
# Plot result
fig = pl.figure()
ax = p3.Axes3D(fig)
ax.view_init(7, -80)
for l in np.unique(label):
ax.plot3D(X[label == l, 0], X[label == l, 1], X[label == l, 2],
'o', color=pl.cm.jet(np.float(l) / np.max(label + 1)))
pl.title('Without connectivity constraints')
pl.show() |
Partager