Hallo, I am trying to understand your syntax for som implementation form scratch. I found something is not right.
for i in range(n_iterations):
# select a training example at random
t = data[:, np.random.randint(0, n)].reshape(np.array([m, 1]))
# find its Best Matching Unit
bmu, bmu_idx = find_bmu(t, net, m)
# decay the SOM parameters
r = decay_radius(init_radius, i, time_constant)
l = decay_learning_rate(init_learning_rate, i, n_iterations)
# update weight vector to move closer to input
# and move its neighbours in 2-D vector space closer
for x in range(net.shape[0]):
for y in range(net.shape[1]):
w = net[x, y, :].reshape(m, 1)
w_dist = np.sum((np.array([x, y]) - bmu_idx) ** 2)
w_dist = np.sqrt(w_dist)
if w_dist <= r:
# calculate the degree of influence (based on the 2-D distance)
influence = calculate_influence(w_dist, r)
# new w = old w + (learning rate * influence * delta)
# where delta = input vector (t) - old w
new_w = w + (l * influence * (t - w))
net[x, y, :] = new_w.reshape(1, 3)
Hallo, I am trying to understand your syntax for som implementation form scratch. I found something is not right.
I think it is supposed to be
w_dist = np.sum((np.array([x, y]) - bmu) ** 2)