API details.
Let's create a SOM with 20 rows and 30 columns
som = SOM(som_size=(5,8))
Let's create 10 random 3-dimensional data points:
my_data = np.random.random([10,3])
lattice = som.train(my_data, 1000)
Let's see what is in the lattice's cell (1,1):
lattice[1,1]
If we have an non-normalized data vector p:
p = np.random.randn(10,1)*3 + 2
p
We can use normalize_data
function to set the values between min_val
and max_val
:
normalize_data(p, min_val=0, max_val=1)
Let's create a U-matrix of the lattice, and check its shape:
um = u_matrix(lattice)
um.shape
Let's project onto the lattice:
projection = project_on_lattice(my_data, lattice)
for p in projection:
if projection[p]:
print (p, projection[p][0])
Let us compute how the vector activates the lattice. (Euclidean distance from each cell)
scaled = lattice_activations(my_data, lattice, exponent=8)
Activations of the data point 0:
scaled[0].round(2)
Activations of the data point 5:
scaled[5].round(2)
Let's find the closest vectors to the lattice:
closest = lattice_closest_vectors(my_data, lattice)
for c in closest:
print (c, closest[c])