09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Unsupervised Learning

self._neighbourhood = []

self._topography = []

self._num_iterations = int(num_iterations)

self._learned = False

self.dim = dim

self.eta = float(eta)

if sigma is None:

sigma = max(m,n)/2.0 # Constant radius

else:

sigma = float(sigma)

self.sigma = sigma

print('Network created with dimensions',m,n)

# Weight Matrix and the topography of neurons

self._W = tf.random.normal([m*n, dim], seed = 0)

self._topography = np.array(list(self._neuron_location(m, n)))

The most important function of the class is the train() function, where we use the

Kohonen algorithm as discussed before to find the winner units and then update the

weights based on the neighborhood function:

def training(self,x, i):

m = self._m

n= self._n

# Finding the Winner and its location

d = tf.sqrt(tf.reduce_sum(tf.pow(self._W - tf.stack([x for i in

range(m*n)]),2),1))

self.WTU_idx = tf.argmin(d,0)

slice_start = tf.pad(tf.reshape(self.WTU_idx, [1]),np.

array([[0,1]]))

self.WTU_loc = tf.reshape(tf.slice(self._topography, slice_

start,[1,2]), [2])

# Change learning rate and radius as a function of iterations

learning_rate = 1 - i/self._num_iterations

_eta_new = self.eta * learning_rate

_sigma_new = self.sigma * learning_rate

[ 388 ]

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

Saved successfully!

Ooh no, something went wrong!