Topology
These functions describe topologically motivated network metrics.
bedge_counts(adjacency, simplices=None, max_simplices=False, max_dim=-1, simplex_type='directed', **kwargs)
Counts the total number of edges in each position on the subgraphs defined by the nodes of the simplices listed in simplices. If a simplex list is not passed, simplices are computed on the adjacency matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adjacency |
(N,N)-array or sparse matrix
|
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
simplices |
series
|
Series of 2d-arrays indexed by dimension. Each array is of dimension (no. of simplices, dimension). Each row corresponds to a list of nodes on a simplex. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex_type |
See simplex_counts |
'directed'
|
Returns:
Type | Description |
---|---|
series
|
pandas series with index dimensions values (dim+1, dim+1) arrays. The (i,j) entry counts the number of edges from node i to node j on all the subgraphs of adjacency on the nodes of the simplices listed. See notes. |
Notes
Every directed \(k\)-simplex \([v_o, v_1, \ldots, v_k]\) defines as subgraph of the adjacency matrix, with edges
\(v_i \to v_j\) whenever \(i\leq j\), but also possibly with ''reverse'' edges. One can represent this structure
with a non-symmetric \((k+1, k+1)\)-matrix with 1
's for every edge in the subgraph. The output of this function
gives for each dimension the sum of all these matrices over all the simplices provided in simplices
or over
all the simplices in the adjacency matrix if none is provided. The lower triangular part of these matrices is
therefore a metric of recurrence within simplices, or "higher dimensional recurrence".
In particular, in dimension 1 it is the number of reciprocal edges in the network.
Source code in src/connalysis/network/topology.py
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
|
betti_counts(adj, node_properties=None, min_dim=0, max_dim=[], simplex_type='directed', approximation=None, **kwargs)
Count betti counts of flag complex of adj. Type of flag complex is given by simplex_type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d (N,N)-array or sparse matrix
|
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. Matrix will be cast to 0,1 entries so weights will be ignored. |
required |
node_properties |
data frame
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
min_dim |
int
|
Minimal dimension from which betti counts are computed. The default min_dim = 0 (counting number of connected components). |
0
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = [] counts betti numbers up to the maximal dimension of the complex. |
[]
|
simplex_type |
string
|
Type of flag complex to consider, given by the type of simplices it is built on. Possible types are: ’directed’ - directed simplices (directed flag complex) ’undirected’ - simplices in the underlying undirected graph (clique complex of the underlying undirected graph) ’reciprocal’ - simplices in the undirected graph of reciprocal connections (clique complex of the undirected graph of reciprocal connections.) |
'directed'
|
approximation |
list of integers or None
|
Approximation parameter for the computation of the betti numbers. Useful for large networks. If None all betti numbers are computed exactly. Otherwise, min_dim must be 0 and approximation but be a list of positive integers or -1. The list approximation is either extended by -1 entries on the right or sliced from [0:max_dim+1] to obtain a list of length max_dim. Each entry of the list denotes the approximation value for the betti computation of that dimension if -1 approximation in that dimension is set to None. If the approximation value at a given dimension is |
None
|
Returns:
Type | Description |
---|---|
series
|
Betti counts indexed per dimension from min_dim to max_dim. |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
AssertionError
|
If adj is not square. |
AssertionError
|
If approximation != None and min_dim != 0. |
See Also
simplex_counts : A function that counts the simplices forming the complex from which bettis are count. Simplex types are described there in detail.
References
For details about the approximation algorithm see
..[1] D. Luetgehetmann, "Documentation of the C++ flagser library"; GitHub: luetge/flagser.
Source code in src/connalysis/network/topology.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
|
count_rc_edges_skeleta(adj=None, max_dim=-1, max_simplices=False, N=None, simplex_list=None, edge_par=None, simplex_type='directed', position='all', return_mats=False, threads=8, **kwargs)
Count the edges and reciprocal edges in the k-skeleta
of the directed flag complex of adj for all
k<= max_dim. If simplex list are provided, it will compute the skeleta directly from these and not use adj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
(N,N)-array or sparse matrix
|
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex |
Series 2d-arrays indexed by dimension. Each array is of dimension (no. of simplices, dimension). Each row corresponds to a list of nodes on a simplex. If provided adj will be ignored but N will be required. |
required | |
edge_par |
DataFrame with edge participation values formatted as the output of |
None
|
|
N |
Number of nodes in original graph. |
None
|
|
simple_type |
See simplex_counts |
required | |
position |
Position of the edges to extract 'all': all edges of the simplex 'spine': edges along the spine of the simplex (only makes sense if simplices are directed) |
'all'
|
|
return_mats |
bool
|
If True return the matrices of the underlying graphs of the k-skeleta as in get_k_skeleta_graph |
False
|
threads |
Number of threads into which to parallelize the computation |
8
|
Returns:
Type | Description |
---|---|
data frame, (dict)
|
data frame with index dimensions and columns number of (rc) edges in the corresponding skeleta if return_mats==True, also return the graphs of the k-skeleta as in get_k_skeleta_graph. |
Raises:
Type | Description |
---|---|
AssertionError
|
If neither adj nor precomputed simplex_list or edge_par values are provided |
AssertionError
|
If N <= than an entry in the simplex list |
See Also
edge_participation : A function that counts the number of times an edge is part of a simplex.
simplex_counts : A function that counts the simplices forming the complex from which bettis are count, where simplex types are described in detail.
Source code in src/connalysis/network/topology.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
|
count_triads_fully_connected(adj, max_num_sampled=5000000, return_normalized=False)
Counts the numbers of each triadic motif in the matrix adj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d-array
|
Adjacency matrix of a directed network. |
required |
max_num_sampled |
int
|
The maximal number of connected triads classified. If the number of connected triads is higher than that, only the specified number is sampled at random and classified. The final counts are extrapolated as (actual_num_triads/ max_num_sampled) * counts. |
5000000
|
return_normalized |
bool
|
If True return the triad counts divided by the size of each isomorphism class. That is, the total counts divided by the following array: \([6, 3, 3, 6, 6, 6, 2, 3, 6, 3, 3, 6, 1].\) |
False
|
Returns:
Type | Description |
---|---|
1d-array
|
The counts of the various triadic motifs in adj as ordered in Figure 5 [1]_. |
Notes
Only connectected motifs are counted, i.e. motifs with less than 2 connections or only a single bidirectional connection are not counted. The connected motifs are ordered as in Figure 5 [1]_.
References
..[1] Gal, Eyal, et al. "Rich cell-type-specific network topology in neocortical microcircuitry." Nature neuroscience 20.7 (2017): 1004-1013.
Source code in src/connalysis/network/topology.py
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 |
|
cross_col_k_in_degree(adj_cross, adj_source, max_simplices=False, threads=8, max_dim=-1, **kwargs)
Compute generalized in-degree of nodes in adj_target from nodes in adj_source. The k-in-degree of a node v is the number of k-simplices in adj_source with all its nodes mapping to v through edges in adj_cross.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj_cross |
(n,m) array or sparse matrix
|
Matrix of connections from the nodes in adj_n to the target population. n is the number of nodes in adj_source and m is the number of nodes in adj_target. A non-zero entry adj_cross[i,j] implies there is an edge from i-th node of adj_source to the j-th node of adj_target. |
required |
adj_source |
(n, n)-array or sparse matrix
|
Adjacency matrix of the source network where n is the number of nodes in the source network. A non-zero entry adj_source[i,j] implies there is an edge from node i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
max_simplices |
bool
|
If False counts all simplices. If True counts only maximal simplices. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
Returns:
Type | Description |
---|---|
Data frame
|
Table of cross-k-in-degrees indexed by the m nodes in the target population. |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj_source has non-zero entries in the diagonal which can produce errors. |
Source code in src/connalysis/network/topology.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
|
dc(matrix, center=0, coeff_index=2, nhbd=True)
Computes the density coefficient of the graph induced by the neighbourhood of center in matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix |
2d-array
|
Adjacency matrix of a directed network. |
required |
center |
int
|
The index of the vertex whose neighbourhood is to be considered, default=0 |
0
|
coeff_index |
int
|
The dimension to be computed, default=2 |
2
|
nhbd |
bool
|
If true then is assumed that matrix is the neighbourhood of center. If false the neighbourhood of center is computed and used, default= True. |
True
|
Returns:
Type | Description |
---|---|
float
|
The density coefficient of the neighbourhood of center |
Source code in src/connalysis/network/topology.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 |
|
edge_participation(adj, node_properties=None, max_simplices=False, threads=8, max_dim=-1, simplex_type='directed', return_simplex_counts=False, verbose=False, **kwargs)
Compute the number of simplex motifs in the network adj each edge is part of. See simplex_counts for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
dataframe
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
max_simplices |
bool
|
If False (default) counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex_type |
string
|
Type of simplex to consider: ’directed’ - directed simplices ’undirected’ - simplices in the underlying undirected graph ’reciprocal’ - simplices in the undirected graph of reciprocal connections |
'directed'
|
Returns:
Type | Description |
---|---|
data frame
|
Indexed by the edges in adj and with columns de dimension for which node participation is counted |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
AssertionError
|
If adj is not square. |
Source code in src/connalysis/network/topology.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
euler_characteristic(matrix)
Computes the Euler characteristic of the flag complex of the graph with adjacency matrix matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix |
2d-array
|
Adjacency matrix of a directed network. |
required |
Returns:
Type | Description |
---|---|
integer
|
The Euler characteristic of the flag complex of matrix |
Source code in src/connalysis/network/topology.py
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 |
|
extract_submatrices_from_edge_participation(edge_par, N, dims=None, thresh=1)
Generate binary submatrix of an NxN matrix of edges with edge participation greater than thresh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_par |
DataFrame with edge participation values formatted as the output of |
required | |
dims |
dimensions of the simplices to consider, if |
None
|
|
N |
Number of nodes in original graph defining the NxN matrix. The indices of edge_par must be smaller than N |
required | |
thresh |
Threshold value at which to consider an edge. If thresh=1 all edges that elong to at least one simplex are considered. |
1
|
Returns:
Type | Description |
---|---|
dict
|
keys: dimensions
values: sparse binary matrices in coo format of shape (N,N) with entries |
Source code in src/connalysis/network/topology.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
|
extract_submatrix_from_simplex_list(simplex_list, N, position='spine')
Generate binary submatrix of NxN matrix of edges in simplex list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simplex |
Array of dimension (no. of simplices, dimension). Each row corresponds to a list of nodes on a simplex indexed by the order of the nodes in an NxN matrix. |
required | |
N |
Number of nodes in original graph defining the NxN matrix. |
required | |
position |
Position of the edges to extract 'all': all edges of the simplex (it is more efficient to do this with 'spine': edges along the spine of the simplex (only makes sense for directed simplices) |
'spine'
|
Returns:
Type | Description |
---|---|
coo bool matrix
|
Matrix with of shape (N,N) with entries |
Source code in src/connalysis/network/topology.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 |
|
get_all_simplices_from_max(max_simplices)
Takes the list of maximal simplices are returns the list of all simplices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_simplices |
list
|
A list of lists of tuples. Where max_simplices[k] is a list of the 0 dimensional maximal simplices, where each simplex is a tuple of the vertices of the simplex |
required |
Returns:
Type | Description |
---|---|
list
|
A list of lists of tuples. Of the same format as the inputted list but now contains all simplices. |
Source code in src/connalysis/network/topology.py
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 |
|
get_k_skeleta_graph(adj=None, dimensions=None, max_simplices=False, N=None, simplex_list=None, edge_par=None, simplex_type='directed', position='all', threads=8, **kwargs)
Return the edges of the (maximal) k-skeleton of the flag complex of adj for all k<= max_dim in the position determined by position. If simplex list are provided, it will compute the edges directly from these and not use adj, in which case N (the number of rows and columns of adj) is required. If simplex lists are not provided they will be calculated with for the flag complex whose type is determined by simplex_type as for simplex_counts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
(N,N)-array or sparse matrix
|
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
dimensions |
list of ints
|
Dimensions |
None
|
simplex_type |
string
|
Type of simplex to consider if computed from adj: ’directed’ - directed simplices ’undirected’ - simplices in the underlying undirected graph ’reciprocal’ - simplices in the undirected graph of reciprocal connections |
'directed'
|
simplex |
Series 2d-arrays indexed by dimension. Each array is of dimension (no. of simplices, dimension). Each row corresponds to a list of nodes on a simplex. If provided adj will be ignored but N will be required. |
required | |
N |
Number of nodes in original graph. |
None
|
|
position |
Position of the edges to extract 'all': all edges of the simplex 'spine': edges along the spine of the simplex (only makes sense if simplices are directed) |
'all'
|
|
threads |
Number of threads into which the computation should be parallelized |
8
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary with keys dimensions and values boolean (N,N) matrices with entries |
Raises:
Type | Description |
---|---|
AssertionError
|
If neither adj nor simplex_list are provided |
AssertionError
|
If N <= than an entry in the simplex list |
AssertionError
|
If a dimension is required that is not an index in the simplex list |
Notes
In order to list k-simplices and thus the k-skeleton, flagsercount needs to list all lower dimensional simplices anyhow.
Source code in src/connalysis/network/topology.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 |
|
in_degree_from_pop(adj, source_pop, max_simplices=False, threads=8, max_dim=-1, **kwargs)
Compute generalized in-degree of nodes source_pop onto the rest of the nodes in adj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required | |
source_pop |
|
required | |
max_simplices |
bool
|
If False counts all simplices. If True counts only maximal simplices. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
Returns:
Type | Description |
---|---|
Data frame
|
Table of k-in-degrees from source_pop indexed by the target population. |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj restricted to source_pop has non-zero entries in the diagonal which can produce errors. |
Source code in src/connalysis/network/topology.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
|
list_simplices_by_dimension(adj, node_properties=None, max_simplices=False, max_dim=-1, nodes=None, verbose=False, simplex_type='directed', **kwargs)
List all simplex motifs in the network adj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d (N,N)-array or sparse matrix
|
Adjacency matrix of a directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
data frame
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex_type |
string
|
Type of simplex to consider: ’directed’ - directed simplices ’undirected’ - simplices in the underlying undirected graph ’reciprocal’ - simplices in the undirected graph of reciprocal connections |
'directed'
|
nodes |
1d array or None(default)
|
Restrict to list only the simplices whose source node is in nodes. If None list all simplices |
None
|
Returns:
Type | Description |
---|---|
series
|
Simplex lists indexed per dimension. The dimension k entry is a (no. of k-simplices, k+1)-array is given, where each row denotes a simplex. |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
AssertionError
|
If adj is not square. |
AssertionError
|
If nodes is not a subarray of np.arange(N) |
See Also
simplex_counts : A function that counts the simplices instead of listing them and has descriptions of the simplex types.
Source code in src/connalysis/network/topology.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
nbc(matrix)
Computes the normalised Betti coefficient of the graph with adjacency matrix matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix |
2d-array
|
Adjacency matrix of a directed network. |
required |
Returns:
Type | Description |
---|---|
float
|
The normalised Betti coefficient of the graph with adjacency matrix matrix |
Source code in src/connalysis/network/topology.py
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 |
|
node_degree(adj, node_properties=None, direction=None, weighted=False, **kwargs)
Compute degree of nodes in network adj
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j of weight adj[i,j]. |
required |
node_properties |
data frame
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
direction |
string or tuple of strings
|
Direction for which to compute the degree 'IN' - In degree 'OUT'- Out degree None or ('IN', 'OUT') - Total degree i.e. IN+OUT |
None
|
Returns:
Type | Description |
---|---|
series or data frame
|
|
Raises:
Type | Description |
---|---|
Warning
|
If adj has non-zero entries in the diagonal |
AssertionError
|
If direction is invalid |
Source code in src/connalysis/network/topology.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
node_k_degree(adj, node_properties=None, direction=('IN', 'OUT'), max_dim=-1, **kwargs)
Compute generalized degree of nodes in network adj. The k-(in/out)-degree of a node v is the number of k-simplices with all its nodes mapping to/from the node v.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j of weight adj[i,j]. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
dataframe
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
direction |
string
|
Direction for which to compute the degree 'IN' - In degree 'OUT'- Out degree (’IN’, ’OUT’) - both |
('IN', 'OUT')
|
max_dim |
int
|
Maximal dimension for which to compute the degree max_dim >=2 or -1 in which case it computes all dimensions. |
-1
|
Returns:
Type | Description |
---|---|
data frame
|
Table of of k-(in/out)-degrees |
Raises:
Type | Description |
---|---|
Warning
|
If adj has non-zero entries in the diagonal which are ignored in the analysis |
AssertionError
|
If direction is invalid |
AssertionError
|
If not max_dim >1 |
Notes
Note that the k-in-degree of a node v is the number of (k+1) simplices the node v is a sink of. Dually, the k-out-degree of a node v is the number of (k+1) simplices the node v is a source of.
Source code in src/connalysis/network/topology.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
node_participation(adj, node_properties=None, max_simplices=False, threads=8, max_dim=-1, simplex_type='directed', **kwargs)
Compute the number of simplex motifs in the network adj each node is part of. See simplex_counts for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
dataframe
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
max_simplices |
bool
|
If False (default) counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex_type |
string
|
Type of simplex to consider: ’directed’ - directed simplices ’undirected’ - simplices in the underlying undirected graph ’reciprocal’ - simplices in the undirected graph of reciprocal connections |
'directed'
|
Returns:
Type | Description |
---|---|
data frame
|
Indexed by the nodes in adj and with columns de dimension for which node participation is counted |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
AssertionError
|
If adj is not square. |
Source code in src/connalysis/network/topology.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
|
normalised_simplex_count(matrix, dim=2)
Computes the normalised simplex count of the flag complex of the graph with adjacency matrix matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix |
2d-array
|
Adjacency matrix of a directed network. |
required |
dim |
int
|
The dimension to be computed, default=2 |
2
|
Returns:
Type | Description |
---|---|
float
|
The normalised simplex count of dimension dim of the flag complex of matrix |
Source code in src/connalysis/network/topology.py
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 |
|
normalized_simplex_counts(adj, node_properties=None, max_simplices=False, threads=8, max_dim=-1, **kwargs)
Compute the ratio of directed/undirected simplex counts normalized to be between 0 and 1. See simplex_counts and undirected_simplex_counts for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j of weight adj[i,j]. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
dataframe
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
Returns:
Type | Description |
---|---|
panda series
|
Normalized simplex counts |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
Notes
Maybe we should say why we choose this metric
Source code in src/connalysis/network/topology.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
rc_submatrix(adj)
Returns the symmetric submatrix of reciprocal connections of adj
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j. |
required |
Returns:
Type | Description |
---|---|
sparse matrix
|
symmetric matrix of the same dtype as adj of reciprocal connections |
Source code in src/connalysis/network/topology.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
simplex_counts(adj, node_properties=None, max_simplices=False, threads=8, max_dim=-1, simplex_type='directed', nodes=None, **kwargs)
Compute the number of simplex motifs in the network adj.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry adj[i,j] implies there is an edge from i to j of weight adj[i,j]. The matrix can be asymmetric, but must have 0 in the diagonal. |
required |
node_properties |
dataframe
|
Data frame of neuron properties in adj. Only necessary if used in conjunction with TAP or connectome utilities. |
None
|
max_simplices |
bool
|
If False counts all simplices in adj. If True counts only maximal simplices i.e., simplex motifs that are not contained in higher dimensional ones. |
False
|
max_dim |
int
|
Maximal dimension up to which simplex motifs are counted. The default max_dim = -1 counts all existing dimensions. Particularly useful for large or dense graphs. |
-1
|
simplex_type |
Type of simplex to consider (See Notes): ’directed’ - directed simplices ’undirected’ - simplices in the underlying undirected graph ’reciprocal’ - simplices in the undirected graph of reciprocal connections |
'directed'
|
|
nodes |
1d array or None(default)
|
Restrict to list only the simplices whose source node is in nodes. If None list all simplices. This only makes sense for directed simplices. |
None
|
Returns:
Type | Description |
---|---|
series
|
simplex counts |
Raises:
Type | Description |
---|---|
AssertionError
|
If adj has non-zero entries in the diagonal which can produce errors. |
AssertionError
|
If adj is not square. |
Notes
A directed simplex of dimension k in adj is a set of (k+1) nodes which are all to all connected in a feedforward manner. That is, they can be ordered from 0 to k such that there is an edge from i to j whenever i < j.
An undirected simplex of dimension k in adj is a set of (k+1) nodes in adj which are all to all connected. That is, they are all to all connected in the underlying undirected graph of adj. In the literature this is also called a (k+1)-clique of the underlying undirected graph.
A reciprocal simplex of dimension k in adj is a set of (k+1) nodes in adj which are all to all reciprocally connected. That is, they are all to all connected in the undirected graph of reciprocal connections of adj. In the literature this is also called a (k+1)-clique of the undirected graph of reciprocal connections.
Source code in src/connalysis/network/topology.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
simplicial_rich_club_curve(M, maximal=False, sparse_bin_set=False)
Computes the simplicial rich club curve of a network. Where the i'th entry is the density of the subnetwork induced by the vertices that are contained in more than i (maximal) simplices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d-array
|
Adjacency matrix of a directed network. |
required |
max_simplices |
bool
|
If true then vertex participation is the number of maximal simplices each vertex is contained in. |
required |
sparse_bin_set |
bool
|
If true then consecutive entries with same rich club coefficient are grouped into bins together, |
False
|
Returns:
Type | Description |
---|---|
Series
|
Where the i'th entry is the rich club coefficient of the network induced by all vertices which are contained in more that i (maximal) simplices |
Source code in src/connalysis/network/topology.py
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 |
|
tcc(matrix, center=0)
Computes the transitive clustering coefficient of the graph induced by the neighbourhood of center in matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix |
2d-array
|
Adjacency matrix of a directed network. |
required |
center |
int
|
The index of the vertex to be considered, default=0 |
0
|
Returns:
Type | Description |
---|---|
float
|
The transitive cluster coefficient of the neighbourhood of center |
Source code in src/connalysis/network/topology.py
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 |
|
underlying_undirected_matrix(adj)
Returns the symmetric matrix of undirected connections of adj
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adj |
2d array or sparse matrix
|
Adjacency matrix of the directed network. A non-zero entry in |
required |
Returns:
Type | Description |
---|---|
sparse boolean matrix
|
Corresponding to the symmetric underlying undirected graph |
Source code in src/connalysis/network/topology.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|