Skip to content

Commit 9596107

Browse files
committed
v 1.0.3 beta
1 parent a4dca6d commit 9596107

File tree

9 files changed

+447
-29
lines changed

9 files changed

+447
-29
lines changed

history.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 18 October 2015
2+
3+
Manlio De Domenico:
4+
5+
Added support for standard degree centrality even in case of weighted networks
6+
7+
18
### 4 October 2015
29

310
Manlio De Domenico:

muxVizGUI.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(!require(shiny)){
1313
devtools::install_github("rstudio/shiny-incubator")
1414
}else{
1515
#check the version, and in case update to the latest one
16-
if(packageDescription("shiny")$Version!="0.12.1"){
16+
if(packageDescription("shiny")$Version!="0.12.1" || packageDescription("shiny")$Version!="0.12.2"){
1717
#install.packages("shiny")
1818
library(devtools)
1919
install.packages("shiny")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
addpath("octave");
2+
3+
%import the muxOctaveLib
4+
muxOctaveLib;
5+
6+
%import the configuration file
7+
LayersList = {};
8+
muxOctaveConfig;
9+
10+
NodesTensor = {};
11+
Layers = 0;
12+
SupraAdjacencyMatrix = 0;
13+
14+
if isExtendedEdgesList
15+
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
16+
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
17+
else
18+
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
19+
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
20+
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
21+
endif
22+
23+
% Calculate the centralities
24+
25+
CentralityVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
26+
outputFile = strcat(AnalysisName,"_centrality_instrength.txt");
27+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
28+
printf("Multislice centrality output to: %s\n",outputFile);
29+
30+
#aggregate
31+
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
32+
CentralityVector = GetMultiInStrengthSum(Aggregate,1,Nodes,Flags);
33+
outputFile = strcat(AnalysisName,"_centrality_instrength_aggregate.txt");
34+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
35+
printf("Multislice centrality output to: %s\n",outputFile);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
addpath("octave");
2+
3+
%import the muxOctaveLib
4+
muxOctaveLib;
5+
6+
%import the configuration file
7+
LayersList = {};
8+
muxOctaveConfig;
9+
10+
NodesTensor = {};
11+
Layers = 0;
12+
SupraAdjacencyMatrix = 0;
13+
14+
if isExtendedEdgesList
15+
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
16+
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
17+
else
18+
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
19+
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
20+
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
21+
endif
22+
23+
24+
% Calculate the centralities
25+
26+
CentralityVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
27+
outputFile = strcat(AnalysisName,"_centrality_outstrength.txt");
28+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
29+
printf("Multislice centrality output to: %s\n",outputFile);
30+
31+
#aggregate
32+
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
33+
CentralityVector = GetMultiOutStrengthSum(Aggregate,1,Nodes,Flags);
34+
outputFile = strcat(AnalysisName,"_centrality_outstrength_aggregate.txt");
35+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
36+
printf("Multislice centrality output to: %s\n",outputFile);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
addpath("octave");
2+
3+
%import the muxOctaveLib
4+
muxOctaveLib;
5+
6+
%import the configuration file
7+
LayersList = {};
8+
muxOctaveConfig;
9+
10+
NodesTensor = {};
11+
Layers = 0;
12+
SupraAdjacencyMatrix = 0;
13+
14+
if isExtendedEdgesList
15+
[SupraAdjacencyMatrix,Layers,Nodes] = BuildSupraAdjacencyMatrixFromFile(MultiLayerEdgesListFile,Flags,MaxNodes,FirstNodeLabel);
16+
NodesTensor = SupraAdjacencyToNodesTensor(SupraAdjacencyMatrix,Layers,Nodes);
17+
else
18+
[NodesTensor,Layers,Nodes] = BuildMultiplexFromFileList(LayersList,Flags,MaxNodes,FirstNodeLabel);
19+
LayersTensor = BuildLayersTensor(Layers,Nodes,OmegaParameter,MultisliceType);
20+
SupraAdjacencyMatrix = BuildSupraAdjacencyMatrix(NodesTensor,LayersTensor,Layers,Nodes);
21+
endif
22+
23+
% Calculate the centralities
24+
25+
CentralityVector = GetMultiStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
26+
outputFile = strcat(AnalysisName,"_centrality_Strength.txt");
27+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
28+
printf("Multislice centrality output to: %s\n",outputFile);
29+
30+
#aggregate
31+
Aggregate = GetAggregateMatrix(NodesTensor,Layers,Nodes);
32+
CentralityVector = GetMultiStrengthSum(Aggregate,1,Nodes,Flags);
33+
outputFile = strcat(AnalysisName,"_centrality_Strength_aggregate.txt");
34+
dlmwrite (outputFile, CentralityVector, 'delimiter',' ')
35+
printf("Multislice centrality output to: %s\n",outputFile);

octave/muxOctaveLib.m

Lines changed: 153 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,19 @@
517517
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518518
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519519

520+
function BinaryMatrix = binarizeMatrix(Matrix)
521+
BinaryMatrix = double(Matrix|Matrix);
522+
endfunction
523+
524+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
525+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
526+
520527
function MultiDegreeVector = GetMultiDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags)
521528
% References:
522529
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
523530

524-
MultiInDegreeVector = GetMultiInDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags);
525-
MultiOutDegreeVector = GetMultiOutDegree(SupraAdjacencyMatrix,Layers,Nodes,Flags);
531+
MultiInDegreeVector = GetMultiInDegree(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
532+
MultiOutDegreeVector = GetMultiOutDegree(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
526533

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

542549
if ismember("U",Flags)
543550
%we proceed by considering the interlayers separately
544-
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
551+
BlockTensor = SupraAdjacencyToBlockTensor(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes);
545552

546553
MultiOutDegreeVector = sparse(Nodes,1);
547554

@@ -559,7 +566,7 @@
559566
endfor
560567
endfor
561568
else
562-
SupraDegree = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
569+
SupraDegree = binarizeMatrix(SupraAdjacencyMatrix)*ones(Nodes*Layers,1);
563570

564571
MultiOutDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
565572
endif
@@ -575,10 +582,10 @@
575582

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

580587
%we proceed by considering the interlayers separately
581-
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
588+
BlockTensor = SupraAdjacencyToBlockTensor(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes);
582589

583590
MultiInDegreeVector = sparse(Nodes,1);
584591

@@ -596,7 +603,7 @@
596603
endfor
597604
endfor
598605
else
599-
SupraDegree = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
606+
SupraDegree = (ones(1,Nodes*Layers)*binarizeMatrix(SupraAdjacencyMatrix))';
600607

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

612-
MultiInDegreeVector = GetMultiInDegreeSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
613-
MultiOutDegreeVector = GetMultiOutDegreeSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
619+
MultiInDegreeVector = GetMultiInDegreeSum(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
620+
MultiOutDegreeVector = GetMultiOutDegreeSum(binarizeMatrix(SupraAdjacencyMatrix),Layers,Nodes,Flags);
614621

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

630637

631-
SupraDegree = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
638+
SupraDegree = binarizeMatrix(SupraAdjacencyMatrix)*ones(Nodes*Layers,1);
632639
MultiOutDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
633640
endfunction
634641

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

643650

644-
SupraDegree = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
651+
SupraDegree = (ones(1,Nodes*Layers)*binarizeMatrix(SupraAdjacencyMatrix))';
645652
MultiInDegreeVector = sum(reshape(SupraDegree,Nodes,Layers),2);
646653
endfunction
647654

655+
656+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658+
659+
function MultiStrengthVector = GetMultiStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
660+
% References:
661+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
662+
663+
MultiInStrengthVector = GetMultiInStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags);
664+
MultiOutStrengthVector = GetMultiOutStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags);
665+
666+
if ismember("U",Flags)
667+
MultiStrengthVector = (MultiInStrengthVector + MultiOutStrengthVector)/2;
668+
else
669+
MultiStrengthVector = MultiInStrengthVector + MultiOutStrengthVector;
670+
endif
671+
endfunction
672+
673+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675+
676+
function MultiOutStrengthVector = GetMultiOutStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
677+
% References:
678+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
679+
680+
681+
if ismember("U",Flags)
682+
%we proceed by considering the interlayers separately
683+
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
684+
685+
MultiOutStrengthVector = sparse(Nodes,1);
686+
687+
%with the matrix U we reweight interlinks corresponding to same replicas
688+
U = ones(Nodes,Nodes);
689+
U(logical(speye(size(U)))) = 1/2;
690+
691+
for i = 1:Layers
692+
for j = 1:Layers
693+
if i==j
694+
MultiOutStrengthVector += (BlockTensor{i,j}-diag(diag(BlockTensor{i,j})))*ones(Nodes,1) + diag(BlockTensor{i,j})*0.5;
695+
else
696+
MultiOutStrengthVector += (BlockTensor{i,j} .* U)*ones(Nodes,1);
697+
endif
698+
endfor
699+
endfor
700+
else
701+
SupraStrength = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
702+
703+
MultiOutStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
704+
endif
705+
endfunction
706+
707+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
709+
710+
function MultiInStrengthVector = GetMultiInStrength(SupraAdjacencyMatrix,Layers,Nodes,Flags)
711+
% References:
712+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
713+
714+
715+
if ismember("U",Flags)
716+
%using the following would consider multiple times the interlinks
717+
%SupraStrength = (SupraAdjacencyMatrix*ones(Nodes*Layers,1) + (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)')/2;
718+
719+
%we proceed by considering the interlayers separately
720+
BlockTensor = SupraAdjacencyToBlockTensor(SupraAdjacencyMatrix,Layers,Nodes);
721+
722+
MultiInStrengthVector = sparse(Nodes,1);
723+
724+
%with the matrix U we reweight interlinks corresponding to same replicas
725+
U = ones(Nodes,Nodes);
726+
U(logical(speye(size(U)))) = 1/2;
727+
728+
for i = 1:Layers
729+
for j = 1:Layers
730+
if i==j
731+
MultiInStrengthVector += (ones(1,Nodes)*(BlockTensor{i,j}-diag(diag(BlockTensor{i,j}))))' + diag(BlockTensor{i,j})*0.5;
732+
else
733+
MultiInStrengthVector += (ones(1,Nodes)*(BlockTensor{i,j} .* U))';
734+
endif
735+
endfor
736+
endfor
737+
else
738+
SupraStrength = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
739+
740+
MultiInStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
741+
endif
742+
endfunction
743+
744+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
745+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
746+
747+
function MultiStrengthVector = GetMultiStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
748+
% References:
749+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
750+
751+
MultiInStrengthVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
752+
MultiOutStrengthVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags);
753+
754+
if ismember("U",Flags)
755+
MultiStrengthVector = (MultiInStrengthVector + MultiOutStrengthVector)/2;
756+
else
757+
MultiStrengthVector = MultiInStrengthVector + MultiOutStrengthVector;
758+
endif
759+
endfunction
760+
761+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763+
764+
function MultiOutStrengthVector = GetMultiOutStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
765+
%this Strength include multiple times the interlinks
766+
% References:
767+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
768+
769+
770+
SupraStrength = SupraAdjacencyMatrix*ones(Nodes*Layers,1);
771+
MultiOutStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
772+
endfunction
773+
774+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
775+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776+
777+
function MultiInStrengthVector = GetMultiInStrengthSum(SupraAdjacencyMatrix,Layers,Nodes,Flags)
778+
%this Strength include multiple times the interlinks
779+
% References:
780+
% M. De Domenico et al, Phys. Rev. X 3, 041022 (2013)
781+
782+
783+
SupraStrength = (ones(1,Nodes*Layers)*SupraAdjacencyMatrix)';
784+
MultiInStrengthVector = sum(reshape(SupraStrength,Nodes,Layers),2);
785+
endfunction
786+
787+
788+
789+
648790
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649791
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
650792

0 commit comments

Comments
 (0)