% July 2018, Etemadi and Lu
%Our PES uses \textbf{less sample sizes} compared to other methods to obtain an estimation with the same RSE=0.2 on most of the graphs. 
%Note that the sample size include both the size of the subgraph and the reservoir for our PES but for GPS methods extra memory per sampled edge was ignored.
clear all;clf('reset');
data_name1={'Orkut'};

data_name={'Ego-facebook';'CA-GrQc';'Wiki-Vote';'AstroPh';'CA-CondMat';'HepPh';'Enron-email'};
             
size_subplot=size(data_name,1);
for i=1: size_subplot
    str1=data_name(i);
    path=char(strcat('our/',str1,'-raw-data-plot-tri.txt'));
    properties=dlmread(path,',',[5 0 5 9]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);KW=properties(9);KWT=properties(10);
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=700;
    data=dlmread(path,',',9);
    point_number=1.0*size(data,1)/(iteration+1);
    n=zeros(point_number,1);
    ObRseTour=0;
    EstRseTour=0;
    AproxEstRseT=0;
    p=0;
    m=0;
    mour=0;
    ObRseTgpsin=0;
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        pour(h)=data(start,1);
       mour(1)=floor(pour(h)*M);
    end
    
     
    path=char(strcat('ratioCompare/',str1,'-raw-data-plot-gps-in.txt'));
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=20;
    data=dlmread(path,',',9);
    point_number=floor(1.0*size(data,1)/(iteration+1));
    n=zeros(point_number,1);
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        mgpsin(1)=data(start,1);
    end
    
     pathREG=char(strcat('OurCIKM1PassStreaming/',str1,'-raw-data-plot-TriCIKM1p.txt'));
    properties=dlmread(pathREG,',',[5 0 5 6]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);   
    iteration=dlmread(pathREG,',',[6 0 6 0]);
    data_REG=dlmread(pathREG,',',9);
    point_number2=1.0*size(data_REG,1)/(iteration+1);  
    
    ApproxRatio=0;
    point_number=4;
    for h=1:point_number       
        start=(h-1)*(iteration+1)+1;    
        p(h)=data_REG(start,1);               
        mcikmour(1)=floor(p(h)*M);
    end
    h1=subplot(1,4,1)
    h=1;
    name = {' ' ;' ' ;' ';''};    
    m=[2*mour(h) mgpsin(h) mcikmour(h) ];
    z1=(i-1)*3.1;
    a1=z1+0.9+floor(z1/3.1);
    line1=bar(a1,2*mour(h),'k','BarWidth',0.7);   
    hold on
    a3=z1+2.05+floor(z1/3.1);
    line3=bar(a3,mgpsin(h),'w','BarWidth',0.7); 
    hold on
    a2=z1+3.25+floor(z1/3.1);
    line2=bar(a2,mcikmour(h),'c','BarWidth',0.7);    
    po=[a1 a3 a2];
    text(po,m,num2str(m'),'vert','bottom','horiz','center','FontSize',5);
    set(gca,'xticklabel','');
    po1(i)=a3;
    labels(i)=str1;     
    if i==7
        set(gca,'xtick',po1(i-6:i),'xticklabel',labels(i-6:i),'FontSize',7);
        xticklabel_rotate(get(gca,'xtick'),45,get(gca,'xticklabel'));   
    end
    xlim([0 28.5 ]);
    ylabel('Sample sizes','FontSize',12,'Interpreter','Latex');
end
%box off;

p = get(h1, 'position');
    p(1)=p(1)-0.05;
    p(2)=p(2)-0.018;
    p(3)=p(3)+0.06;  %+0.036;
    p(4)=p(4)-0.48;
set(h1, 'position', p);

data_name={'Brightkite';'Facebook';'Epinions';'Digg';...
             'Gowalla';'FLicker'};
size_subplot=size(data_name,1);
for i=1: size_subplot
    str1=data_name(i);
    path=char(strcat('our/',str1,'-raw-data-plot-tri.txt'));
    properties=dlmread(path,',',[5 0 5 9]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);KW=properties(9);KWT=properties(10);
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=700;
    data=dlmread(path,',',9);
    point_number=1.0*size(data,1)/(iteration+1);
    n=zeros(point_number,1);
    ObRseTour=0;
    EstRseTour=0;
    AproxEstRseT=0;
    p=0;
    m=0;
    mour=0;
    ObRseTgpsin=0;
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        pour(h)=data(start,1);
       mour(1)=floor(pour(h)*M);
    end
    
     
    path=char(strcat('ratioCompare/',str1,'-raw-data-plot-gps-in.txt'));
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=20;
    data=dlmread(path,',',9);
    point_number=floor(1.0*size(data,1)/(iteration+1));
    n=zeros(point_number,1);
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        mgpsin(1)=data(start,1);
    end
    
     pathREG=char(strcat('OurCIKM1PassStreaming/',str1,'-raw-data-plot-TriCIKM1p.txt'));
    properties=dlmread(pathREG,',',[5 0 5 6]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);   
    iteration=dlmread(pathREG,',',[6 0 6 0]);
    data_REG=dlmread(pathREG,',',9);
    point_number2=1.0*size(data_REG,1)/(iteration+1);  
    
    ApproxRatio=0;
    point_number=4;
    for h=1:point_number       
        start=(h-1)*(iteration+1)+1;    
        p(h)=data_REG(start,1);               
        mcikmour(1)=floor(p(h)*M);
    end
    h2=subplot(1,4,2)
    name = {' ' ;' ' ;' ';''}; 
    h=1;
    m=[2*mour(h) mgpsin(h) mcikmour(h) ];
    z1=(i-1)*3.1;
    a1=z1+0.9+floor(z1/3.1);
    line1=bar(a1,2*mour(h),'k','BarWidth',0.7);   
    hold on
    a3=z1+2.05+floor(z1/3.1);
    line3=bar(a3,mgpsin(h),'w','BarWidth',0.7); 
    hold on
    a2=z1+3.25+floor(z1/3.1);
    line2=bar(a2,mcikmour(h),'c','BarWidth',0.7);    
    po=[a1 a3 a2];
    text(po,m,num2str(m'),'vert','bottom','horiz','center','FontSize',5);
    set(gca,'xticklabel','');
    po1(i)=a3;
    labels(i)=str1;     
    if i==6
        set(gca,'xtick',po1(i-5:i),'xticklabel',labels(i-5:i),'FontSize',7);
        xticklabel_rotate(get(gca,'xtick'),45,get(gca,'xticklabel'));   
    end
    xlim([0 24.5 ]);
end
%box off;

p = get(h2, 'position');
    p(1)=p(1)-0.06;
    p(2)=p(2)+0.0005;
    p(3)=p(3)+0.03;  %+0.036;
    p(4)=p(4)-0.49;
set(h2, 'position', p);

data_name={'Douban';'Libimseti';'Amazon';'Dblp';'Hollywood';'Pokec';'LiveJournal';'Orkut';'Web-Arabic'};

size_subplot=size(data_name,1);
for i=1: size_subplot
    str1=data_name(i);
    path=char(strcat('our/',str1,'-raw-data-plot-tri.txt'));
    properties=dlmread(path,',',[5 0 5 9]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);KW=properties(9);KWT=properties(10);
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=700;
    data=dlmread(path,',',9);
    point_number=1.0*size(data,1)/(iteration+1);
    n=zeros(point_number,1);
    ObRseTour=0;
    EstRseTour=0;
    AproxEstRseT=0;
    p=0;
    m=0;
    mour=0;
    ObRseTgpsin=0;
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        pour(h)=data(start,1);
       mour(1)=floor(pour(h)*M);
    end
    
     
    path=char(strcat('ratioCompare/',str1,'-raw-data-plot-gps-in.txt'));
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=20;
    data=dlmread(path,',',9);
    point_number=floor(1.0*size(data,1)/(iteration+1));
    n=zeros(point_number,1);
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        mgpsin(1)=data(start,1);
    end
    
     pathREG=char(strcat('OurCIKM1PassStreaming/',str1,'-raw-data-plot-TriCIKM1p.txt'));
    properties=dlmread(pathREG,',',[5 0 5 6]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);   
    iteration=dlmread(pathREG,',',[6 0 6 0]);
    data_REG=dlmread(pathREG,',',9);
    point_number2=1.0*size(data_REG,1)/(iteration+1);  
    
    ApproxRatio=0;
    point_number=4;
    for h=1:point_number       
        start=(h-1)*(iteration+1)+1;    
        p(h)=data_REG(start,1);               
        mcikmour(1)=floor(p(h)*M);
    end
    h2=subplot(1,4,3)
    name = {' ' ;' ' ;' ';''};  
    h=1;
    m=[2*mour(h) mgpsin(h) mcikmour(h) ];
    z1=(i-1)*3.1;
    a1=z1+0.9+floor(z1/3.1);
    line1=bar(a1,2*mour(h),'k','BarWidth',0.7);   
    hold on
    a3=z1+2.05+floor(z1/3.1);
    line3=bar(a3,mgpsin(h),'w','BarWidth',0.7); 
    hold on
    a2=z1+3.25+floor(z1/3.1);
    line2=bar(a2,mcikmour(h),'c','BarWidth',0.7);    
    po=[a1 a3 a2];
    text(po,m,num2str(m'),'vert','bottom','horiz','center','FontSize',5);
    set(gca,'xticklabel','');
    po1(i)=a3;
    labels(i)=str1;     
    if i==9
        set(gca,'xtick',po1(i-8:i),'xticklabel',labels(i-8:i),'FontSize',7);
        xticklabel_rotate(get(gca,'xtick'),45,get(gca,'xticklabel'));   
    end
    xlim([0 37 ]);
end
%box off;

p = get(h2, 'position');
    p(1)=p(1)-0.09;
    p(2)=p(2)-0.0075;
    p(3)=p(3)+0.14;  %+0.036;
    p(4)=p(4)-0.48;
set(h2, 'position', p);

data_name={'MicrosoftAG';'Friendster'};

size_subplot=size(data_name,1);
for i=1: size_subplot
    str1=data_name(i);
    path=char(strcat('our/',str1,'-raw-data-plot-tri.txt'));
    properties=dlmread(path,',',[5 0 5 9]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);KW=properties(9);KWT=properties(10);
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=700;
    data=dlmread(path,',',9);
    point_number=1.0*size(data,1)/(iteration+1);
    n=zeros(point_number,1);
    ObRseTour=0;
    EstRseTour=0;
    AproxEstRseT=0;
    p=0;
    m=0;
    mour=0;
    ObRseTgpsin=0;
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        pour(h)=data(start,1);
       mour(1)=floor(pour(h)*M);
    end
    
     
    path=char(strcat('ratioCompare/',str1,'-raw-data-plot-gps-in02.txt'));
    iteration=dlmread(path,',',[6 0 6 0]);
    %iteration=20;
    data=dlmread(path,',',9);
    point_number=floor(1.0*size(data,1)/(iteration+1));
    n=zeros(point_number,1);
    point_number=4;
    for h=1:point_number
        start=(h-1)*(iteration+1)+1;
        mgpsin(1)=data(start,1);
    end
    
     pathREG=char(strcat('OurCIKM1PassStreaming/',str1,'-raw-data-plot-TriCIKM1p.txt'));
    properties=dlmread(pathREG,',',[5 0 5 6]);
    C=properties(1); N=properties(2); M=properties(3); T=properties(4); K=properties(5); CW=properties(6); W=properties(7);   
    iteration=dlmread(pathREG,',',[6 0 6 0]);
    data_REG=dlmread(pathREG,',',9);
    point_number2=1.0*size(data_REG,1)/(iteration+1);  
    
    ApproxRatio=0;
    point_number=4;
    for h=1:point_number       
        start=(h-1)*(iteration+1)+1;    
        p(h)=data_REG(start,1);               
        mcikmour(1)=floor(p(h)*M);
    end
    h2=subplot(1,4,4)
    name = {' ' ;' ' ;' ';''}; 
    h=1;
    m=[2*mour(h) mgpsin(h) mcikmour(h) ];
    z1=(i-1)*3.1;
    a1=z1+0.9+floor(z1/3.1);
    line1=bar(a1,2*mour(h),'k','BarWidth',0.7);   
    hold on
    a3=z1+2.05+floor(z1/3.1);
    line3=bar(a3,mgpsin(h),'w','BarWidth',0.7); 
    hold on
    a2=z1+3.25+floor(z1/3.1);
    line2=bar(a2,mcikmour(h),'c','BarWidth',0.7);    
    po=[a1 a3 a2];
    text(po,m,num2str(m'),'vert','bottom','horiz','center','FontSize',5);
    set(gca,'xticklabel','');
    po1(i)=a3;
    labels(i)=str1;     
    if i==2
        set(gca,'xtick',po1(i-1:i),'xticklabel',labels(i-1:i),'FontSize',7);
        xticklabel_rotate(get(gca,'xtick'),45,get(gca,'xticklabel'));   
    end
    xlim([0 8 ]);
end
%box off;

p = get(h2, 'position');
    p(1)=p(1)-0.02;
    p(2)=p(2)-0.012;
    p(3)=p(3)-0.045;  %+0.036;
    p(4)=p(4)-0.48;
set(h2, 'position', p);


%xticks([a2])
hL = legend([line1 line3 line2],{'$PES$ ','GPS-In','$NES$'},'FontSize',8, 'LineWidth', 1,'interpreter','latex','Orientation','horizontal');
newPosition = [0.42 0.08 0.0001 0.01];
newUnits = 'normalized';
set(hL,'Position', newPosition,'Units', newUnits);
legend('boxoff');
set(gcf,'color','w');
export_fig Fig3 -painters -eps

