python-igraph API reference

List of all classes, functions and methods in python-igraph

module documentation

Undocumented

Function _community_fastgreedy Community structure based on the greedy optimization of modularity.
Function _community_infomap Finds the community structure of the network according to the Infomap method of Martin Rosvall and Carl T. Bergstrom.
Function _community_leading_eigenvector_naive Naive implementation of Newman's eigenvector community structure detection.
Function _community_leading_eigenvector Newman's leading eigenvector method for detecting community structure.
Function _community_label_propagation Finds the community structure of the graph according to the label propagation method of Raghavan et al.
Function _community_multilevel Community structure based on the multilevel algorithm of Blondel et al.
Function _community_optimal_modularity Calculates the optimal modularity score of the graph and the corresponding community structure.
Function _community_edge_betweenness Community structure based on the betweenness of the edges in the network.
Function _community_spinglass Finds the community structure of the graph according to the spinglass community detection method of Reichardt & Bornholdt.
Function _community_walktrap Community detection algorithm of Latapy & Pons, based on random walks.
Function _k_core Returns some k-cores of the graph.
Function _community_leiden Finds the community structure of the graph using the Leiden algorithm of Traag, van Eck & Waltman.
Function _modularity Calculates the modularity score of the graph with respect to a given clustering.
def _community_fastgreedy(graph, weights=None):

Community structure based on the greedy optimization of modularity.

This algorithm merges individual nodes into communities in a way that greedily maximizes the modularity score of the graph. It can be proven that if no merge can increase the current modularity score, the algorithm can be stopped since no further increase can be achieved.

This algorithm is said to run almost in linear time on sparse graphs.

ParametersgraphUndocumented
weightsedge attribute name or a list containing edge weights
Returnsan appropriate VertexDendrogram object.
Unknown Field: newfieldrefReference
Unknown Field: refA Clauset, MEJ Newman and C Moore: Finding community structure in very large networks. Phys Rev E 70, 066111 (2004).
def _community_infomap(graph, edge_weights=None, vertex_weights=None, trials=10):

Finds the community structure of the network according to the Infomap method of Martin Rosvall and Carl T. Bergstrom.

ParametersgraphUndocumented
edge_weightsname of an edge attribute or a list containing edge weights.
vertex_weightsname of an vertex attribute or a list containing vertex weights.
trialsthe number of attempts to partition the network.
Returnsan appropriate VertexClustering object with an extra attribute called codelength that stores the code length determined by the algorithm.
Unknown Field: newfieldrefReference
Unknown Field: refM. Rosvall and C. T. Bergstrom: Maps of information flow reveal community structure in complex networks, PNAS 105, 1118 (2008). http://dx.doi.org/10.1073/pnas.0706851105, http://arxiv.org/abs/0707.0609.
M. Rosvall, D. Axelsson, and C. T. Bergstrom: The map equation, Eur. Phys. J. Special Topics 178, 13 (2009). http://dx.doi.org/10.1140/epjst/e2010-01179-1, http://arxiv.org/abs/0906.1405.
def _community_leading_eigenvector_naive(graph, clusters=None, return_merges=False):

Naive implementation of Newman's eigenvector community structure detection.

This function splits the network into two components according to the leading eigenvector of the modularity matrix and then recursively takes the given number of steps by splitting the communities as individual networks. This is not the correct way, however, see the reference for explanation. Consider using the correct community_leading_eigenvector method instead.

ParametersgraphUndocumented
clustersthe desired number of communities. If None, the algorithm tries to do as many splits as possible. Note that the algorithm won't split a community further if the signs of the leading eigenvector are all the same, so the actual number of discovered communities can be less than the desired one.
return_mergeswhether the returned object should be a dendrogram instead of a single clustering.
Returnsan appropriate VertexClustering or VertexDendrogram object.
Unknown Field: newfieldrefReference
Unknown Field: refMEJ Newman: Finding community structure in networks using the eigenvectors of matrices, arXiv:physics/0605087
def _community_leading_eigenvector(graph, clusters=None, weights=None, arpack_options=None):

Newman's leading eigenvector method for detecting community structure.

This is the proper implementation of the recursive, divisive algorithm: each split is done by maximizing the modularity regarding the original network.

ParametersgraphUndocumented
clustersthe desired number of communities. If None, the algorithm tries to do as many splits as possible. Note that the algorithm won't split a community further if the signs of the leading eigenvector are all the same, so the actual number of discovered communities can be less than the desired one.
weightsname of an edge attribute or a list containing edge weights.
arpack_optionsan ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used.
Returnsan appropriate VertexClustering object.
Unknown Field: newfieldrefReference
Unknown Field: refMEJ Newman: Finding community structure in networks using the eigenvectors of matrices, arXiv:physics/0605087
def _community_label_propagation(graph, weights=None, initial=None, fixed=None):

Finds the community structure of the graph according to the label propagation method of Raghavan et al.

Initially, each vertex is assigned a different label. After that, each vertex chooses the dominant label in its neighbourhood in each iteration. Ties are broken randomly and the order in which the vertices are updated is randomized before every iteration. The algorithm ends when vertices reach a consensus. Note that since ties are broken randomly, there is no guarantee that the algorithm returns the same community structure after each run. In fact, they frequently differ. See the paper of Raghavan et al on how to come up with an aggregated community structure.

ParametersgraphUndocumented
weightsname of an edge attribute or a list containing edge weights
initialname of a vertex attribute or a list containing the initial vertex labels. Labels are identified by integers from zero to n-1 where n is the number of vertices. Negative numbers may also be present in this vector, they represent unlabeled vertices.
fixeda list of booleans for each vertex. True corresponds to vertices whose labeling should not change during the algorithm. It only makes sense if initial labels are also given. Unlabeled vertices cannot be fixed. It may also be the name of a vertex attribute; each attribute value will be interpreted as a Boolean.
Returnsan appropriate VertexClustering object.
Unknown Field: newfieldrefReference
Unknown Field: refRaghavan, U.N. and Albert, R. and Kumara, S. Near linear time algorithm to detect community structures in large-scale networks. Phys Rev E 76:036106, 2007. http://arxiv.org/abs/0709.2938.
def _community_multilevel(graph, weights=None, return_levels=False):

Community structure based on the multilevel algorithm of Blondel et al.

This is a bottom-up algorithm: initially every vertex belongs to a separate community, and vertices are moved between communities iteratively in a way that maximizes the vertices' local contribution to the overall modularity score. When a consensus is reached (i.e. no single move would increase the modularity score), every community in the original graph is shrank to a single vertex (while keeping the total weight of the adjacent edges) and the process continues on the next level. The algorithm stops when it is not possible to increase the modularity any more after shrinking the communities to vertices.

This algorithm is said to run almost in linear time on sparse graphs.

ParametersgraphUndocumented
weightsedge attribute name or a list containing edge weights
return_levelsif True, the communities at each level are returned in a list. If False, only the community structure with the best modularity is returned.
Returnsa list of VertexClustering objects, one corresponding to each level (if return_levels is True), or a VertexClustering corresponding to the best modularity.
Unknown Field: newfieldrefReference
Unknown Field: refVD Blondel, J-L Guillaume, R Lambiotte and E Lefebvre: Fast unfolding of community hierarchies in large networks, J Stat Mech P10008 (2008), http://arxiv.org/abs/0803.0476
def _community_optimal_modularity(graph, *args, **kwds):

Calculates the optimal modularity score of the graph and the corresponding community structure.

This function uses the GNU Linear Programming Kit to solve a large integer optimization problem in order to find the optimal modularity score and the corresponding community structure, therefore it is unlikely to work for graphs larger than a few (less than a hundred) vertices. Consider using one of the heuristic approaches instead if you have such a large graph.

Returnsthe calculated membership vector and the corresponding modularity in a tuple.
def _community_edge_betweenness(graph, clusters=None, directed=True, weights=None):

Community structure based on the betweenness of the edges in the network.

The idea is that the betweenness of the edges connecting two communities is typically high, as many of the shortest paths between nodes in separate communities go through them. So we gradually remove the edge with the highest betweenness and recalculate the betweennesses after every removal. This way sooner or later the network falls of to separate components. The result of the clustering will be represented by a dendrogram.

ParametersgraphUndocumented
clustersthe number of clusters we would like to see. This practically defines the "level" where we "cut" the dendrogram to get the membership vector of the vertices. If None, the dendrogram is cut at the level which maximizes the modularity when the graph is unweighted; otherwise the dendrogram is cut at at a single cluster (because cluster count selection based on modularities does not make sense for this method if not all the weights are equal).
directedwhether the directionality of the edges should be taken into account or not.
weightsname of an edge attribute or a list containing edge weights.
Returnsa VertexDendrogram object, initally cut at the maximum modularity or at the desired number of clusters.
def _community_spinglass(graph, *args, **kwds):

Finds the community structure of the graph according to the spinglass community detection method of Reichardt & Bornholdt.

ParametersgraphUndocumented
argsUndocumented
kwdsUndocumented
weightsedge weights to be used. Can be a sequence or iterable or even an edge attribute name.
spinsinteger, the number of spins to use. This is the upper limit for the number of communities. It is not a problem to supply a (reasonably) big number here, in which case some spin states will be unpopulated.
parupdatewhether to update the spins of the vertices in parallel (synchronously) or not
start_tempthe starting temperature
stop_tempthe stop temperature
cool_factcooling factor for the simulated annealing
update_rulespecifies the null model of the simulation. Possible values are "config" (a random graph with the same vertex degrees as the input graph) or "simple" (a random graph with the same number of edges)
gammathe gamma argument of the algorithm, specifying the balance between the importance of present and missing edges within a community. The default value of 1.0 assigns equal importance to both of them.
implementationcurrently igraph contains two implementations of the spinglass community detection algorithm. The faster original implementation is the default. The other implementation is able to take into account negative weights, this can be chosen by setting implementation to "neg"
lambda_the lambda argument of the algorithm, which specifies the balance between the importance of present and missing negatively weighted edges within a community. Smaller values of lambda lead to communities with less negative intra-connectivity. If the argument is zero, the algorithm reduces to a graph coloring algorithm, using the number of spins as colors. This argument is ignored if the original implementation is used. Note the underscore at the end of the argument name; this is due to the fact that lambda is a reserved keyword in Python.
Returnsan appropriate VertexClustering object.
Unknown Field: newfieldrefReference
Unknown Field: refReichardt J and Bornholdt S: Statistical mechanics of community detection. Phys Rev E 74:016110 (2006). http://arxiv.org/abs/cond-mat/0603718.
Traag VA and Bruggeman J: Community detection in networks with positive and negative links. Phys Rev E 80:036115 (2009). http://arxiv.org/abs/0811.2329.
def _community_walktrap(graph, weights=None, steps=4):

Community detection algorithm of Latapy & Pons, based on random walks.

The basic idea of the algorithm is that short random walks tend to stay in the same community. The result of the clustering will be represented as a dendrogram.

ParametersgraphUndocumented
weightsname of an edge attribute or a list containing edge weights
stepslength of random walks to perform
Returnsa VertexDendrogram object, initially cut at the maximum modularity.
Unknown Field: newfieldrefReference
Unknown Field: refPascal Pons, Matthieu Latapy: Computing communities in large networks using random walks, http://arxiv.org/abs/physics/0512106.
def _k_core(graph, *args):

Returns some k-cores of the graph.

The method accepts an arbitrary number of arguments representing the desired indices of the k-cores to be returned. The arguments can also be lists or tuples. The result is a single Graph object if an only integer argument was given, otherwise the result is a list of Graph objects representing the desired k-cores in the order the arguments were specified. If no argument is given, returns all k-cores in increasing order of k.

def _community_leiden(graph, objective_function='CPM', weights=None, resolution_parameter=1.0, beta=0.01, initial_membership=None, n_iterations=2, node_weights=None):

Finds the community structure of the graph using the Leiden algorithm of Traag, van Eck & Waltman.

ParametersgraphUndocumented
objective_functionwhether to use the Constant Potts Model (CPM) or modularity. Must be either "CPM" or "modularity".
weightsedge weights to be used. Can be a sequence or iterable or even an edge attribute name.
resolution_parameterthe resolution parameter to use. Higher resolutions lead to more smaller communities, while lower resolutions lead to fewer larger communities.
betaparameter affecting the randomness in the Leiden algorithm. This affects only the refinement step of the algorithm.
initial_membershipif provided, the Leiden algorithm will try to improve this provided membership. If no argument is provided, the aglorithm simply starts from the singleton partition.
n_iterationsthe number of iterations to iterate the Leiden algorithm. Each iteration may improve the partition further. Using a negative number of iterations will run until a stable iteration is encountered (i.e. the quality was not increased during that iteration).
node_weightsthe node weights used in the Leiden algorithm. If this is not provided, it will be automatically determined on the basis of whether you want to use CPM or modularity. If you do provide this, please make sure that you understand what you are doing.
Returnsan appropriate VertexClustering object.
Unknown Field: newfieldrefReference
Unknown Field: refTraag, V. A., Waltman, L., & van Eck, N. J. (2019). From Louvain to Leiden: guaranteeing well-connected communities. Scientific reports, 9(1), 5233. doi: 10.1038/s41598-019-41695-z
def _modularity(self, membership, weights=None):

Calculates the modularity score of the graph with respect to a given clustering.

The modularity of a graph w.r.t. some division measures how good the division is, or how separated are the different vertex types from each other. It's defined as Q=1/(2m)*sum(Aij-ki*kj/(2m)delta(ci,cj),i,j). m is the number of edges, Aij is the element of the A adjacency matrix in row i and column j, ki is the degree of node i, kj is the degree of node j, and Ci and cj are the types of the two vertices (i and j). delta(x,y) is one iff x=y, 0 otherwise.

If edge weights are given, the definition of modularity is modified as follows: Aij becomes the weight of the corresponding edge, ki is the total weight of edges adjacent to vertex i, kj is the total weight of edges adjacent to vertex j and m is the total edge weight in the graph.

Parametersmembershipa membership list or a VertexClustering object
weightsoptional edge weights or None if all edges are weighed equally. Attribute names are also allowed.
Returnsthe modularity score
Unknown Field: newfieldrefReference
Unknown Field: refMEJ Newman and M Girvan: Finding and evaluating community structure in networks. Phys Rev E 69 026113, 2004.
API Documentation for python-igraph, generated by pydoctor 21.2.2.