function [j_min]=SOM_compare(weight,train_data_active,node_num,index_active)
for j=1:node_num
distant(j,1)=sum((weight(:,j)-train_data_active).^2);
end
[~,j_min]=min(distant);
while(index_active(1,j_min)==0)
distant(j_min,1)=10000000;
[~,j_min]=min(distant);
end
end
SOM_neighb3.m
function [weight]=SOM_neighb3(weight,train_data_active,j_min,delta,alpha)
%% 權值調整幅度分布
% -0.2
% 0.2
% 0.6
% -0.2 0.2 0.6 1 0.6 0.2 -0.2
% 0.6
% 0.2
% -0.2
% 機關距離轉化比例為0.4
%% 坐标轉換
[x,y]=line_to_array(j_min);
% 将1*70向量中的坐标轉化為7*10矩陣中的坐标
% 1 8 ···
% 7 14 ···
%% 權值調整過程
%結點靠上邊情況
if (x<=3)
for m=1:1:x+3
if (y<=3) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=8) %結點靠右邊
for n=y-3:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-3:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點靠下邊情況
elseif (x>=5)
for m=x-3:1:7
if (y<=3) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=8) %結點靠右邊
for n=y-3:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-3:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點正好在中間
else
for m=1:7
if (y<=3) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=8) %結點靠右邊
for n=y-3:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-3:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
end
end
SOM_neighb2.m
function [weight]=SOM_neighb2(weight,train_data_active,j_min,delta,alpha)
%% 權值調整幅度分布
% -0.2
% 0.2
% 0.6
% -0.2 0.2 0.6 1 0.6 0.2 -0.2
% 0.6
% 0.2
% -0.2
% 機關距離轉化比例為0.4
%% 坐标轉換
[x,y]=line_to_array(j_min);
% 将1*70向量中的坐标轉化為7*10矩陣中的坐标
% 1 8 ···
% 7 14 ···
%% 權值調整過程
%結點靠上邊情況
if (x<=2)
for m=1:1:x+2
if (y<=2) %結點靠左邊
for n=1:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=9) %結點靠右邊
for n=y-2:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-2:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點靠下邊情況
elseif (x>=6)
for m=x-2:1:7
if (y<=2) %結點靠左邊
for n=1:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=9) %結點靠右邊
for n=y-2:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-2:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點正好在中間
else
for m=x-2:1:x+2
if (y<=2) %結點靠左邊
for n=1:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=9) %結點靠右邊
for n=y-2:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-2:1:y+2
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
end
end
SOM_neighb1.m
function [weight]=SOM_neighb1(weight,train_data_active,j_min,delta,alpha)
%% 權值調整幅度分布
% -0.2
% 0.2
% 0.6
% -0.2 0.2 0.6 1 0.6 0.2 -0.2
% 0.6
% 0.2
% -0.2
% 機關距離轉化比例為0.4
%% 坐标轉換
[x,y]=line_to_array(j_min);
% 将1*70向量中的坐标轉化為7*10矩陣中的坐标
% 1 8 ···
% 7 14 ···
%% 權值調整過程
%結點靠上邊情況
if (x<=1)
for m=1:1:x+1
if (y<=1) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=10) %結點靠右邊
for n=y-1:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-1:1:y+1
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點靠下邊情況
elseif (x>=7)
for m=x-3:1:7
if (y<=1) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=10) %結點靠右邊
for n=y-1:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-1:1:y+1
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
%結點正好在中間
else
for m=x-1:1:x+1
if (y<=1) %結點靠左邊
for n=1:1:y+3
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
elseif (y>=10) %結點靠右邊
for n=y-1:1:10
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
else
for n=y-1:1:y+1
distant=sqrt((x-m)^2+(y-n)^2);
weight(:,(n-1)*7+m)=weight(:,(n-1)*7+m)-alpha*exp(-distant^2/delta^2)*(weight(:,(n-1)*7+m)-train_data_active);
end
end
end
end
end
SOM_neighb0.m
function [weight]=SOM_neighb0(weight,train_data_active,j_min,alpha)
weight(:,j_min)=weight(:,j_min)+alpha*(weight(:,j_min)-train_data_active);
end
line_to_array.m
function [x,y]=line_to_array(j_min)
% 将1*70向量中的坐标轉化為7*10矩陣中的坐标
% 1 8 ···
% 7 14 ···
y=ceil(j_min/7);
x=rem(j_min,7);
end