Computer Vision News - December 2020

11 Self-Organizing Maps (SOMs) with PyTorch Each line represents an iris flower. The flower names are 0: setosa, 1: versicolor, 2: virginica and are represented in the last item of each line. The first four values on each line are the flower's sepal length, sepal width, petal length and petal width. Therefore, the data has four dimensions. SOMs usually need normalized data although in this case the predictor values all have roughly the same magnitude, so you could omit that step. H ow many dimensions a SOM must have is a very subjective matter and very often decided after experimentation. The main idea is that each node vector represents some of the data items and on the same time the map nodes are geometrically closer, therefore representing similar items. The SOM will be constructed using the following pseudo-code: Define a n x n map with random node vector values loop while s < StepsMax times Calculate and define what a "close" node means, based on s compute a learn rate, based on s pick a random data item determine the map node closest to data item (BMU) for-each node close to the BMU adjust node vector values towards data item end-loop The main skeleton Here is the main skeleton of the SOM creation: import numpy as np import matplotlib.pyplot as plt def closest_node (data, t, map, m_rows, m_cols): . . def euc_dist (v1, v2): . . def manhattan_dist (r1, c1, r2, c2): . . def most_common (lst): . . def main (): # 0. Definitions np.random.seed( 1 ) dims = 4 rows = 40 cols = 40 range_max = rows + cols lr_max = 0.4 Steps_max = 2500 # 1. Data loading # 2. SOM construction # 3. U-Matrix display and construction # 4. Reduced data display and construction if __name__=="__main__": main()

RkJQdWJsaXNoZXIy NTc3NzU=