-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSOM_1_D_running.m
52 lines (40 loc) · 1.08 KB
/
SOM_1_D_running.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
%% SOM 1-D
close all
clc
samples = 200;
neurons = 70;
eta_i = 0.3;
sigma_i = 2; %initial sigma
tau1 = 3000;
tau2 = 30;
h = 0; %neighbourhood function
%% Generation of data for input space
input_space = rand(2,samples);
%% Initialization of SOM
weights = 0.8*rand(2,neurons)-1;
%% SOM Algo
for m = 1:100
eta = eta_i*exp(-(m/tau2));
display(m)
display(eta)
for i = 1:samples
% Finding out winning neuron
dist = zeros(1,neurons);
for j = 1:neurons
dist(j) = norm(weights(:,j)-input_space(:,i));
end
[min_val,index_min] = min(dist);
%weight updation
sigma = sigma_i*exp(-(i/tau1));
for j = 1:neurons
h = exp(-((abs(j-index_min))^2/(2*sigma^2)));
weights(:,j) = weights(:,j) + eta*h*(input_space(:,i)-weights(:,j));
end
end
plot(input_space(1,:),input_space(2,:),'.');
hold on
plot(weights(1,:),weights(2,:),'bo');
hold off
pause(0.05)
end
save('SOM_eg_2_8');