%% 该算法是NSA的编程实例,其中:sf是自己模式串;det是检测器集合;
%% n是解测器检测器集合的个数;
%% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%% 下面是检测器产生阶段 %%
rs=0.04;
rab=0.05;
self=[0.2265 0.1423;
0.2871 0.2186;
0.273 0.1977;
0.265 0.2008;
0.1426 0.0567;
0.17 0.0797;
0.1772 0.087;
0.2773 0.2113;
0.2874 0.2288;
0.3045 0.2572];
d=rand(250,2);
%for s=1:250
%plot(det(s,1),det(s,2),'b+');hold on;
%end
for n=1:250
for i=1:250
for j=1:10
affity(j)=sqrt((d(i,1)-self(j,1)).^2+(d(i,2)-self(j,2)).^2);
if affity(j)<=(rab+rs);
d(i,:)=rand(1,2);
else
d(i,:)=d(i,:);
end
end
end
end
d;
for i=1:10
plot(self(i,1),self(i,2),'bo');hold on;
end
for i=1:250
plot(d(i,1),d(i,2),'b+');hold on;
end
%************************** the end ********************
%% 下面是测试阶段 %%
test=[0.3245 0.22;
0.2866 0.2279;
0.2308 0.1464;
0.2544 0.18;
0.151 0.068;
0.3179 0.2077;
0.3042 0.1989;
0.258 0.3477;
0.3327 0.2501;
0.214 0.139;
0.4524 0.31;
0.4401 0.30;
0.4782 0.36;
0.4633 0.357;
0.5687 0.898;
0.7245 0.987;
0.6333 0.96;
0.6929 0.983;
0.31 0.454;
0.344 0.568;
0.376 0.67;
0.284 0.563;
0.5501 0.1512;
0.2250 0.7821;
0.6543 0.2945];
for j=1:25
plot(test(j,1),test(j,2),'r*'); hold on; % 标识当前的测试样本
for i=1:250
dir=norm(test(j,:)-d(i,:));
d_test(i,1)=dir;
d_label(i,1)=i; % 标识当前是那个抗体和那个抗原在计算亲和力
end %d(d_label(i,1)
for i=1:250
if d_test(i,1)<=rab
plot(d(d_label(i,1),1),d(d_label(i,1),2),'g^'); hold on;
end
end
min_dir=min(d_test);
%for i=1:245
% f=or(d_test(i,1)<=rab,d_test(i+1,1)<=rab);
% f=and(f,1);
%end
%f;
%if f==1
if min_dir<=rab
disp('This data is detected')
else
for p=1:10
dir2=norm(test(j,:)-self(p,:));
test_self(p,1)=dir2;
self_label(p,1)=p;
end
for p=1:10
if test_self(p,1)<=rs
plot(self(self_label(p,1),1),self(self_label(p,1),2),'g^'); hold on;
end
end
%for p=1:9
%ff=or(test_self(p,1)<=rs,test_self(p+1,1)<=rs);
%ff=and(ff,1);
%end
min_dir2=min(test_self);
%if ff==1
if min_dir2<=rs
disp('This data is self_data')
else
disp('This data is not detected and not a selfdata')
end
end
end
%% ^^^^^^^^^^^^^^^^^ The end ^^^^^^^^^^^^^^^^^^^^ %%