Info

此问题已关闭。 请重新打开它进行编辑或回答。

I need assistance of the intitials represent in the algorithm i was provided

2 次查看(过去 30 天)
I want to use this Entropy based recommendation algorithm in fishing out some malicious nodes in internet of thing security analysis but I am having a little challenges about what the initials I highlighted represent. For instance tp represent "true positive", just like fp represent "false positive" Please I need help
tp=zeros(10,10); fp=zeros(10,10); phh=zeros(10,10); pmm=zeros(10,10); pmh=zeros(10,10); phm=zeros(10,10); M=zeros(10,10); H=zeros(10,10); source=zeros(10,200,100); avgT=zeros(10,10); eval= zeros(1, 100); sim = zeros(10, 1); se=zeros(10,1); ce =zeros(10,1); pc= zeros(10,100); c=zeros(10,100); T=zeros(100,100,10); actM=[1 1 1 1 1 0 0 0 0 0]; %cw2= [ 1 0 0 0 0 1 1 1 1 1] ; %tq=zeros(10,T); cw3=zeros(1,100); q=10; while q < 40 d=1; T=zeros(10,100,100); while d <5 %%%%%%%%%%%%%%%%%%% iterating over percentage of malicious packets
phh=zeros(10,10); pmm=zeros(10,10); pmh=zeros(10,10); phm=zeros(10,10); M=zeros(10,10); H=zeros(10,10); iter=1; while iter < 20 %%%%%% look into the following code, it does not run for iterations %%%%%%%%%%%%%%%% generating multiple runs for the given percentage %%%%%%%%%%%%%%%% of malicious packets
eval=zeros(1,100);
rp=randperm(100);
eval(rp(1:q)) = 1;
cw1=bsc(eval,0.04);
cw2=zeros(1,100);
%%%%%%%%%%%formulating malicious behavior
% for i = 1:100
%if i < q
% if eval(i)==1
% cw2(i)=0;
% else
% cw2(i)=1;
% end
% else
% cw2(i)=eval(i);
% end
% end
cw2=bsc(eval,(q/100));
source=zeros(100,200,100);
sim = zeros(10, 1); se=zeros(10,1); ce =zeros(10,1);
pc= zeros(10,100);
c=zeros(10,100);
for i=1:100
for j=1:10
source(j,i,:) =eval;% cw1;
if rem(i,10)<(d )&& j<((10/2) +1) &&i>1 %%%%%%%%%%%%%%%%%%%%malicious behavior %%%%%%%%%%%%%%
source(j,i,:)=cw2;%bsc(eval,q/100);
end
% if rem(i,10)<d &&j>3&&j<6 %%%%%%%%%%%%%%to have different amounts
% of misbehavior
% source(j,i,:)=cw3;
% end
for k=1:100
if (i ==1)
c(j,k)=1;
end
if (i>1&& source(j,i,k) == source(j,i-1,k))
c(j,k) =c(j,k)+1;
end
end
sim(j)=similar(source(j,i,:),eval);
se(j)= -sim(j)*log10(sim(j))/log10(100);
if isnan(se(j))
se(j)=1;
end
pc(j,:)=c(j,:)/i; pc(1,:)=c(1,:)/i;
sum =0;
for k=1:100
sum=(-pc(j,k)*log10(pc(j,k))/log10(100) )+ sum; % computing the entropy of each source for the whole code word
end
ce(j) =sum;
if isnan(ce(j))
ce(j)=1;
end
if i <2
T(d,i,j)=1-se(j); %%%%%%%%d is replaced by d
else
T(d,i,j)=(1-(se(j)+ce(j)))*0.5+ 0.5*T(d,i-1,j);
T(d,i,j)= T(d,i,j)/max(T(d,:,j));
end
if (isnan(T(d,i,j)) )
T(d,i,j)=0;
end
if (T(d,i,j)>1)
T(d,i,j)=1;
end
if (T(d,i,j)<0)
T(d,i,j)=0;
end
end
end
for i = 1: 10 % d*10 to 10 avgT(d,i)=mean(T(d,:,i)); %%%%%%%%%% replacing 'd 'by d if avgT(d,i)<0.75 M(d,i)=M(d,i)+1; if actM(i)==1 pmm (q/10,d)= pmm(q/10,d)+1; else pmh(q/10,d) =pmh(q/10,d)+1; end else H(d,i)=H(d,i)+1; if actM(i)==0 phh(q/10,d)=phh(q/10,d)+1; else phm(q/10,d) =phm(q/10,d)+1; end end end iter =iter+1; end % tp(q/10,d)=pmm(q/10,d)/(pmm(q/10,d)+phm(q/10,d)); tp(q/10,d)=pmm(q/10,d)/(pmm(q/10,d)+phm(q/10,d)); % fp(q/10,d)=pmh(q/10,d)/(phh(q/10,d)+pmh(q/10,d)); fp(q/10,d)=pmh(q/10,d)/(phh(q/10,d)+pmh(q/10,d)); d=d+1;
end
q =q+10; x=1:100; figure(q/10) plot(x,T(1,:,9),'-ob', x,T(1,:,2),'-dr', x, T(2,:,2),'-sg',x,T(3,:,2),'-m*',x,T(5,:,2),'-k^'); legend('Honest', 'Malicious, p =0.1, 10% recommendations are false', 'Malicious,p=0.2, 10% recommendations are false','Malicious,p=0.3, 10% recommendations are false','Malicious,p=0.5, 10% recommendations are false') xlabel('Iteration'); ylabel('RecommendationTrust'); title('Impact of size of recommendation vector');
end

回答(1 个)

Steven Lord
Steven Lord 2016-11-15
I recommend you ask the person from whom you obtained that code for assistance in understanding what the code is doing. One first step in that process, in my opinion, should be to use descriptive variable names and add comments explaining the purposes behind the non-obvious lines of code.
For instance, rather than 'tp' or 'fp' I would use 'truePositive' or 'falsePositive' as variable names. The shorter names will be faster to type (though tab completion will mitigate that somewhat) but the longer names will be faster to understand.
  1 个评论
Image Analyst
Image Analyst 2016-11-15
I whole-heartedly agree. Right now that is an impenetrable alphabet soup mess of a program that no one can follow. Tell the author to get professional and put in comments and use descriptive variable names. As is it, that code is not maintainable or even understandable.

此问题已关闭。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by