function [SWN_spr,SWN_erd,SWP_spr,SWP_erd,CC_WN_erd,CC_WN_spr1,L_WN_erd,L_WN_spr1,deltaC_erd,deltaC_spr,deltaL_erd,deltaL_spr,global_CC,L_real,CC_latt_erd,L_latt_erd,L_latt_spr,CC_latt_spr,L_rand1_spr,CC_rand1_spr,CC_rand_erd,L_rand_erd,degree_spr_latt,degree_spr_rand,degree_erd_latt,degree_erd_rand,hubs] = small_world_analysis_new(signf_edges_0,dim,neuron,com_x,com_y)
% small_world_analysis_new: small world analysis following Sporns Erdös like
% and Erdös-Rényi methods. 
%
% INPUTS:
%   signf_edges_0: significant connections between neurons
%   dim: number of neurons
%   neuron: array that contains the exact neurons we are working with
%   com_x: x coordenates of the position of each neuron
%   com_y: y coordenates of the position of each neuron
%
% OUTPUTS:
%   SWN_spr: small-worldness coefficient (Sporns Erdös like)
%   SWN_erd: small-worldness coefficient (Erdös-Rényi method)
%   SWP_spr: small-world propensity coefficient (Sporns Erdös like)
%   SWP_erd: small-world propensity coefficient (Erdös-Rényi method)
%   CC_WN_erd: parameter needed to compute the small-worldness coefficient (Erdös-Rényi method)
%   CC_WN_spr1: parameter needed to compute the small-worldness coefficient (Sporns Erdös like)
%   L_WN_erd: parameter needed to compute the small-worldness coefficient (Erdös-Rényi method)
%   L_WN_spr1: parameter needed to compute the small-worldness coefficient (Sporns Erdös like)
%   deltaC_erd: parameter needed to compute the small-world propensity coefficient (Erdös-Rényi method)
%   deltaC_spr: parameter needed to compute the small-world propensity coefficient (Sporns Erdös like)
%   deltaL_erd: parameter needed to compute the small-world propensity coefficient (Erdös-Rényi method)
%   deltaL_spr: parameter needed to compute the small-world propensity coefficient (Sporns Erdös like)
%   global_CC: clustering coefficient (transitivity) of the real network
%   L_real: shortest path length of the real network
%   CC_latt_erd: clustering coefficient (transitivity) of the lattice network (Erdös-Rényi method)
%   L_latt_erd: shortest path length of the lattice network (Erdös-Rényi method)
%   L_latt_spr: shortest path length of the lattice network (Sporns Erdös like)
%   CC_latt_spr: clustering coefficient (transitivity) of the lattice network (Sporns Erdös like)
%   L_rand1_spr: shortest path length of the random network (Sporns Erdös like)
%   CC_rand1_spr: clustering coefficient (transitivity) of the random network (Sporns Erdös like)
%   CC_rand_erd: clustering coefficient (transitivity) of the random network (Erdös-Rényi method)
%   L_rand_erd: shortest path length of the random network (Erdös-Rényi method)
%   degree_spr_latt: degree of connectivity of the lattice network (Sporns Erdös like)
%   degree_spr_rand: degree of connectivity of the random network (Sporns Erdös like)
%   degree_erd_latt: degree of connectivity of the lattice network (Erdös-Rényi method)
%   degree_erd_rand: degree of connectivity of the random network (Erdös-Rényi method)
%   hubs: neurons which degree is above 0.90 percentile.

addpath('BCT\2017_01_15_BCT');

%create the connection matrix
for i = 1:size(signf_edges_0,1)
    conn_matrix(signf_edges_0(i,1),signf_edges_0(i,2)) = 1;    
end

%make the connection matrix unidirectional 
for i = 1:dim
    for j = 1:dim
        if conn_matrix(neuron(i),neuron(j))~=conn_matrix(neuron(j),neuron(i))
            conn_matrix(neuron(i),neuron(j)) = 1;
            conn_matrix(neuron(j),neuron(i)) = 1;
        end
    end
end

%unidirectional edges
uni_edges  = [];
uni_conn_matrix = triu(conn_matrix);
aux = 1;
for i = 1:size(uni_conn_matrix,1)
    for j = 1:size(uni_conn_matrix,2)
        if uni_conn_matrix(i,j)==1
            uni_edges(aux,1)=i;
            uni_edges(aux,2)=j;
            aux = aux+1;
        end
    end
end

%plot of the graph
plot_graph(uni_edges,neuron,com_x,com_y)

%unidirectional global CC
global_CC = clustering_coefficient_v2(uni_edges,dim,neuron);

%DoC
[degree,mean_degree,hubs] = DoC(conn_matrix);

% shortest path length
DG = sparse(signf_edges_0(:,1),signf_edges_0(:, 2),1); %unweight
[short_path_edges ] = graphallshortestpaths(DG,'directed',false);
L_real              = sum(short_path_edges(short_path_edges~=Inf))/(dim*(dim-1));

%% lattice Erdös-Rényi
%compute k coefficient. It must be an even number.
k = ceil(mean_degree)
if mod(k,2) ~= 0
    k = k-1;
end

%create the lattice network
erd_latt = erdosRenyi(dim,0,k);
erd_latt_m = full(erd_latt.Adj);
erd_latt_uni = triu(erd_latt_m,1);

%number of unidirectional edges
n_edg_erd_latt = sum(sum(erd_latt_uni))

%find the connected edges. 
%Create 2 columns matrix with these connections. 
%Column 1: neuron A. Column 2: neuron B.
edg_latt_erd = [];
aux = 1;
for i = 1:size(erd_latt_uni,1)
    for j = 1:size(erd_latt_uni,2)
        if erd_latt_uni(i,j)==1
            edg_latt_erd(aux,1)=i;
            edg_latt_erd(aux,2)=j;
            aux = aux+1;
        end
    end
end

%degree of connectivity
[degree_erd_latt,mean_degree_erd_latt,~] = DoC(erd_latt_m);

%Clustering coefficient
CC_latt_erd = clustering_coefficient_v2(edg_latt_erd,dim,1:dim)

%Shortest path length
[SP_latt_erd] = graphallshortestpaths(erd_latt.Adj,'directed',false);
L_latt_erd    = (sum(SP_latt_erd(SP_latt_erd~=Inf)))/(dim*(dim-1))

%% lattice Sporns Erdös like
%compute the total number of edges of the lattice network constructed by
%following Erdös-Rényi method
n_edges  = sum(sum(erd_latt_m));
%create the lattice network
spr_latt = makeringlatticeCIJ(dim,n_edges);
spr_latt_uni = triu(spr_latt,1);

%number of unidirectional edges
n_edg_spr_latt = sum(sum(spr_latt_uni))

%find the connected edges. 
%Create 2 columns matrix with these connections. 
%Column 1: neuron A. Column 2: neuron B.
edg_latt_spr = [];
aux = 1;
for i = 1:size(spr_latt_uni,1)
    for j = 1:size(spr_latt_uni,2)
        if spr_latt_uni(i,j)==1
            edg_latt_spr(aux,1)=i;
            edg_latt_spr(aux,2)=j;
            aux = aux+1;
        end
    end
end

%degree of connectivity
[degree_spr_latt,~,~] = DoC(spr_latt);

%Clustering coefficient
CC_latt_spr = clustering_coefficient_v2(edg_latt_spr,dim,1:dim)

%Shortest Path Length
DG = sparse(spr_latt);
[SP_latt_spr] = graphallshortestpaths(DG,'directed',false);
L_latt_spr = (sum(SP_latt_spr(SP_latt_spr~=Inf)))/(dim*(dim-1))

%% random  Sporns Erdös like
%compute the unidirectional number of edges of the lattice network
%constructed by following Erdös-Rényi method
n_edges  = sum(sum(erd_latt_uni));

%create the random network
spr_rand1 = makerandCIJ_und(dim,n_edges);
spr_rand1_uni = triu(spr_rand1,1);

%number of unidirectional edges
n_edg_spr_rand1 = sum(sum(spr_rand1_uni))

%find the connected edges. 
%Create 2 columns matrix with these connections. 
%Column 1: neuron A. Column 2: neuron B.
edg_rand1_spr = [];
aux = 1;
for i = 1:size(spr_rand1_uni,1)
    for j = 1:size(spr_rand1_uni,2)
        if spr_rand1_uni(i,j)==1
            edg_rand1_spr(aux,1)=i;
            edg_rand1_spr(aux,2)=j;
            aux = aux+1;
        end
    end
end

%degree of connectivity
[degree_spr_rand,~,~] = DoC(spr_rand1);

%Clustering coefficient
CC_rand1_spr = clustering_coefficient_v2(edg_rand1_spr,dim,1:dim)

%Shortest Path Length
DG = sparse(spr_rand1);
[SP_rand1_spr] = graphallshortestpaths(DG,'directed',false);
L_rand1_spr = (sum(SP_rand1_spr(SP_rand1_spr~=Inf)))/(dim*(dim-1))

%% random Erdös-Rényi
%create the random network
erd_rand = erdosRenyi(dim,1,k);
erd_rand_m = full(erd_rand.Adj);
erd_rand_uni = triu(erd_rand_m,1);

%make the random graph undirectional
erd_rand_m = [];
for i = 1:size(erd_rand_uni,1)
    for j = 1:size(erd_rand_uni,2)
        if erd_rand_uni(i,j) == 1
            erd_rand_m(i,j) = 1;
            erd_rand_m(j,i) = 1;  
        end
    end
end

%number of unidirectional edges
n_edg_erd_rand = sum(sum(erd_rand_uni))

%find the connected edges. 
%Create 2 columns matrix with these connections. 
%Column 1: neuron A. Column 2: neuron B.
edg_rand_erd = [];
aux = 1;
for i = 1:size(erd_rand_uni,1)
    for j = 1:size(erd_rand_uni,2)
        if erd_rand_uni(i,j)==1
            edg_rand_erd(aux,1)=i;
            edg_rand_erd(aux,2)=j;
            aux = aux+1;
        end
    end
end

%degree of connectivity
[degree_erd_rand,~,~] = DoC(erd_rand_m);

%Clustering Coefficient
CC_rand_erd = clustering_coefficient_v2(edg_rand_erd,dim,1:dim);

%Shortest Path Length
DG_rand = sparse(erd_rand_m);
[SP_rand_erd] = graphallshortestpaths(DG_rand,'directed',false);
L_rand_erd    = (sum(SP_rand_erd(SP_rand_erd~=Inf)))/(dim*(dim-1))

%% Small-Worldness
CC_WN_erd = global_CC/CC_rand_erd;
CC_WN_spr1 = global_CC/CC_rand1_spr;

L_WN_erd = L_real/L_rand_erd;
L_WN_spr1 = L_real/L_rand1_spr;

%small-worldness coefficients 
SWN_erd = CC_WN_erd/L_WN_erd;
SWN_spr = CC_WN_spr1/L_WN_spr1;

%% small propensity

deltaC_erd = (CC_latt_erd - global_CC)/(CC_latt_erd-CC_rand_erd);
%limit the coefficient deltaC_erd between [0,1]
if deltaC_erd > 1
    deltaC_erd = 1;
elseif deltaC_erd < 0
    deltaC_erd = 0;
end
%limit the coefficient deltaL_erd between [0,1]
deltaL_erd = (L_real - L_rand_erd)/(L_latt_erd - L_rand1_spr);
if deltaL_erd > 1
    deltaL_erd = 1;
elseif deltaL_erd < 0
    deltaL_erd = 0;
end

%small-world propensity coefficient
SWP_erd = 1 - sqrt((power(deltaC_erd,2) + power(deltaL_erd,2))/2);

%limit the coefficient deltaC_spr between [0,1]
deltaC_spr = (CC_latt_spr - global_CC)/(CC_latt_spr-CC_rand1_spr);
if deltaC_spr > 1
    deltaC_spr = 1;
elseif deltaC_spr < 0
    deltaC_spr = 0;
end
%limit the coefficient deltaL_spr between [0,1]
deltaL_spr = (L_real - L_rand1_spr)/(L_latt_spr - L_rand1_spr);
if deltaL_spr > 1
    deltaL_spr = 1;
elseif deltaL_spr < 0
    deltaL_spr = 0;
end

%small-world propensity coefficients
SWP_spr = 1 - sqrt((power(deltaC_spr,2) + power(deltaL_spr,2))/2);