Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from minisom import MiniSom
- from mpl_toolkits.mplot3d import Axes3D
- from skimage import measure
- with open("benc.txt") as f:
- data = [[float(i) for i in linia.split()] for linia in f]
- data = np.reshape(data, (699, 9))
- data /= np.max(data)
- som = MiniSom(40, 40, 9, sigma=0.6, learning_rate=0.5, random_seed=13)
- som.train_batch(data, 1000)
- distMap = som.distance_map().T
- plt.pcolor(distMap, cmap='afmhot')
- plt.show()
- thresh = 0.6
- distMap[distMap < thresh] = 0
- distMap[distMap >= thresh] = 1
- distMap = 1 - distMap
- distMap[0, :], distMap[39, :], distMap[:, 0], distMap[:, 39] = 0, 0, 0, 0
- for cnt, wsp in enumerate(data):
- w = som.winner(wsp)
- print(w)
- plt.plot(w[0], w[1], 'o')
- plt.xlim([0, 40])
- plt.ylim([0, 40])
- plt.show()
- blobs = measure.label(distMap)
- plt.pcolor(blobs, cmap='terrain')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement