📄 som.v
字号:
4:begin
state1<=5;
weights1[4]<=X1;weights2[4]<=X2;weights3[4]<=X3;
end
5:begin
state1<=6;
weights1[5]<=X1;weights2[5]<=X2;weights3[5]<=X3;
end
6:begin
state1<=7;
weights1[6]<=X1;weights2[6]<=X2;weights3[6]<=X3;
end
7:begin
state1<=8;
weights1[7]<=X1;weights2[7]<=X2;weights3[7]<=X3;
end
8:begin
state1<=9;
weights1[8]<=X1;weights2[8]<=X2;weights3[8]<=X3;
end
9:begin
state1<=10;
weights1[9]<=X1;weights2[9]<=X2;weights3[9]<=X3;
end
10:begin
state1<=11;
weights1[10]<=X1;weights2[10]<=X2;weights3[10]<=X3;
end
11:begin
state1<=12;
weights1[11]<=X1;weights2[11]<=X2;weights3[11]<=X3;
end
12:begin
state1<=13;
weights1[12]<=X1;weights2[12]<=X2;weights3[12]<=X3;
end
13:begin
state1<=14;
weights1[13]<=X1;weights2[13]<=X2;weights3[13]<=X3;
end
14:begin
state1<=15;
weights1[14]<=X1;weights2[14]<=X2;weights3[14]<=X3;
end
15:begin
state1<=16;
weights1[15]<=X1;weights2[15]<=X2;weights3[15]<=X3;
end
16:begin
state1<=17;
weights1[16]<=X1;weights2[16]<=X2;weights3[16]<=X3;
end
17:begin
state1<=18;
weights1[17]<=X1;weights2[17]<=X2;weights3[17]<=X3;
end
18:begin
state1<=19;
weights1[18]<=X1;weights2[18]<=X2;weights3[18]<=X3;
end
19:begin
state1<=20;
weights1[19]<=X1;weights2[19]<=X2;weights3[19]<=X3;
end
20:begin
state1<=21;
weights1[20]<=X1;weights2[20]<=X2;weights3[20]<=X3;
end
21:begin
state1<=22;
weights1[21]<=X1;weights2[21]<=X2;weights3[21]<=X3;
end
22:begin
state1<=23;
weights1[22]<=X1;weights2[22]<=X2;weights3[22]<=X3;
end
23:begin
state1<=24;
weights1[23]<=X1;weights2[23]<=X2;weights3[23]<=X3;
end
24:begin
state1<=25;
weights1[24]<=X1;weights2[24]<=X2;weights3[24]<=X3;
end
25:begin
state1<=26;
weights1[25]<=X1;weights2[25]<=X2;weights3[25]<=X3;
end
26:begin
state1<=27;
weights1[26]<=X1;weights2[26]<=X2;weights3[26]<=X3;
end
27:begin
state1<=28;
weights1[27]<=X1;weights2[27]<=X2;weights3[27]<=X3;
end
28:begin
state1<=29;
weights1[28]<=X1;weights2[28]<=X2;weights3[28]<=X3;
end
29:begin
state1<=30;
weights1[29]<=X1;weights2[29]<=X2;weights3[29]<=X3;
end
30:begin
state1<=31;
weights1[30]<=X1;weights2[30]<=X2;weights3[30]<=X3;
end
31:begin
state1<=32;
weights1[31]<=X1;weights2[31]<=X2;weights3[31]<=X3;
end
32:begin
state1<=33;
weights1[32]<=X1;weights2[32]<=X2;weights3[32]<=X3;
end
33:begin
state1<=34;
weights1[33]<=X1;weights2[33]<=X2;weights3[33]<=X3;
end
34:begin
state1<=35;
weights1[34]<=X1;weights2[34]<=X2;weights3[34]<=X3;
end
35:begin
state1<=36;
state<=3'b010;
single_data_finish<=1;
weights1[35]<=X1;weights2[35]<=X2;weights3[35]<=X3;
end
default:
state1<=0;
endcase
end
else if(start_train&&load_x&&state==3'b010)
begin
single_data_finish<=0;
if(count_num==1000)
begin
frame_finish<=1;
state<=3'b000;
NC<=12;
lammda<=1023;
count_num<=0;
end
else
begin
state<=3'b011;
lammda<=lammda-1;
NC<=(NC>1)? NC-1:1;
count_num<=count_num+1;
end
//state2<=0;
end
else if(state==3'b011) //计算距离
begin
case(state2)
0:begin
state2<=1;
data_temp_b1<=X1-weights1[0];data_temp_b2<=X2-weights2[0];data_temp_b3<=X3-weights3[0];
end
1:begin
state2<=2;
data_temp_b1<=X1-weights1[1];data_temp_b2<=X2-weights2[1];data_temp_b3<=X3-weights3[1];
distance[0]<=distance_temp1+distance_temp2+distance_temp3;
end
2:begin
state2<=3;
data_temp_b1<=X1-weights1[2];data_temp_b2<=X2-weights2[2];data_temp_b3<=X3-weights3[2];
distance[1]<=distance_temp1+distance_temp2+distance_temp3;
end
3:begin
state2<=4;
data_temp_b1<=X1-weights1[3];data_temp_b2<=X2-weights2[3];data_temp_b3<=X3-weights3[3];
distance[2]<=distance_temp1+distance_temp2+distance_temp3;
end
4:begin
state2<=5;
data_temp_b1<=X1-weights1[4];data_temp_b2<=X2-weights2[4];data_temp_b3<=X3-weights3[4];
distance[3]<=distance_temp1+distance_temp2+distance_temp3;
end
5:begin
state2<=6;
data_temp_b1<=X1-weights1[5];data_temp_b2<=X2-weights2[5];data_temp_b3<=X3-weights3[5];
distance[4]<=distance_temp1+distance_temp2+distance_temp3;
end
6:begin
state2<=7;
data_temp_b1<=X1-weights1[6];data_temp_b2<=X2-weights2[6];data_temp_b3<=X3-weights3[6];
distance[5]<=distance_temp1+distance_temp2+distance_temp3;
end
7:begin
state2<=8;
data_temp_b1<=X1-weights1[7];data_temp_b2<=X2-weights2[7];data_temp_b3<=X3-weights3[7];
distance[6]<=distance_temp1+distance_temp2+distance_temp3;
end
8:begin
state2<=9;
data_temp_b1<=X1-weights1[8];data_temp_b2<=X2-weights2[8];data_temp_b3<=X3-weights3[8];
distance[7]<=distance_temp1+distance_temp2+distance_temp3;
end
9:begin
state2<=10;
data_temp_b1<=X1-weights1[9];data_temp_b2<=X2-weights2[9];data_temp_b3<=X3-weights3[9];
distance[8]<=distance_temp1+distance_temp2+distance_temp3;
end
10:begin
state2<=11;
data_temp_b1<=X1-weights1[10];data_temp_b2<=X2-weights2[10];data_temp_b3<=X3-weights3[10];
distance[9]<=distance_temp1+distance_temp2+distance_temp3;
end
11:begin
state2<=12;
data_temp_b1<=X1-weights1[11];data_temp_b2<=X2-weights2[11];data_temp_b3<=X3-weights3[11];
distance[10]<=distance_temp1+distance_temp2+distance_temp3;
end
12:begin
state2<=13;
data_temp_b1<=X1-weights1[12];data_temp_b2<=X2-weights2[12];data_temp_b3<=X3-weights3[12];
distance[11]<=distance_temp1+distance_temp2+distance_temp3;
end
13:begin
state2<=14;
data_temp_b1<=X1-weights1[13];data_temp_b2<=X2-weights2[13];data_temp_b3<=X3-weights3[13];
distance[12]<=distance_temp1+distance_temp2+distance_temp3;
end
14:begin
state2<=15;
data_temp_b1<=X1-weights1[14];data_temp_b2<=X2-weights2[14];data_temp_b3<=X3-weights3[14];
distance[13]<=distance_temp1+distance_temp2+distance_temp3;
end
15:begin
state2<=16;
data_temp_b1<=X1-weights1[15];data_temp_b2<=X2-weights2[15];data_temp_b3<=X3-weights3[15];
distance[14]<=distance_temp1+distance_temp2+distance_temp3;
end
16:begin
state2<=17;
data_temp_b1<=X1-weights1[16];data_temp_b2<=X2-weights2[16];data_temp_b3<=X3-weights3[16];
distance[15]<=distance_temp1+distance_temp2+distance_temp3;
end
17:begin
state2<=18;
data_temp_b1<=X1-weights1[17];data_temp_b2<=X2-weights2[17];data_temp_b3<=X3-weights3[17];
distance[16]<=distance_temp1+distance_temp2+distance_temp3;
end
18:begin
state2<=19;
data_temp_b1<=X1-weights1[18];data_temp_b2<=X2-weights2[18];data_temp_b3<=X3-weights3[18];
distance[17]<=distance_temp1+distance_temp2+distance_temp3;
end
19:begin
state2<=20;
data_temp_b1<=X1-weights1[19];data_temp_b2<=X2-weights2[19];data_temp_b3<=X3-weights3[19];
distance[18]<=distance_temp1+distance_temp2+distance_temp3;
end
20:begin
state2<=21;
data_temp_b1<=X1-weights1[20];data_temp_b2<=X2-weights2[20];data_temp_b3<=X3-weights3[20];
distance[19]<=distance_temp1+distance_temp2+distance_temp3;
end
21:begin
state2<=22;
data_temp_b1<=X1-weights1[21];data_temp_b2<=X2-weights2[21];data_temp_b3<=X3-weights3[21];
distance[20]<=distance_temp1+distance_temp2+distance_temp3;
end
22:begin
state2<=23;
data_temp_b1<=X1-weights1[22];data_temp_b2<=X2-weights2[22];data_temp_b3<=X3-weights3[22];
distance[21]<=distance_temp1+distance_temp2+distance_temp3;
end
23:begin
state2<=24;
data_temp_b1<=X1-weights1[23];data_temp_b2<=X2-weights2[23];data_temp_b3<=X3-weights3[23];
distance[22]<=distance_temp1+distance_temp2+distance_temp3;
end
24:begin
state2<=25;
data_temp_b1<=X1-weights1[24];data_temp_b2<=X2-weights2[24];data_temp_b3<=X3-weights3[24];
distance[23]<=distance_temp1+distance_temp2+distance_temp3;
end
25:begin
state2<=26;
data_temp_b1<=X1-weights1[25];data_temp_b2<=X2-weights2[25];data_temp_b3<=X3-weights3[25];
distance[24]<=distance_temp1+distance_temp2+distance_temp3;
end
26:begin
state2<=27;
data_temp_b1<=X1-weights1[26];data_temp_b2<=X2-weights2[26];data_temp_b3<=X3-weights3[26];
distance[25]<=distance_temp1+distance_temp2+distance_temp3;
end
27:begin
state2<=28;
data_temp_b1<=X1-weights1[27];data_temp_b2<=X2-weights2[27];data_temp_b3<=X3-weights3[27];
distance[26]<=distance_temp1+distance_temp2+distance_temp3;
end
28:begin
state2<=29;
data_temp_b1<=X1-weights1[28];data_temp_b2<=X2-weights2[28];data_temp_b3<=X3-weights3[28];
distance[27]<=distance_temp1+distance_temp2+distance_temp3;
end
29:begin
state2<=30;
data_temp_b1<=X1-weights1[29];data_temp_b2<=X2-weights2[29];data_temp_b3<=X3-weights3[29];
distance[28]<=distance_temp1+distance_temp2+distance_temp3;
end
30:begin
state2<=31;
data_temp_b1<=X1-weights1[30];data_temp_b2<=X2-weights2[30];data_temp_b3<=X3-weights3[30];
distance[29]<=distance_temp1+distance_temp2+distance_temp3;
end
31:begin
state2<=32;
data_temp_b1<=X1-weights1[31];data_temp_b2<=X2-weights2[31];data_temp_b3<=X3-weights3[31];
distance[30]<=distance_temp1+distance_temp2+distance_temp3;
end
32:begin
state2<=33;
data_temp_b1<=X1-weights1[32];data_temp_b2<=X2-weights2[32];data_temp_b3<=X3-weights3[32];
distance[31]<=distance_temp1+distance_temp2+distance_temp3;
end
33:begin
state2<=34;
data_temp_b1<=X1-weights1[33];data_temp_b2<=X2-weights2[33];data_temp_b3<=X3-weights3[33];
distance[32]<=distance_temp1+distance_temp2+distance_temp3;
end
34:begin
state2<=35;
data_temp_b1<=X1-weights1[34];data_temp_b2<=X2-weights2[34];data_temp_b3<=X3-weights3[34];
distance[33]<=distance_temp1+distance_temp2+distance_temp3;
end
35:begin
state2<=36;
data_temp_b1<=X1-weights1[35];data_temp_b2<=X2-weights2[35];data_temp_b3<=X3-weights3[35];
distance[34]<=distance_temp1+distance_temp2+distance_temp3;
end
36:begin
state2<=37;
state<=3'b100;
Nc<=NC;
lam<=lammda;
distance[35]<=distance_temp1+distance_temp2+distance_temp3;
end
default:
state2<=0;
endcase
end
else if(state==3'b100)
begin
for(i=0;i<6;i=i+1)
begin
for(j=0;j<6;j=j+1)
begin
$fwrite(file_p,"%3d ",weights1[6*i+j]);
end
$fwrite(file_p,"\n ");
end
$fwrite(file_p,"\n ");
for(i=0;i<6;i=i+1)
begin
for(j=0;j<6;j=j+1)
begin
$fwrite(file_p,"%3d ",weights2[6*i+j]);
end
$fwrite(file_p,"\n ");
end
$fwrite(file_p,"\n ");
for(i=0;i<6;i=i+1)
begin
for(j=0;j<6;j=j+1)
begin
$fwrite(file_p,"%3d ",weights3[6*i+j]);
end
$fwrite(file_p,"\n ");
end
$fwrite(file_p,"\n ");
for(i=0;i<6;i=i+1)
begin
for(j=0;j<6;j=j+1)
begin
$fwrite(file_p,"%3d ",distance[6*i+j]);
end
$fwrite(file_p,"\n ");
end
$fwrite(file_p,"\n ");
$fwrite(file_p,"lam=%3d ,Nc=%3d,winner_x=%d,winner_y=%d,X1=%d,X2=%d,X3=%d ,deta1=%d\n ",lam,Nc,winner_x,winner_y,X1,X2,X3,deta1);
if(Nc==0) //开始训练
begin
single_data_finish<=1;
state<=3'b010;
end
else
begin
state<=3'b101;
lam<=(lam>1)? lam>>1:1;
end
end
else if(state==3'b101)
begin
case(state3)
0:begin
state3<=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -