Skip to content

Commit

Permalink
v 1.0.3 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
manlius committed Oct 18, 2015
1 parent a4dca6d commit 9596107
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 29 deletions.
7 changes: 7 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 18 October 2015

Manlio De Domenico:

Added support for standard degree centrality even in case of weighted networks


### 4 October 2015

Manlio De Domenico:
Expand Down
2 changes: 1 addition & 1 deletion muxVizGUI.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if(!require(shiny)){
devtools::install_github("rstudio/shiny-incubator")
}else{
#check the version, and in case update to the latest one
if(packageDescription("shiny")$Version!="0.12.1"){
if(packageDescription("shiny")$Version!="0.12.1" || packageDescription("shiny")$Version!="0.12.2"){
#install.packages("shiny")
library(devtools)
install.packages("shiny")
Expand Down
35 changes: 35 additions & 0 deletions octave/muxMultisliceCentralityInStrength.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
addpath("octave");

%import the muxOctaveLib
muxOctaveLib;

%import the configuration file
LayersList = {};
muxOctaveConfig;

NodesTensor = {};
Layers = 0;
SupraAdjacencyMatrix = 0;

if isExtendedEdgesList
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
else
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
endif

% Calculate the centralities

CentralityVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_instrength.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);

#aggregate
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
CentralityVector = GetMultiInStrengthSum(Aggregate,1,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_instrength_aggregate.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);
36 changes: 36 additions & 0 deletions octave/muxMultisliceCentralityOutStrength.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
addpath("octave");

%import the muxOctaveLib
muxOctaveLib;

%import the configuration file
LayersList = {};
muxOctaveConfig;

NodesTensor = {};
Layers = 0;
SupraAdjacencyMatrix = 0;

if isExtendedEdgesList
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
else
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
endif


% Calculate the centralities

CentralityVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_outstrength.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);

#aggregate
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
CentralityVector = GetMultiOutStrengthSum(Aggregate,1,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_outstrength_aggregate.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);
35 changes: 35 additions & 0 deletions octave/muxMultisliceCentralityStrength.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
addpath("octave");

%import the muxOctaveLib
muxOctaveLib;

%import the configuration file
LayersList = {};
muxOctaveConfig;

NodesTensor = {};
Layers = 0;
SupraAdjacencyMatrix = 0;

if isExtendedEdgesList
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
else
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
endif

% Calculate the centralities

CentralityVector = GetMultiStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_Strength.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);

#aggregate
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
CentralityVector = GetMultiStrengthSum(Aggregate,1,Nodes,Flags);
outputFile = strcat(AnalysisName,"_centrality_Strength_aggregate.txt");
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
printf("Multislice centrality output to: %s\n",outputFile);
164 changes: 153 additions & 11 deletions octave/muxOctaveLib.m
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,19 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function BinaryMatrix = binarizeMatrix(Matrix)
BinaryMatrix = double(Matrix|Matrix);
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiDegreeVector = GetMultiDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags)
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)

MultiInDegreeVector = GetMultiInDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiOutDegreeVector = GetMultiOutDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiInDegreeVector = GetMultiInDegree(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
MultiOutDegreeVector = GetMultiOutDegree(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);

if ismember("U",Flags)
MultiDegreeVector = (MultiInDegreeVector + MultiOutDegreeVector)/2;
Expand All @@ -541,7 +548,7 @@

if ismember("U",Flags)
%we proceed by considering the interlayers separately
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
BlockTensor = SupraAdjacencyToBlockTensor(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes);

MultiOutDegreeVector = sparse(Nodes,1);

Expand All @@ -559,7 +566,7 @@
endfor
endfor
else
SupraDegree = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
SupraDegree = binarizeMatrix(SupraAdjacencyMatrix)*ones(Nodes*Layers,1);

MultiOutDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
endif
Expand All @@ -575,10 +582,10 @@

if ismember("U",Flags)
%using the following would consider multiple times the interlinks
%SupraDegree = (SupraAdjacencyMatrix*ones(Nodes*Layers,1) + (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)')/2;
%SupraDegree = (binarizeMatrix(SupraAdjacencyMatrix)*ones(Nodes*Layers,1) + (ones(1,Nodes*Layers)*binarizeMatrix(SupraAdjacencyMatrix))')/2;

%we proceed by considering the interlayers separately
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
BlockTensor = SupraAdjacencyToBlockTensor(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes);

MultiInDegreeVector = sparse(Nodes,1);

Expand All @@ -596,7 +603,7 @@
endfor
endfor
else
SupraDegree = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
SupraDegree = (ones(1,Nodes*Layers)*binarizeMatrix(SupraAdjacencyMatrix))';

MultiInDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
endif
Expand All @@ -609,8 +616,8 @@
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)

MultiInDegreeVector = GetMultiInDegreeSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiOutDegreeVector = GetMultiOutDegreeSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiInDegreeVector = GetMultiInDegreeSum(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
MultiOutDegreeVector = GetMultiOutDegreeSum(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);

if ismember("U",Flags)
MultiDegreeVector = (MultiInDegreeVector + MultiOutDegreeVector)/2;
Expand All @@ -628,7 +635,7 @@
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


SupraDegree = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
SupraDegree = binarizeMatrix(SupraAdjacencyMatrix)*ones(Nodes*Layers,1);
MultiOutDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
endfunction

Expand All @@ -641,10 +648,145 @@
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


SupraDegree = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
SupraDegree = (ones(1,Nodes*Layers)*binarizeMatrix(SupraAdjacencyMatrix))';
MultiInDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
endfunction


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiStrengthVector = GetMultiStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)

MultiInStrengthVector = GetMultiInStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiOutStrengthVector = GetMultiOutStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags);

if ismember("U",Flags)
MultiStrengthVector = (MultiInStrengthVector + MultiOutStrengthVector)/2;
else
MultiStrengthVector = MultiInStrengthVector + MultiOutStrengthVector;
endif
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiOutStrengthVector = GetMultiOutStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


if ismember("U",Flags)
%we proceed by considering the interlayers separately
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);

MultiOutStrengthVector = sparse(Nodes,1);

%with the matrix U we reweight interlinks corresponding to same replicas
U = ones(Nodes,Nodes);
U(logical(speye(size(U)))) = 1/2;

for i = 1:Layers
for j = 1:Layers
if i==j
MultiOutStrengthVector += (BlockTensor{i,j}-diag(diag(BlockTensor{i,j})))*ones(Nodes,1) + diag(BlockTensor{i,j})*0.5;
else
MultiOutStrengthVector += (BlockTensor{i,j} .* U)*ones(Nodes,1);
endif
endfor
endfor
else
SupraStrength = SupraAdjacencyMatrix*ones(Nodes*Layers,1);

MultiOutStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
endif
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiInStrengthVector = GetMultiInStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


if ismember("U",Flags)
%using the following would consider multiple times the interlinks
%SupraStrength = (SupraAdjacencyMatrix*ones(Nodes*Layers,1) + (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)')/2;

%we proceed by considering the interlayers separately
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);

MultiInStrengthVector = sparse(Nodes,1);

%with the matrix U we reweight interlinks corresponding to same replicas
U = ones(Nodes,Nodes);
U(logical(speye(size(U)))) = 1/2;

for i = 1:Layers
for j = 1:Layers
if i==j
MultiInStrengthVector += (ones(1,Nodes)*(BlockTensor{i,j}-diag(diag(BlockTensor{i,j}))))' + diag(BlockTensor{i,j})*0.5;
else
MultiInStrengthVector += (ones(1,Nodes)*(BlockTensor{i,j} .* U))';
endif
endfor
endfor
else
SupraStrength = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';

MultiInStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
endif
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiStrengthVector = GetMultiStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)

MultiInStrengthVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
MultiOutStrengthVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);

if ismember("U",Flags)
MultiStrengthVector = (MultiInStrengthVector + MultiOutStrengthVector)/2;
else
MultiStrengthVector = MultiInStrengthVector + MultiOutStrengthVector;
endif
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiOutStrengthVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
%this Strength include multiple times the interlinks
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


SupraStrength = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
MultiOutStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function MultiInStrengthVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
%this Strength include multiple times the interlinks
% References:
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)


SupraStrength = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
MultiInStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
endfunction




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Expand Down
Loading

0 comments on commit 9596107

Please sign in to comment.