Kohonen Self Organizing Map
Introduction
Kohonen self organizing map is a unsupervised clustering algorithm
Clusters high dimensional input to easy to visualize 2D representations
Used to find patterns/ clusters
Algorithm
Create Self Organizing Map
Define map width
Define map height
Define max epochs
Define no of colors, need to classify
Define inputs - pixels values in the range 0-256 with rgb values
Define initial weights - weight values in between 0-1 for all nodes
Define initial learning rate = 0.1
Define initial neighbourhood radius
Define time constant
Define node locations (x & y)
Iterate through the training loop & update weights
Select random input from the inputs of colors
Update weights
Find the winning neuron/Best Matching Unit - calculate Euclidean Distance between the random input and nodes to find the node with minimum distance
Iterate through all nodes
Find the euclidean distance between the current node and BMU
Find the influence
Update the weight of the current node
Update the learning rate
Update the neighborhood radius
Translate the weights of each node in the map to pixel data (image)
Image height = map height
Image width = map width
Each element has a vector with 3 values (rgb)
Plot the image
Source code
Click the following link
Click open with google colaboratory
Go to Runtime -> Change Runtime Type
Set Hardware accelerator to GPU
Exercise 1 : Output
width=10
height=10
no_of_colors=20
Max_Epoch=100
Exercise 2 : Output
width=10
height=10
no_of_colors=20
Max_Epoch=200
Exercise 3: Output
width=10
height=10
no_of_colors=20
Max_Epoch=500
Exercise 4 : Output
width=100
height=100
no_of_colors=20
Max_Epoch=1000Test Case 1
Inputs
width = 10, height = 10, no_of_colors = 20, max_epoch = 100
Parameter, Expected output
som.NO_OF_COLORS, 20
som.INPUT_DATA_SHAPE[0], 20 som.INPUT_DATA_SHAPE[1], 3
som.MAP_WIDTH, 10 som.MAP_HEIGHT, 10
som.SOM_SHAPE[0], 10 som.SOM_SHAPE[1], 10
Inputs values in range 0-256
Initial Weights values in range 0-1
som.MAX_EPOCH, 100
som.ALPHA_0, 0.1
som.SIGMA_0, 5
som.TIME_CONST, 143.0676558073393
Test Case 2
Inputs
width = 10, height = 10, no_of_colors = 20, max_epoch = 100
input = [0.5,0.3,0.7]
nodes = [[5,13,20],[14,7,3],[2,12,30]]
Parameter, Expected output
Node 1 Euclidean distance 23.5
Node 1 Euclidean distance 15.2
Node 1 Euclidean distance 31.6
Best Matching Unit, 1 (second node with weights of [14,7,3])
Test Case 3
Inputs
width = 10, height = 10, no_of_colors = 20, max_epoch = 100
epoch =1, ALPHA_0 = 0.1, TIME_CONST, 143.0676558073393
Parameter, Expected output
Decayed learning rate, 0.09930346710946143
Test Case 4
Inputs
width = 10, height = 10, no_of_colors = 20, max_epoch = 100
epoch =1, SIGMA_0 = 5, TIME_CONST, 143.0676558073393
Parameter, Expected output
Decayed neighbourhood radius, 4.9651733554730715
Comments
Post a Comment