To simulate my work
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 <50 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 < 10 %%%%%% 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
0 commentaires
Réponses (1)
Daniel Pereira
le 16 Sep 2016
What is the question here and what is that code?
I suggest you to be tidier with code, making it easier to debug and to maintain. Take a look at this guide:
0 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!