www.pudn.com > matlab_program_for_DS.rar > D_S.m


%This program is written by Caoqiang 
%Any question, contact me ! 
alfa=0.2; 
beta=0.9; 
temp=load('AttckSet_116');%NumOfTuples*5 
attackSet=temp.attack_set_116; 
temp=load('NormalSet_116');%NumOfTuples*5 
normalSet=temp.normal_set; 
attackNum=length(attackSet); 
normalNum=length(normalSet); 
%computing the relevant parametres 
E_attack=[sum(attackSet(:,1))/attackNum,sum(attackSet(:,2))/attackNum,sum(attackSet(:,3))/attackNum,sum(attackSet(:,4))/attackNum,sum(attackSet(:,5))/attackNum]; 
E_normal=[sum(normalSet(:,1))/normalNum,sum(normalSet(:,2))/normalNum,sum(normalSet(:,3))/normalNum,sum(normalSet(:,4))/normalNum,sum(normalSet(:,5))/normalNum]; 
for j=1:5 
m_min(j)=sum(attackSet(:,j)E_attack(j))/(sum(attackSet(:,j)>E_attack(j))+sum(normalSet(:,j)>E_attack(j))); 
end  
m_min(4)=sum(attackSet(:,4)>E_normal(4))/(sum(attackSet(:,4)>E_normal(4))+sum(normalSet(:,4)>E_normal(4))); 
m_max(4)=sum(attackSet(:,4)E_attack(j) 
            attackSet_pro_attack(i,j)=m_max(j); 
            attackSet_pro_normal(i,j)=m_min(j); 
        else  
            attackSet_pro_attack(i,j)=cosin(j)/((attackSet(i,j)-enta(j))*(attackSet(i,j)-enta(j)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
            attackSet_pro_normal(i,j)=cosin(j)/((E_normal(j)+E_attack(j)-attackSet(i,j)-enta(j))*(E_normal(j)+E_attack(j)-attackSet(i,j)-enta(j))); 
        end 
    end 
end 
 
for i=1:length(attackSet) 
    if attackSet(i,4)E_normal(4) 
        attackSet_pro_attack(i,4)=m_min(4); 
        attackSet_pro_normal(i,4)=m_max(4); 
    else 
        attackSet_pro_attack(i,4)=cosin(4)/((attackSet(i,4)-enta(4))*(attackSet(i,4)-enta(4)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
        attackSet_pro_normal(i,4)=cosin(4)/((E_normal(4)+E_attack(4)-attackSet(i,4)-enta(4))*(E_normal(4)+E_attack(4)-attackSet(i,4)-enta(4))); 
    end 
end 
 
%process normal tuples 
for j=[1 2 3 5] 
    for i=1:length(normalSet) 
        if normalSet(i,j)E_attack(j) 
            normalSet_pro_attack(i,j)=m_max(j); 
            normalSet_pro_normal(i,j)=m_min(j); 
        else  
            normalSet_pro_attack(i,j)=cosin(j)/((normalSet(i,j)-enta(j))*(normalSet(i,j)-enta(j)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
            normalSet_pro_normal(i,j)=cosin(j)/((E_normal(j)+E_attack(j)-normalSet(i,j)-enta(j))*(E_normal(j)+E_attack(j)-normalSet(i,j)-enta(j))); 
        end 
    end 
end 
 
for i=1:length(normalSet) 
    if normalSet(i,4)E_normal(4) 
        normalSet_pro_attack(i,4)=m_min(4); 
        normalSet_pro_normal(i,4)=m_max(4); 
    else 
        normalSet_pro_attack(i,4)=cosin(4)/((normalSet(i,4)-enta(4))*(normalSet(i,4)-enta(4)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
        normalSet_pro_normal(i,4)=cosin(4)/((E_normal(4)+E_attack(4)-normalSet(i,4)-enta(4))*(E_normal(4)+E_attack(4)-normalSet(i,4)-enta(4))); 
    end 
end 
 
%fusion the 5 features 
for i=1:length(attackSet) 
    [temp1_p_a,temp1_p_n]=fusion(attackSet_pro_attack(i,1),attackSet_pro_normal(i,1),attackSet_pro_attack(i,2),attackSet_pro_normal(i,2)); 
    [temp2_p_a,temp2_p_n]=fusion(attackSet_pro_attack(i,3),attackSet_pro_normal(i,3),attackSet_pro_attack(i,4),attackSet_pro_normal(i,4)); 
    [temp3_p_a,temp3_p_n]=fusion(temp1_p_a,temp1_p_n,temp2_p_a,temp2_p_n); 
    [attackSet_fusionpro_attack(i),attackSet_fusionpro_normal(i)]=fusion(temp3_p_a,temp3_p_n,attackSet_pro_attack(i,5),attackSet_pro_normal(i,5)); 
    attackSet_Bel(i)=attackSet_fusionpro_attack(i);   %compution the Bel and Pl for attack set 
    attackSet_Pl(i)=1-attackSet_fusionpro_normal(i); 
end 
 
for i=1:length(normalSet) 
    [temp1_p_a,temp1_p_n]=fusion(normalSet_pro_attack(i,1),normalSet_pro_normal(i,1),normalSet_pro_attack(i,2),normalSet_pro_normal(i,2)); 
    [temp2_p_a,temp2_p_n]=fusion(normalSet_pro_attack(i,3),normalSet_pro_normal(i,3),normalSet_pro_attack(i,4),normalSet_pro_normal(i,4)); 
    [temp3_p_a,temp3_p_n]=fusion(temp1_p_a,temp1_p_n,temp2_p_a,temp2_p_n); 
    [normalSet_fusionpro_attack(i),normalSet_fusionpro_normal(i)]=fusion(temp3_p_a,temp3_p_n,normalSet_pro_attack(i,5),normalSet_pro_normal(i,5)); 
    normalSet_Bel(i)=normalSet_fusionpro_attack(i);   %compution the Bel and Pl for normal set 
    normalSet_Pl(i)=1-normalSet_fusionpro_normal(i); 
end 
 
%collaborative fusion.......... 
%collaborative node: from 23&24 to 22   //2322 & 2422->223 
%                    from 35&33 to 32   //3332 & 3532->325  
%                    from 32&3  to 5    //35   & 325 ->51 
%                    from 0 & 5 to 1    //51   & 01  ->116 
 
temp=load('AttckSet_01'); 
source1_attackset=temp.attack_set_01; 
temp=load('NormalSet_01'); 
source1_normalset=temp.normal_set; 
temp=load('AttckSet_51'); 
source2_attackset=temp.attack_set_51; 
temp=load('NormalSet_51'); 
source2_normalset=temp.normal_set; 
co_attackSet=collaborate_feature(source1_attackset,source2_attackset); 
co_normalSet=collaborate_feature(source1_normalset,source2_normalset); 
 
%process attack tuples 
for j=[1 2 3 5] 
    for i=1:length(co_attackSet) 
        if co_attackSet(i,j)E_attack(j) 
            co_attackSet_pro_attack(i,j)=m_max(j); 
            co_attackSet_pro_normal(i,j)=m_min(j); 
        else  
            co_attackSet_pro_attack(i,j)=cosin(j)/((co_attackSet(i,j)-enta(j))*(co_attackSet(i,j)-enta(j)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
            co_attackSet_pro_normal(i,j)=cosin(j)/((E_normal(j)+E_attack(j)-co_attackSet(i,j)-enta(j))*(E_normal(j)+E_attack(j)-co_attackSet(i,j)-enta(j))); 
        end 
    end 
end 
 
for i=1:length(co_attackSet) 
    if co_attackSet(i,4)E_normal(4) 
        co_attackSet_pro_attack(i,4)=m_min(4); 
        co_attackSet_pro_normal(i,4)=m_max(4); 
    else 
        co_attackSet_pro_attack(i,4)=cosin(4)/((co_attackSet(i,4)-enta(4))*(co_attackSet(i,4)-enta(4)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
        co_attackSet_pro_normal(i,4)=cosin(4)/((E_normal(4)+E_attack(4)-co_attackSet(i,4)-enta(4))*(E_normal(4)+E_attack(4)-co_attackSet(i,4)-enta(4))); 
    end 
end 
 
%process normal tuples 
for j=[1 2 3 5] 
    for i=1:length(co_normalSet) 
        if co_normalSet(i,j)E_attack(j) 
            co_normalSet_pro_attack(i,j)=m_max(j); 
            co_normalSet_pro_normal(i,j)=m_min(j); 
        else  
            co_normalSet_pro_attack(i,j)=cosin(j)/((co_normalSet(i,j)-enta(j))*(co_normalSet(i,j)-enta(j)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
            co_normalSet_pro_normal(i,j)=cosin(j)/((E_normal(j)+E_attack(j)-co_normalSet(i,j)-enta(j))*(E_normal(j)+E_attack(j)-co_normalSet(i,j)-enta(j))); 
        end 
    end 
end 
 
for i=1:length(co_normalSet) 
    if co_normalSet(i,4)E_normal(4) 
        co_normalSet_pro_attack(i,4)=m_min(4); 
        co_normalSet_pro_normal(i,4)=m_max(4); 
    else 
        co_normalSet_pro_attack(i,4)=cosin(4)/((co_normalSet(i,4)-enta(4))*(co_normalSet(i,4)-enta(4)));%the attackSet(i,j) and E_normal(j)+E_attack(j)-attackSet(i,j) are symmetry about the line (E_normal(j)+E_attack(j))/2; 
        co_normalSet_pro_normal(i,4)=cosin(4)/((E_normal(4)+E_attack(4)-co_normalSet(i,4)-enta(4))*(E_normal(4)+E_attack(4)-co_normalSet(i,4)-enta(4))); 
    end 
end 
 
%fusion the 5 features 
for i=1:length(co_attackSet) 
    [co_temp1_p_a,co_temp1_p_n]=fusion(co_attackSet_pro_attack(i,1),co_attackSet_pro_normal(i,1),co_attackSet_pro_attack(i,2),co_attackSet_pro_normal(i,2)); 
    [co_temp2_p_a,co_temp2_p_n]=fusion(co_attackSet_pro_attack(i,3),co_attackSet_pro_normal(i,3),co_attackSet_pro_attack(i,4),co_attackSet_pro_normal(i,4)); 
    [co_temp3_p_a,co_temp3_p_n]=fusion(co_temp1_p_a,co_temp1_p_n,co_temp2_p_a,co_temp2_p_n); 
    [co_attackSet_fusionpro_attack(i),co_attackSet_fusionpro_normal(i)]=fusion(co_temp3_p_a,co_temp3_p_n,co_attackSet_pro_attack(i,5),co_attackSet_pro_normal(i,5)); 
    co_attackSet_Bel(i)=co_attackSet_fusionpro_attack(i);   %compution the Bel and Pl for attack set 
    co_attackSet_Pl(i)=1-co_attackSet_fusionpro_normal(i); 
end 
 
for i=1:length(co_normalSet) 
    [co_temp1_p_a,co_temp1_p_n]=fusion(co_normalSet_pro_attack(i,1),co_normalSet_pro_normal(i,1),co_normalSet_pro_attack(i,2),co_normalSet_pro_normal(i,2)); 
    [co_temp2_p_a,co_temp2_p_n]=fusion(co_normalSet_pro_attack(i,3),co_normalSet_pro_normal(i,3),co_normalSet_pro_attack(i,4),co_normalSet_pro_normal(i,4)); 
    [co_temp3_p_a,co_temp3_p_n]=fusion(co_temp1_p_a,co_temp1_p_n,co_temp2_p_a,co_temp2_p_n); 
    [co_normalSet_fusionpro_attack(i),co_normalSet_fusionpro_normal(i)]=fusion(co_temp3_p_a,co_temp3_p_n,co_normalSet_pro_attack(i,5),co_normalSet_pro_normal(i,5)); 
    co_normalSet_Bel(i)=co_normalSet_fusionpro_attack(i);   %compution the Bel and Pl for normal set 
    co_normalSet_Pl(i)=1-co_normalSet_fusionpro_normal(i); 
end 
figure(1); 
plot(normalSet_Pl,'k');hold on;plot(co_normalSet_Bel,'r'); 
figure(2); 
plot(attackSet_Pl,'k');hold on; plot(co_attackSet_Bel,'r'); 
total=1000; 
normal_normal=sum(normalSet_Pl<=alfa)+sum(normalSet_Pl>alfa & co_normalSet_Belalfa & co_attackSet_Bel>beta); 
attack_normal=total-attack_attack; 
[normal_normal, normal_attack] 
[attack_normal,attack_attack] 
 
loc_detection_rate=(sum(normalSet_Plalfa))/(length(attackSet_Pl)+length(normalSet_Pl)); 
loc_false_positive_rate=sum(normalSet_Pl>alfa)/(length(attackSet_Pl)+length(normalSet_Pl)); 
[loc_detection_rate, loc_false_positive_rate] 
 
 
% alfa=0.1; 
% i=1; 
% for beta=0.1:0.05:0.95 
%     loc_detection_rate(i)=(sum(normalSet_Plalfa))/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     loc_false_positive_rate(i)=sum(normalSet_Pl>alfa)/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     co_detection_rate(i)=(sum(normalSet_Pl<=alfa)+sum(normalSet_Pl>alfa & co_normalSet_Belalfa & co_attackSet_Bel>beta))/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     co_false_positive_rate(i)=sum(normalSet_Pl>alfa & co_normalSet_Bel>beta)/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     %loc_detection_rate 
%     %loc_false_positive_rate 
%     %co_detection_rate 
%     %co_false_positive_rate 
%     i=i+1; 
% end 
% figure(3); 
% plot(0.1:0.05:0.95,co_detection_rate,'k');hold on 
% plot(0.1:0.05:0.95,co_false_positive_rate,'r'); 
% plot(0.1:0.05:0.95,loc_detection_rate,'b'); 
% plot(0.1:0.05:0.95,loc_false_positive_rate,'y'); 
%  
% beta=0.9; 
% i=1; 
% for alfa=0.1:0.05:0.95 
%     loc_detection_rate(i)=(sum(normalSet_Plalfa))/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     loc_false_positive_rate(i)=sum(normalSet_Pl>alfa)/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     co_detection_rate(i)=(sum(normalSet_Pl<=alfa)+sum(normalSet_Pl>alfa & co_normalSet_Belalfa & co_attackSet_Bel>beta))/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     co_false_positive_rate(i)=sum(normalSet_Pl>alfa & co_normalSet_Bel>beta)/(length(attackSet_Pl)+length(normalSet_Pl)); 
%     %loc_detection_rate 
%     %loc_false_positive_rate 
%     %co_detection_rate 
%     %co_false_positive_rate 
%     i=i+1; 
% end 
% figure(4); 
% plot(0.1:0.05:0.95,co_detection_rate,'k');hold on 
% plot(0.1:0.05:0.95,co_false_positive_rate,'r'); 
% plot(0.1:0.05:0.95,loc_detection_rate,'b'); 
% plot(0.1:0.05:0.95,loc_false_positive_rate,'y'); 
%  
% loc_detection_rate(3) 
% loc_false_positive_rate(3) 
% co_detection_rate(3) 
% co_false_positive_rate(3) 
%  
% % alfa=0.95; 
% % i=1; 
% % for beta=0.9:0.01:1 
% %     loc_detection_rate(i)=(sum(normalSet_Plalfa))/(length(attackSet_Pl)+length(normalSet_Pl)); 
% %     loc_false_positive_rate(i)=sum(normalSet_Pl>alfa)/(length(attackSet_Pl)+length(normalSet_Pl)); 
% %     co_detection_rate(i)=(sum(normalSet_Pl<=alfa)+sum(normalSet_Pl>alfa & co_normalSet_Belalfa & co_attackSet_Bel>beta))/(length(attackSet_Pl)+length(normalSet_Pl)); 
% %     co_false_positive_rate(i)=sum(normalSet_Pl>alfa & co_normalSet_Bel>beta)/(length(attackSet_Pl)+length(normalSet_Pl)); 
% %     %loc_detection_rate 
% %     %loc_false_positive_rate 
% %     %co_detection_rate 
% %     %co_false_positive_rate 
% %     i=i+1; 
% % end 
% % figure(4); 
% % plot(0.9:0.01:1,co_detection_rate,'k');hold on 
% % plot(0.9:0.01:1,co_false_positive_rate,'r'); 
% %               
%