09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Unsupervised Learning

Then there are some more helper functions to find the winner and generate a 2D

lattice of neurons, and a function to map input vectors to the corresponding neurons

in the 2D lattice:

def winner(self, x):

idx = self.WTU_idx,self.WTU_loc

return idx

def _neuron_location(self,m,n):

"""

Function to generate the 2D lattice of neurons

"""

for i in range(m):

for j in range(n):

yield np.array([i,j])

def get_centroids(self):

"""

Function to return a list of 'm' lists, with each inner

list containing the 'n' corresponding centroid locations as 1-D

NumPy arrays.

"""

if not self._learned:

raise ValueError("SOM not trained yet")

return self._centroid_grid

def map_vects(self, X):

"""

Function to map each input vector to the relevant

neuron in the lattice

"""

if not self._learned:

raise ValueError("SOM not trained yet")

to_return = []

for vect in X:

min_index = min([i for i in range(len(self._Wts))],

key=lambda x: np.linalg.norm(vect -

self._Wts[x]))

to_return.append(self._locations[min_index])

return to_return

[ 390 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!