%Feb 2017, Etemadi and Lu
% The Bias of C of EG

% Data format:
% #run,# sampled edges,CW,W,CW in g,Psi_g,Omega_g,CW checked in G
%Example
%2,1021,6,33,0,6,13,1

%set(0,'defaulttextinterpreter','latex');
clear all;clf('reset');
data_name={'Ego-facebook';'CA-GrQc';'Wiki-Vote';'AstroPh';'CA-CondMat';'HepPh';'Enron-email';'Brightkite';'Facebook';'Epinions';'Slashdot-Zoo';'Prosper';'Livemocha';'Douban';'Gowalla';'Libimseti';'Digg';'Web-Stanford';'Dblp-Coau';...
    'Amazon';'Actor';'Web-NotreDame';'Citeseer';'Dogster';'Catster';'Web-Berkeley';'Web-Google';'Youtube';'Dblp';'Hyves';	'Wiki-Polish';'Trec-wt10g';'Wiki-Portuguese';'Wiki-Japanese';'Pokec';'As-skitter';...
    'Wiki-Italian';'Wiki-En';'Hudong';'Hollywood';'Baidu' ;'FLicker';'Flixster';'Wiki-Russian';'Wiki-Franch';'Orkut';'Wiki-German';'USpatent';'LiveJournal';... 
    'Orkut2';'DBpedia';'Web-Arabic';'Gsh-2015';'Twitter';'MicrosoftAG';'Friendster'};

size_subplot=size(data_name,1)

for i=1: size_subplot
    path=char(strcat('Results_EG_Bias_RSE0.2_p/',data_name(i),'-raw-data-plot-REG.txt'));
    properties=dlmread(path,',',[5 0 5 9]);
    C=properties(1); N=properties(2); M=properties(3); triangles=properties(4); K=properties(5); CW=properties(6); W=properties(7);KW=properties(9);KWT=properties(10);
    Omega=2*KWT+6*triangles;
    Psi=KW;
    CW=3*triangles;
    
    iteration=dlmread(path,',',[6 0 6 0]);
    data=dlmread(path,',',9);
    point_number=1.0*size(data,1)/(iteration+1);
       
    path=char(strcat('d3d2/',data_name(i),'.txt'));
    d3d2=dlmread(path,' ',[0 0 0 1]);
    d3=d3d2(1);
    d2=d3d2(2);
    
    size_M(i)=2*Psi/(W^2);
    size_M2(i)=4*d3/(N*d2^2);
    for j=1:point_number
        start=(j-1)*(iteration+1)+1;
        p(j)=data(start,1);
        start=start+1;
        
        % read Lambda_g and Delta_g and compute Obs_RB
        ob_Lambda_g=data(start:start+iteration-1,4);
        ob_Delta_g=data(start:start+iteration-1,3);
        obs_c=(ob_Delta_g)./(ob_Lambda_g);
        obs_RB(i)=(mean(obs_c)-C)/C;
        
               
        %n1=n(j);
        p1=p(j);
        size_M(i)=size_M(i)/p1;
        size_M2(i)=size_M2(i)/p1;
        
        est_RB_exact(i)=(2.0/p1)*(Psi/(W^2))-(1.0/p1)*(Omega/(CW*W));
        
        t1(i)=(2.0/p1)*(Psi/(W^2));
       names{i}=num2str(i);
    end
end

fig=figure;
line1=plot(est_RB_exact,obs_RB,'x','MarkerSize',8);

%set(gca, 'Position', [0.3 0.44 0.3 0.5]);
ylabel('RB','FontSize',12,'Interpreter','Latex');
xlabel('$\frac{1}{p}(2\Psi/\Lambda^2-\Omega/\Delta\Lambda)$','FontSize',12,'Interpreter','Latex');
set(gcf,'color','w');
export_fig rb_term1t2_p -painters -eps
%saveas(fig,'rb_term1t2_etemadi','epsc')

 fig2=figure
 a=1:12;
 plot(t1,obs_RB,'x','MarkerSize',8);
 ylabel('RB','FontSize',11);
 xlabel('$2\Psi/p\Lambda^2$','FontSize',12,'Interpreter','Latex')
 text(t1(a), obs_RB(a), names(a),'FontSize',12);
% %saveas(fig2,'rb_term1_etemadi','epsc')
 set(gcf,'color','w');
 export_fig rb_term1_p -painters -eps

