Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #8050
| Newsgroups | comp.programming |
|---|---|
| Date | 2017-09-25 09:41 -0700 |
| Message-ID | <a75a3d79-e250-4420-8699-19efc4e51aba@googlegroups.com> (permalink) |
| Subject | Challenge in running some plots |
| From | elvindavin@gmail.com |
%I want to plot the True Positive Rate of different percentages of "q" bits %modified ( ranges of 10,20,30,40,and 50) with the constant value of p =0.1; as a single graph. The one already done is with q =10% with different variations of p.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%The main file below
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 <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
%%%%%%%%%%%%%%%%%%%%%%%%The function path below
function [ s ] = similar( X,y1 )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
com=0;
[r1 sy]=size(y1);
[r2 sx]=size(X);
sy=sy-sum(y1(:)==999);
sx=sx-sum(X(:)==999);
for i=1:sx
if (X(i)==y1(i) && X(i)<999)
com=com+1;
end
end
if(sx+sy-com>0)
s=com/(sx+sy-com);
else
s=0;
end
end
function [sx] = Sim(X,y1,y2,y3 )
sx=(similar(X,y1)*similar(X,y2)*similar(X,y3))^(1/3);
end
Back to comp.programming | Previous | Next | Find similar | Unroll thread
Challenge in running some plots elvindavin@gmail.com - 2017-09-25 09:41 -0700
csiph-web