Advertisement
qtinio

Untitled

Nov 8th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from minisom import MiniSom
  4. from mpl_toolkits.mplot3d import Axes3D
  5. from skimage import measure
  6.  
  7. with open("benc.txt") as f:
  8. data = [[float(i) for i in linia.split()] for linia in f]
  9.  
  10. data = np.reshape(data, (699, 9))
  11. data /= np.max(data)
  12.  
  13. som = MiniSom(40, 40, 9, sigma=0.6, learning_rate=0.5, random_seed=13)
  14. som.train_batch(data, 1000)
  15.  
  16.  
  17. distMap = som.distance_map().T
  18. plt.pcolor(distMap, cmap='afmhot')
  19. plt.show()
  20.  
  21. thresh = 0.6
  22. distMap[distMap < thresh] = 0
  23. distMap[distMap >= thresh] = 1
  24. distMap = 1 - distMap
  25. distMap[0, :], distMap[39, :], distMap[:, 0], distMap[:, 39] = 0, 0, 0, 0
  26.  
  27. for cnt, wsp in enumerate(data):
  28. w = som.winner(wsp)
  29. print(w)
  30. plt.plot(w[0], w[1], 'o')
  31.  
  32. plt.xlim([0, 40])
  33. plt.ylim([0, 40])
  34. plt.show()
  35.  
  36. blobs = measure.label(distMap)
  37. plt.pcolor(blobs, cmap='terrain')
  38. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement