Low-level representation of a graph.
Don't use it directly, use igraph.Graph instead.
__new__
Create and return a new object. See help(type) for accurate signature.
add_edges
Adds edges to the graph.
add_vertices
Adds vertices to the graph.
Adjacency
Generates a graph from its adjacency matrix.
all_minimal_st_separators
Returns a list containing all the minimal s-t separators of a graph.
all_st_cuts
Returns all the cuts between the source and target vertices in a directed graph.
all_st_mincuts
Returns all minimum cuts between the source and target vertices in a directed graph.
are_connected
Decides whether two given vertices are directly connected.
articulation_points
Returns the list of articulation points in the graph.
assortativity
Returns the assortativity of the graph based on numeric properties of the vertices.
assortativity_degree
Returns the assortativity of a graph based on vertex degrees.
assortativity_nominal
Returns the assortativity of the graph based on vertex categories.
Asymmetric_Preference
Generates a graph based on asymmetric vertex types and connection probabilities.
Atlas
Generates a graph from the Graph Atlas.
attributes
No summary
authority_score
Calculates Kleinberg's authority score for the vertices of the graph
average_path_length
Calculates the average path length in a graph.
Barabasi
Generates a graph based on the Barabasi-Albert model.
betweenness
Calculates or estimates the betweenness of vertices in a graph.
bfs
Conducts a breadth first search (BFS) on the graph.
bfsiter
Constructs a breadth first search (BFS) iterator of the graph.
bibcoupling
Calculates bibliographic coupling scores for given vertices in a graph.
biconnected_components
Calculates the biconnected components of the graph.
bipartite_projection
Internal function, undocumented.
bipartite_projection_size
Internal function, undocumented.
bridges
Returns the list of bridges in the graph.
canonical_permutation
Calculates the canonical permutation of a graph using the BLISS isomorphism algorithm.
chordal_completion
Returns the list of edges needed to be added to the graph to make it chordal.
clique_number
Returns the clique number of the graph.
cliques
Returns some or all cliques of the graph as a list of tuples.
closeness
Calculates the closeness centralities of given vertices in a graph.
cocitation
Calculates cocitation scores for given vertices in a graph.
cohesive_blocks
Calculates the cohesive block structure of the graph.
community_edge_betweenness
Community structure detection based on the betweenness of the edges in the network. This algorithm was invented by M Girvan and MEJ Newman, see: M Girvan and MEJ Newman: Community structure in social and biological networks, Proc...
community_fastgreedy
Finds the community structure of the graph according to the algorithm of Clauset et al based on the greedy optimization of modularity.
community_infomap
Finds the community structure of the network according to the Infomap method of Martin Rosvall and Carl T. Bergstrom.
community_label_propagation
Finds the community structure of the graph according to the label propagation method of Raghavan et al.
community_leading_eigenvector
A proper implementation of Newman's eigenvector community structure detection. Each split is done by maximizing the modularity regarding the original network. See the reference for details.
community_leiden
Finds the community structure of the graph using the Leiden algorithm of Traag, van Eck & Waltman.
community_multilevel
Finds the community structure of the graph according to 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...
community_optimal_modularity
Calculates the optimal modularity score of the graph and the corresponding community structure.
community_spinglass
Finds the community structure of the graph according to the spinglass community detection method of Reichardt & Bornholdt.
community_walktrap
Finds the community structure of the graph according to the random walk method of Latapy & Pons.
complementer
Returns the complementer of the graph
compose
Returns the composition of two graphs.
connected_components
Calculates the (strong or weak) connected components for a given graph.
constraint
Calculates Burt's constraint scores for given vertices in a graph.
contract_vertices
Contracts some vertices in the graph, i.e. replaces groups of vertices with single vertices. Edges are not affected.
convergence_degree
Undocumented (yet).
convergence_field_size
Undocumented (yet).
copy
Creates a copy of the graph.
coreness
Finds the coreness (shell index) of the vertices of the network.
count_isomorphisms_vf2
Determines the number of isomorphisms between the graph and another one
count_multiple
Counts the multiplicities of the given edges.
count_subisomorphisms_vf2
Determines the number of subisomorphisms between the graph and another one
De_Bruijn
Generates a de Bruijn graph with parameters (m, n)
decompose
Decomposes the graph into subgraphs.
degree
Returns some vertex degrees from the graph.
Degree_Sequence
Generates a graph with a given degree sequence.
delete_edges
Removes edges from the graph.
delete_vertices
Deletes vertices and all its edges from the graph.
density
Calculates the density of the graph.
dfsiter
Constructs a depth first search (DFS) iterator of the graph.
diameter
Calculates the diameter of the graph.
difference
Subtracts the given graph from the original
distances
Calculates shortest path lengths for given vertices in a graph.
diversity
Calculates the structural diversity index of the vertices.
dominator
Returns the dominator tree from the given root node
dyad_census
Dyad census, as defined by Holland and Leinhardt
eccentricity
Calculates the eccentricities of given vertices in a graph.
ecount
Counts the number of edges.
edge_attributes
No summary
edge_betweenness
Calculates or estimates the edge betweennesses in a graph.
edge_connectivity
Calculates the edge connectivity of the graph or between some vertices.
eigen_adjacency
Undocumented
eigenvector_centrality
Calculates the eigenvector centralities of the vertices in a graph.
Erdos_Renyi
Generates a graph based on the Erdos-Renyi model.
Establishment
Generates a graph based on a simple growing model with vertex types.
Famous
Generates a famous graph based on its name.
farthest_points
Returns two vertex IDs whose distance equals the actual diameter of the graph.
feedback_arc_set
Calculates an approximately or exactly minimal feedback arc set.
Forest_Fire
Generates a graph based on the forest fire model
Full
Generates a full graph (directed or undirected, with or without loops).
Full_Citation
Generates a full citation graph
fundamental_cycles
Finds a single fundamental cycle basis of the graph
get_adjacency
Returns the adjacency matrix of a graph.
get_all_shortest_paths
Calculates all of the shortest paths from/to a given node in a graph.
get_diameter
Returns a path with the actual diameter of the graph.
get_edgelist
Returns the edge list of a graph.
get_eid
Returns the edge ID of an arbitrary edge between vertices v1 and v2
get_eids
Returns the edge IDs of some edges between some vertices.
get_incidence
Internal function, undocumented.
get_isomorphisms_vf2
Returns all isomorphisms between the graph and another one
get_shortest_paths
Calculates the shortest paths from/to a given node in a graph.
get_subisomorphisms_lad
Returns all subisomorphisms between the graph and another one using the LAD algorithm.
get_subisomorphisms_vf2
Returns all subisomorphisms between the graph and another one
girth
Returns the girth of the graph.
gomory_hu_tree
Internal function, undocumented.
Growing_Random
Generates a growing random graph.
harmonic_centrality
Calculates the harmonic centralities of given vertices in a graph.
has_multiple
Checks whether the graph has multiple edges.
hub_score
Calculates Kleinberg's hub score for the vertices of the graph
incident
Returns the edges a given vertex is incident on.
independence_number
Returns the independence number of the graph.
independent_vertex_sets
Returns some or all independent vertex sets of the graph as a list of tuples.
induced_subgraph
Returns a subgraph spanned by the given vertices.
is_acyclic
Returns whether the graph is acyclic (i.e. contains no cycles).
is_bipartite
Decides whether the graph is bipartite or not.
is_chordal
Returns whether the graph is chordal or not.
is_connected
Decides whether the graph is connected.
is_dag
Checks whether the graph is a DAG (directed acyclic graph).
is_directed
Checks whether the graph is directed.
is_loop
Checks whether a specific set of edges contain loop edges
is_minimal_separator
Decides whether the given vertex set is a minimal separator.
is_multiple
Checks whether an edge is a multiple edge.
is_mutual
Checks whether an edge has an opposite pair.
is_separator
Decides whether the removal of the given vertices disconnects the graph.
is_simple
Checks whether the graph is simple (no loop or multiple edges).
is_tree
Checks whether the graph is a (directed or undirected) tree graph.
Isoclass
Generates a graph with a given isomorphism class.
isoclass
Returns the isomorphism class of the graph or its subgraph.
isomorphic
Checks whether the graph is isomorphic to another graph.
isomorphic_bliss
Checks whether the graph is isomorphic to another graph, using the BLISS isomorphism algorithm.
isomorphic_vf2
Checks whether the graph is isomorphic to another graph, using the VF2 isomorphism algorithm.
K_Regular
Generates a k-regular random graph
Kautz
Generates a Kautz graph with parameters (m, n)
knn
Calculates the average degree of the neighbors for each vertex, and the same quantity as the function of vertex degree.
laplacian
Returns the Laplacian matrix of a graph.
largest_cliques
Returns the largest cliques of the graph as a list of tuples.
largest_independent_vertex_sets
Returns the largest independent vertex sets of the graph as a list of tuples.
Lattice
Generates a regular lattice.
layout_bipartite
Place the vertices of a bipartite graph in two layers.
layout_circle
Places the vertices of the graph uniformly on a circle or a sphere.
layout_davidson_harel
Places the vertices on a 2D plane according to the Davidson-Harel layout algorithm.
layout_drl
Places the vertices on a 2D plane or in the 3D space ccording to the DrL layout algorithm.
layout_fruchterman_reingold
Places the vertices on a 2D plane according to the Fruchterman-Reingold algorithm.
layout_graphopt
This is a port of the graphopt layout algorithm by Michael Schmuhl. graphopt version 0.4.1 was rewritten in C and the support for layers was removed.
layout_grid
Places the vertices of a graph in a 2D or 3D grid.
layout_kamada_kawai
Places the vertices on a plane according to the Kamada-Kawai algorithm.
layout_lgl
Places the vertices on a 2D plane according to the Large Graph Layout.
layout_mds
Places the vertices in an Euclidean space with the given number of dimensions using multidimensional scaling.
layout_random
Places the vertices of the graph randomly.
layout_reingold_tilford
Places the vertices on a 2D plane according to the Reingold-Tilford layout algorithm.
layout_reingold_tilford_circular
Circular Reingold-Tilford layout for trees.
layout_star
Calculates a star-like layout for the graph.
layout_umap
No summary
LCF
Generates a graph from LCF notation.
linegraph
Returns the line graph of the graph.
list_triangles
Lists the triangles of the graph
maxdegree
Returns the maximum degree of a vertex set in the graph.
maxflow
Returns the maximum flow between the source and target vertices.
maxflow_value
Returns the value of the maximum flow between the source and target vertices.
maximal_cliques
Returns the maximal cliques of the graph as a list of tuples.
maximal_independent_vertex_sets
Returns the maximal independent vertex sets of the graph as a list of tuples.
maximum_cardinality_search
Conducts a maximum cardinality search on the graph. The function computes a rank alpha for each vertex such that visiting vertices in decreasing rank order corresponds to always choosing the vertex with the most already visited neighbors as the next one to visit.
mincut
Calculates the minimum cut between the source and target vertices or within the whole graph.
mincut_value
Returns the minimum cut between the source and target vertices or within the whole graph.
minimum_cycle_basis
Computes a minimum cycle basis of the graph
minimum_size_separators
Returns a list containing all separator vertex sets of minimum size.
modularity
Calculates the modularity of the graph with respect to some vertex types.
motifs_randesu
Counts the number of motifs in the graph
motifs_randesu_estimate
Counts the total number of motifs in the graph
motifs_randesu_no
Counts the total number of motifs in the graph
neighborhood
For each vertex specified by vertices, returns the vertices reachable from that vertex in at most order steps. If mindist is larger than zero, vertices that are reachable in less than mindist steps are excluded.
neighborhood_size
For each vertex specified by vertices, returns the number of vertices reachable from that vertex in at most order steps. If mindist is larger than zero, vertices that are reachable in less than mindist...
neighbors
Returns adjacent vertices to a given vertex.
path_length_hist
Calculates the path length histogram of the graph
permute_vertices
Permutes the vertices of the graph according to the given permutation and returns the new graph.
personalized_pagerank
Calculates the personalized PageRank values of a graph.
predecessors
Returns the predecessors of a given vertex.
Preference
Generates a graph based on vertex types and connection probabilities.
radius
Calculates the radius of the graph.
random_walk
Performs a random walk of a given length from a given node.
Read_DIMACS
Reads a graph from a file conforming to the DIMACS minimum-cost flow file format.
Read_DL
Reads an UCINET DL file and creates a graph based on it.
Read_Edgelist
Reads an edge list from a file and creates a graph based on it.
Read_GML
Reads a GML file and creates a graph based on it.
Read_GraphDB
Reads a GraphDB format file and creates a graph based on it.
Read_GraphML
Reads a GraphML format file and creates a graph based on it.
Read_Lgl
Reads an .lgl file used by LGL.
Read_Ncol
Reads an .ncol file used by LGL.
Read_Pajek
Reads a file in the Pajek format and creates a graph based on it. Only Pajek network files (.net extension) are supported, not project files (.paj).
Realize_Degree_Sequence
Generates a graph from a degree sequence.
Recent_Degree
Generates a graph based on a stochastic model where the probability of an edge gaining a new node is proportional to the edges gained in a given time window.
reciprocity
Reciprocity defines the proportion of mutual connections in a directed graph. It is most commonly defined as the probability that the opposite counterpart of a directed edge is also included in the graph...
reverse_edges
Reverses the direction of some edges in the graph.
rewire
Randomly rewires the graph while preserving the degree distribution.
rewire_edges
Rewires the edges of a graph with constant probability.
Ring
Generates a ring graph.
SBM
Generates a graph based on a stochastic blockmodel.
similarity_dice
Dice similarity coefficient of vertices.
similarity_inverse_log_weighted
Inverse log-weighted similarity coefficient of vertices.
similarity_jaccard
Jaccard similarity coefficient of vertices.
simplify
Simplifies a graph by removing self-loops and/or multiple edges.
st_mincut
Calculates the minimum cut between the source and target vertices in a graph.
Star
Generates a star graph.
Static_Fitness
Generates a non-growing graph with edge probabilities proportional to node fitnesses.
Static_Power_Law
Generates a non-growing graph with prescribed power-law degree distributions.
strength
Returns the strength (weighted degree) of some vertices from the graph
subcomponent
Determines the indices of vertices which are in the same component as a given vertex.
subgraph_edges
Returns a subgraph spanned by the given edges.
subisomorphic_lad
Checks whether a subgraph of the graph is isomorphic to another graph.
subisomorphic_vf2
Checks whether a subgraph of the graph is isomorphic to another graph.
successors
Returns the successors of a given vertex.
to_directed
Converts an undirected graph to directed.
to_prufer
Converts a tree graph into a Prufer sequence.
to_undirected
Converts a directed graph to undirected.
topological_sorting
Calculates a possible topological sorting of the graph.
transitivity_avglocal_undirected
Calculates the average of the vertex transitivities of the graph.
transitivity_local_undirected
Calculates the local transitivity (clustering coefficient) of the given vertices in the graph.
transitivity_undirected
Calculates the global transitivity (clustering coefficient) of the graph.
Tree
Generates a tree in which almost all vertices have the same number of children.
Tree_Game
Generates a random tree by sampling uniformly from the set of labelled trees with a given number of nodes.
triad_census
Triad census, as defined by Davis and Leinhardt
unfold_tree
Unfolds the graph using a BFS to a tree by duplicating vertices as necessary.
vcount
Counts the number of vertices.
vertex_attributes
No summary
vertex_connectivity
Calculates the vertex connectivity of the graph or between some vertices.
Watts_Strogatz
No summary
write_dimacs
Writes the graph in DIMACS format to the given file.
write_dot
Writes the graph in DOT format to the given file.
write_edgelist
Writes the edge list of a graph to a file.
write_gml
Writes the graph in GML format to the given file.
write_graphml
Writes the graph to a GraphML file.
write_leda
Writes the graph to a file in LEDA native format.
write_lgl
Writes the edge list of a graph to a file in .lgl format.
write_ncol
Writes the edge list of a graph to a file in .ncol format.
write_pajek
Writes the graph in Pajek format to the given file.
__graph_as_capsule
Returns the igraph graph encapsulated by the Python object as a PyCapsule
__register_destructor
Registers a destructor to be called when the object is freed by Python. This function should not be used directly by igraph users.
_Bipartite
Internal function, undocumented.
_Full_Bipartite
Internal function, undocumented.
_get_all_simple_paths
Internal function, undocumented.
_GRG
Internal function, undocumented.
_Incidence
Internal function, undocumented.
_is_matching
Internal function, undocumented.
_is_maximal_matching
Internal function, undocumented.
_layout_sugiyama
Internal function, undocumented.
_maximum_bipartite_matching
Internal function, undocumented.
_Random_Bipartite
Internal function, undocumented.
_raw_pointer
Returns the memory address of the igraph graph encapsulated by the Python object as an ordinary Python integer.
_spanning_tree
Internal function, undocumented.
_Weighted_Adjacency
Generates a graph from its adjacency matrix.
Create and return a new object. See help(type) for accurate signature.
igraph.Graph Adds edges to the graph.
igraph.Graph Adds vertices to the graph.
igraph.Graph Generates a graph from its adjacency matrix.
the mode to be used. Possible values are:
- "directed" - the graph will be directed and a matrix element gives the number of edges between two vertices.
- "undirected" - alias to "max" for convenience.
- "max" - undirected graph will be created and the number of edges between vertex i and j is max(A(i, j), A(j, i))
- "min" - like "max", but with min(A(i, j), A(j, i))
- "plus" - like "max", but with A(i, j) + A(j, i)
- "upper" - undirected graph with the upper right triangle of the matrix (including the diagonal)
- "lower" - undirected graph with the lower left triangle of the matrix (including the diagonal)
specifies how the diagonal of the matrix should be handled:
- "ignore" - ignore loop edges in the diagonal
- "once" - treat the diagonal entries as loop edge counts
- "twice" - treat the diagonal entries as twice the number of loop edges
Returns a list containing all the minimal s-t separators of a graph.
A minimal separator is a set of vertices whose removal disconnects the graph, while the removal of any subset of the set keeps the graph connected.
igraph.Graph Returns all the cuts between the source and target vertices in a directed graph.
This function lists all edge-cuts between a source and a target vertex. Every cut is listed exactly once.
igraph.Graph Returns all minimum cuts between the source and target vertices in a directed graph.
Decides whether two given vertices are directly connected.
Returns the list of articulation points in the graph.
A vertex is an articulation point if its removal increases the number of connected components in the graph.
Returns the assortativity of the graph based on numeric properties of the vertices.
This coefficient is basically the correlation between the actual connectivity patterns of the vertices and the pattern expected from the disribution of the vertex types.
See equation (21) in Newman MEJ: Mixing patterns in networks, Phys Rev E 67:026126 (2003) for the proper definition. The actual calculation is performed using equation (26) in the same paper for directed graphs, and equation (4) in Newman MEJ: Assortative mixing in networks, Phys Rev Lett 89:208701 (2002) for undirected graphs.
assortativity_degree() when the types are the vertex degreesNewman MEJ: Assortative mixing in networks, Phys Rev Lett 89:208701,
Returns the assortativity of a graph based on vertex degrees.
See assortativity() for the details. assortativity_degree() simply calls assortativity() with the vertex degrees as types.
Returns the assortativity of the graph based on vertex categories.
Assuming that the vertices belong to different categories, this function calculates the assortativity coefficient, which specifies the extent to which the connections stay within categories. The assortativity coefficient is one if all the connections stay within categories and minus one if all the connections join vertices of different categories. For a randomly connected network, it is asymptotically zero.
See equation (2) in Newman MEJ: Mixing patterns in networks, Phys Rev E 67:026126 (2003) for the proper definition.
Generates a graph based on asymmetric vertex types and connection probabilities.
This is the asymmetric variant of Preference() . A given number of vertices are generated. Every vertex is assigned to an "incoming" and an "outgoing" vertex type according to the given joint type probabilities. Finally, every vertex pair is evaluated and a directed edge is created between them with a probability depending on the "outgoing" type of the source vertex and the "incoming" type of the target vertex.
Generates a graph from the Graph Atlas.
The index of the graph to be generated. Indices start from zero, graphs are listed:
- in increasing order of number of vertices;
- for a fixed number of vertices, in increasing order of the number of edges;
- for fixed numbers of vertices and edges, in increasing order of the degree sequence, for example 111223 < 112222;
- for fixed degree sequence, in increasing number of automorphisms.
Calculates Kleinberg's authority score for the vertices of the graph
ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used.Calculates the average path length in a graph.
Generates a graph based on the Barabasi-Albert model.
the algorithm to use to generate the network. Possible values are:
- "bag": the algorithm that was the default in igraph before 0.6. It works by putting the ids of the vertices into a bag (multiset) exactly as many times as their in-degree, plus once more. The required number of cited vertices are then drawn from the bag with replacement. It works only for power=1 and zero_appeal=1.
- "psumtree": this algorithm uses a partial prefix-sum tree to generate the graph. It does not generate multiple edges and it works for any values of power and zero_appeal.
- "psumtree_multiple": similar to "psumtree", but it will generate multiple edges as well. igraph before 0.6 used this algorithm for powers other than 1.
GraphBase object. igraph will use this graph as a starting point for the preferential attachment model.Calculates or estimates the betweenness of vertices in a graph.
Keyword arguments:
Conducts a breadth first search (BFS) on the graph.
a tuple with the following items:
- The vertex IDs visited (in order)
- The start indices of the layers in the vertex list
- The parent of every vertex in the BFS
Constructs a breadth first search (BFS) iterator of the graph.
igraph.BFSIter object.Calculates bibliographic coupling scores for given vertices in a graph.
igraph.Graph Calculates the biconnected components of the graph.
Components containing a single vertex only are not considered as being biconnected.
igraph.Graph Internal function, undocumented.
igraph.Graph Internal function, undocumented.
Returns the list of bridges in the graph.
An edge is a bridge if its removal increases the number of (weakly) connected components in the graph.
Calculates the canonical permutation of a graph using the BLISS isomorphism algorithm.
Passing the permutation returned here to permute_vertices() will transform the graph into its canonical form.
See http://www.tcs.hut.fi/Software/bliss/index.html for more information about the BLISS algorithm and canonical permutations.
splitting heuristics for graph as a case-insensitive string, with the following possible values:
- "f": first non-singleton cell
- "fl": first largest non-singleton cell
- "fs": first smallest non-singleton cell
- "fm": first maximally non-trivially connected non-singleton cell
- "flm": largest maximally non-trivially connected non-singleton cell
- "fsm": smallest maximally non-trivially connected non-singleton cell
Returns the list of edges needed to be added to the graph to make it chordal.
A graph is chordal if each of its cycles of four or more nodes has a chord, i.e. an edge joining two nodes that are not adjacent in the cycle. An equivalent definition is that any chordless cycles have at most three nodes.
The chordal completion of a graph is the list of edges that needed to be added to the graph to make it chordal. It is an empty list if the graph is already chordal.
Note that at the moment igraph does not guarantee that the returned chordal completion is minimal; there may exist a subset of the returned chordal completion that is still a valid chordal completion.
maximum_cardinality_search() on the graph. Useful only if you already have the alpha vector; simply passing None here will make igraph calculate the alpha vector on its own.maximum_cardinality_search() on the graph. Useful only if you already have the inverse alpha vector; simply passing None here will make igraph calculate the inverse alpha vector on its own.Returns the clique number of the graph.
The clique number of the graph is the size of the largest clique.
largest_cliques() for the largest cliques.Returns some or all cliques of the graph as a list of tuples.
A clique is a complete subgraph -- a set of vertices where an edge is present between any two of them (excluding loops)
Calculates the closeness centralities of given vertices in a graph.
The closeness centerality of a vertex measures how easily other vertices can be reached from it (or the other way: how easily it can be reached from the other vertices). It is defined as the number of vertices minus one divided by the sum of the lengths of all geodesics from/to the given vertex.
If the graph is not connected, and there is no path between two vertices, the number of vertices is used instead the length of the geodesic. This is always longer than the longest possible geodesic.
Calculates cocitation scores for given vertices in a graph.
Calculates the cohesive block structure of the graph.
Graph which wraps the result in a CohesiveBlocks object. It is advised to use that.igraph.Graph Community structure detection based on the betweenness of the edges in the network. This algorithm was invented by M Girvan and MEJ Newman, see: M Girvan and MEJ Newman: Community structure in social and biological networks, Proc. Nat. Acad. Sci. USA 99, 7821-7826 (2002).
The idea is that the betweenness of the edges connecting two communities is typically high. So we gradually remove the edge with the highest betweenness from the network and recalculate edge betweenness after every removal, as long as all edges are removed.
Graph . It is advised to use that instead of this version.igraph.Graph Finds the community structure of the graph according to the algorithm of Clauset et al based on the greedy optimization of modularity.
This is a bottom-up algorithm: initially every vertex belongs to a separate community, and communities are merged one by one. In every step, the two communities being merged are the ones which result in the maximal increase in modularity.
a tuple with the following elements:
- The list of merges
- The modularity scores before each merge
Graph . It is advised to use that instead of this version.igraph.Graph Finds the community structure of the network according to the Infomap method of Martin Rosvall and Carl T. Bergstrom.
See http://www.mapequation.org for a visualization of the algorithm or one of the references provided below.
igraph.Graph 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.
igraph.Graph A proper implementation of Newman's eigenvector community structure detection. Each split is done by maximizing the modularity regarding the original network. See the reference for details.
ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used.Graph . It is advised to use that instead of this version.igraph.Graph Finds the community structure of the graph using the Leiden algorithm of Traag, van Eck & Waltman.
igraph.Graph Finds the community structure of the graph according to 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 incident 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.
Graph . It is advised to use that instead of this version.igraph.Graph 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.
igraph.Graph Finds the community structure of the graph according to the spinglass community detection method of Reichardt & Bornholdt.
igraph.Graph Finds the community structure of the graph according to the random walk method of Latapy & Pons.
The basic idea of the algorithm is that short random walks tend to stay in the same community. The method provides a dendrogram.
Graph . It is advised to use that instead of this version.Returns the complementer of the graph
Returns the composition of two graphs.
Calculates the (strong or weak) connected components for a given graph.
Graph which wraps the result in a VertexClustering object. It is advised to use that.Calculates Burt's constraint scores for given vertices in a graph.
Burt's constraint is higher if ego has less, or mutually stronger related (i.e. more redundant) contacts. Burt's measure of constraint, C[i], of vertex i's ego network V[i], is defined for directed and valued graphs as follows:
C[i] = sum( sum( (p[i,q] p[q,j])^2, q in V[i], q != i,j ), j in V[], j != i)
for a graph of order (ie. number od vertices) N, where proportional tie strengths are defined as follows:
p[i,j]=(a[i,j]+a[j,i]) / sum(a[i,k]+a[k,i], k in V[i], k != i), a[i,j] are elements of A and the latter being the graph adjacency matrix.
For isolated vertices, constraint is undefined.
Contracts some vertices in the graph, i.e. replaces groups of vertices with single vertices. Edges are not affected.
VertexClustering object here.simplify() for more details.Undocumented (yet).
Undocumented (yet).
Creates a copy of the graph.
Attributes are copied by reference; in other words, if you use mutable Python objects as attribute values, these objects will still be shared between the old and new graph. You can use `deepcopy()` from the `copy` module if you need a truly deep copy of the graph.
Finds the coreness (shell index) of the vertices of the network.
The k-core of a graph is a maximal subgraph in which each vertex has at least degree k. (Degree here means the degree in the subgraph of course). The coreness of a vertex is k if it is a member of the k-core but not a member of the k + 1-core.
Determines the number of isomorphisms between the graph and another one
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Counts the multiplicities of the given edges.
Determines the number of subisomorphisms between the graph and another one
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Generates a de Bruijn graph with parameters (m, n)
A de Bruijn graph represents relationships between strings. An alphabet of m letters are used and strings of length n are considered. A vertex corresponds to every possible string and there is a directed edge from vertex v to vertex w if the string of v can be transformed into the string of w by removing its first letter and appending a letter to it.
Please note that the graph will have mn vertices and even more edges, so probably you don't want to supply too big numbers for m and n.
Decomposes the graph into subgraphs.
Returns some vertex degrees from the graph.
This method accepts a single vertex ID or a list of vertex IDs as a parameter, and returns the degree of the given vertices (in the form of a single integer or a list, depending on the input parameter).
Generates a graph with a given degree sequence.
the generation method to be used. One of the following:
- "configuration" -- simple generator that implements the stub-matching configuration model. It may generate self-loops and multiple edges. This method does not sample multigraphs uniformly, but it can be used to implement uniform sampling for simple graphs by rejecting any result that is non-simple (i.e. contains loops or multi-edges).
- "fast_heur_simple" -- similar to "configuration" but avoids the generation of multiple and loop edges at the expense of increased time complexity. The method will re-start the generation every time it gets stuck in a configuration where it is not possible to insert any more edges without creating loops or multiple edges, and there is no upper bound on the number of iterations, but it will succeed eventually if the input degree sequence is graphical and throw an exception if the input degree sequence is not graphical. This method does not sample simple graphs uniformly.
- "configuration_simple" -- similar to "configuration" but rejects generated graphs if they are not simple. This method samples simple graphs uniformly.
- "edge_switching_simple" -- an MCMC sampler based on degree-preserving edge switches. It generates simple undirected or directed graphs. The algorithm uses
Graph.Realize_Degree_Sequence()to construct an initial graph, then rewires it usingGraph.rewire(). - "vl" -- a more sophisticated generator that can sample undirected, connected simple graphs approximately uniformly. It uses edge-switching Monte-Carlo methods to randomize the graphs. This generator should be favoured if undirected and connected graphs are to be generated and execution time is not a concern. igraph uses the original implementation of Fabien Viger; see the following URL and the paper cited on it for the details of the algorithm: https://www-complexnetworks.lip6.fr/~latapy/FV/generation.html.
Legacy names that were valid before igraph 0.10 are also supported, but these may be removed without further notice:
- "simple" -- equivalent to "configuration" - "no_multiple" -- equivalent to "fast_heur_simple" - "no_multiple_uniform" -- equivalent to "configuration_simple"
igraph.Graph Removes edges from the graph.
All vertices will be kept, even if they lose all their edges. Nonexistent edges will be silently ignored.
EdgeSeq objects are also accepted here. No argument deletes all edges.Deletes vertices and all its edges from the graph.
Calculates the density of the graph.
Constructs a depth first search (DFS) iterator of the graph.
igraph.DFSIter object.Calculates the diameter of the graph.
Subtracts the given graph from the original
Calculates shortest path lengths for given vertices in a graph.
The algorithm used for the calculations is selected automatically: a simple BFS is used for unweighted graphs, Dijkstra's algorithm is used when all the weights are positive. Otherwise, the Bellman-Ford algorithm is used if the number of requested source vertices is larger than 100 and Johnson's algorithm is used otherwise.
Calculates the structural diversity index of the vertices.
The structural diversity index of a vertex is simply the (normalized) Shannon entropy of the weights of the edges incident on the vertex.
The measure is defined for undirected graphs only; edge directions are ignored.
Returns the dominator tree from the given root node
igraph.Graph Dyad census, as defined by Holland and Leinhardt
Dyad census means classifying each pair of vertices of a directed graph into three categories: mutual, there is an edge from a to b and also from b to a; asymmetric, there is an edge either from a to b or from b to a but not the other way and null, no edges between a and b.
Graph which wraps the result in a DyadCensus object. It is advised to use that.Calculates the eccentricities of given vertices in a graph.
The eccentricity of a vertex is calculated by measuring the shortest distance from (or to) the vertex, to (or from) all other vertices in the graph, and taking the maximum.
Counts the number of edges.
Calculates or estimates the edge betweennesses in a graph.
Calculates the edge connectivity of the graph or between some vertices.
The edge connectivity between two given vertices is the number of edges that have to be removed in order to disconnect the two vertices into two separate components. This is also the number of edge disjoint directed paths between the vertices. The edge connectivity of the graph is the minimal edge connectivity over all vertex pairs.
This method calculates the edge connectivity of a given vertex pair if both the source and target vertices are given. If none of them is given (or they are both negative), the overall edge connectivity is returned.
Undocumented
Calculates the eigenvector centralities of the vertices in a graph.
Eigenvector centrality is a measure of the importance of a node in a network. It assigns relative scores to all nodes in the network based on the principle that connections from high-scoring nodes contribute more to the score of the node in question than equal connections from low-scoring nodes. In practice, the centralities are determined by calculating eigenvector corresponding to the largest positive eigenvalue of the adjacency matrix. In the undirected case, this function considers the diagonal entries of the adjacency matrix to be twice the number of self-loops on the corresponding vertex.
In the directed case, the left eigenvector of the adjacency matrix is calculated. In other words, the centrality of a vertex is proportional to the sum of centralities of vertices pointing to it.
Eigenvector centrality is meaningful only for connected graphs. Graphs that are not connected should be decomposed into connected components, and the eigenvector centrality calculated for each separately.
ARPACKOptions object that can be used to fine-tune the calculation. If it is omitted, the module-level variable called arpack_options is used.Generates a graph based on the Erdos-Renyi model.
Generates a graph based on a simple growing model with vertex types.
A single vertex is added at each time step. This new vertex tries to connect to k vertices in the graph. The probability that such a connection is realized depends on the types of the vertices involved.
Generates a famous graph based on its name.
Several famous graphs are known to igraph including (but not limited to) the Chvatal graph, the Petersen graph or the Tutte graph. This method generates one of them based on its name (case insensitive). See the documentation of the C interface of igraph for the names available: https://igraph.org/c/doc.
Returns two vertex IDs whose distance equals the actual diameter of the graph.
If there are many shortest paths with the length of the diameter, it returns the first one it found.
Calculates an approximately or exactly minimal feedback arc set.
A feedback arc set is a set of edges whose removal makes the graph acyclic. Since this is always possible by removing all the edges, we are in general interested in removing the smallest possible number of edges, or an edge set with as small total weight as possible. This method calculates one such edge set. Note that the task is trivial for an undirected graph as it is enough to find a spanning tree and then remove all the edges not in the spanning tree. Of course it is more complicated for directed graphs.
Generates a graph based on the forest fire model
The forest fire model is a growing graph model. In every time step, a new vertex is added to the graph. The new vertex chooses an ambassador (or more than one if ambs > 1) and starts a simulated forest fire at its ambassador(s). The fire spreads through the edges. The spreading probability along an edge is given by fwprob. The fire may also spread backwards on an edge by probability fwprob*bwfactor. When the fire ended, the newly added vertex connects to the vertices ``burned'' in the previous fire.
Generates a full graph (directed or undirected, with or without loops).
Generates a full citation graph
A full citation graph is a graph where the vertices are indexed from 0 to n − 1 and vertex i has a directed edge towards all vertices with an index less than i.
Finds a single fundamental cycle basis of the graph
igraph.Graph Returns the adjacency matrix of a graph.
Calculates all of the shortest paths from/to a given node in a graph.
VertexSeq object. None means all the vertices.Returns a path with the actual diameter of the graph.
If there are many shortest paths with the length of the diameter, it returns the first one it founds.
Returns the edge list of a graph.
Returns the edge ID of an arbitrary edge between vertices v1 and v2
Returns the edge IDs of some edges between some vertices.
This method can operate in two different modes, depending on which of the keyword arguments pairs and path are given.
The method does not consider multiple edges; if there are multiple edges between a pair of vertices, only the ID of one of the edges is returned.
igraph.Graph Internal function, undocumented.
Returns all isomorphisms between the graph and another one
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Calculates the shortest paths from/to a given node in a graph.
VertexSeq object. None means all the vertices.Returns all subisomorphisms between the graph and another one using the LAD algorithm.
The optional domains argument may be used to restrict vertices that may match each other. You can also specify whether you are interested in induced subgraphs only or not.
Returns all subisomorphisms between the graph and another one
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Returns the girth of the graph.
The girth of a graph is the length of the shortest circle in it.
igraph.Graph Internal function, undocumented.
Generates a growing random graph.
Calculates the harmonic centralities of given vertices in a graph.
The harmonic centerality of a vertex measures how easily other vertices can be reached from it (or the other way: how easily it can be reached from the other vertices). It is defined as the mean inverse distance to all other vertices.
If the graph is not connected, and there is no path between two vertices, the inverse distance is taken to be zero.
Checks whether the graph has multiple edges.
Calculates Kleinberg's hub score for the vertices of the graph
ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used.Returns the edges a given vertex is incident on.
Returns the independence number of the graph.
The independence number of the graph is the size of the largest independent vertex set.
largest_independent_vertex_sets() for the largest independent vertex setsReturns some or all independent vertex sets of the graph as a list of tuples.
Two vertices are independent if there is no edge between them. Members of an independent vertex set are mutually independent.
Returns a subgraph spanned by the given vertices.
Returns whether the graph is acyclic (i.e. contains no cycles).
Decides whether the graph is bipartite or not.
Vertices of a bipartite graph can be partitioned into two groups A and B in a way that all edges go between the two groups.
Returns whether the graph is chordal or not.
A graph is chordal if each of its cycles of four or more nodes has a chord, i.e. an edge joining two nodes that are not adjacent in the cycle. An equivalent definition is that any chordless cycles have at most three nodes.
maximum_cardinality_search() on the graph. Useful only if you already have the alpha vector; simply passing None here will make igraph calculate the alpha vector on its own.maximum_cardinality_search() on the graph. Useful only if you already have the inverse alpha vector; simply passing None here will make igraph calculate the inverse alpha vector on its own.Decides whether the graph is connected.
Checks whether the graph is a DAG (directed acyclic graph).
A DAG is a directed graph with no directed cycles.
Checks whether the graph is directed.
Checks whether a specific set of edges contain loop edges
Decides whether the given vertex set is a minimal separator.
A minimal separator is a set of vertices whose removal disconnects the graph, while the removal of any subset of the set keeps the graph connected.
Checks whether an edge is a multiple edge.
Also works for a set of edges -- in this case, every edge is checked one by one. Note that if there are multiple edges going between a pair of vertices, there is always one of them that is not reported as multiple (only the others). This allows one to easily detect the edges that have to be deleted in order to make the graph free of multiple edges.
Checks whether an edge has an opposite pair.
Also works for a set of edges -- in this case, every edge is checked one by one. The result will be a list of booleans (or a single boolean if only an edge index is supplied), every boolean corresponding to an edge in the edge set supplied. True is returned for a given edge a --> b if there exists another edge b --> a in the original graph (not the given edge set!). All edges in an undirected graph are mutual. In case there are multiple edges between a and b, it is enough to have at least one edge in either direction to report all edges between them as mutual, so the multiplicity of edges do not matter.
Decides whether the removal of the given vertices disconnects the graph.
Checks whether the graph is simple (no loop or multiple edges).
Checks whether the graph is a (directed or undirected) tree graph.
For directed trees, the function may require that the edges are oriented outwards from the root or inwards to the root, depending on the value of the mode argument.
Generates a graph with a given isomorphism class.
Currently we support directed graphs of size 3 and 4, and undirected graphs of size 3, 4, 5 or 6. Use the isoclass() instance method to find the isomorphism class of a given graph.
Returns the isomorphism class of the graph or its subgraph.
Isomorphism class calculations are implemented only for directed graphs with 3 or 4 vertices, or undirected graphs with 3, 4, 5 or 6 vertices..
Checks whether the graph is isomorphic to another graph.
The algorithm being used is selected using a simple heuristic:
- If one graph is directed and the other undirected, an exception is thrown.
- If the two graphs does not have the same number of vertices and edges, it returns with False
- If the graphs have three or four vertices, then an O(1) algorithm is used with precomputed data.
- Otherwise if the graphs are directed, then the VF2 isomorphism algorithm is used (see
isomorphic_vf2). - Otherwise the BLISS isomorphism algorithm is used, see
isomorphic_bliss.
Checks whether the graph is isomorphic to another graph, using the BLISS isomorphism algorithm.
See http://www.tcs.hut.fi/Software/bliss/index.html for more information about the BLISS algorithm.
splitting heuristics for the first graph as a case-insensitive string, with the following possible values:
- "f": first non-singleton cell
- "fl": first largest non-singleton cell
- "fs": first smallest non-singleton cell
- "fm": first maximally non-trivially connected non-singleton cell
- "flm": largest maximally non-trivially connected non-singleton cell
- "fsm": smallest maximally non-trivially connected non-singleton cell
Checks whether the graph is isomorphic to another graph, using the VF2 isomorphism algorithm.
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Generates a k-regular random graph
A k-regular random graph is a random graph where each vertex has degree k. If the graph is directed, both the in-degree and the out-degree of each vertex will be k.
Generates a Kautz graph with parameters (m, n)
A Kautz graph is a labeled graph, vertices are labeled by strings of length n + 1 above an alphabet with m + 1 letters, with the restriction that every two consecutive letters in the string must be different. There is a directed edge from a vertex v to another vertex w if it is possible to transform the string of v into the string of w by removing the first letter and appending a letter to it.
Calculates the average degree of the neighbors for each vertex, and the same quantity as the function of vertex degree.
Returns the Laplacian matrix of a graph.
The Laplacian matrix is similar to the adjacency matrix, but the edges are denoted with -1 and the diagonal contains the node degrees.
Symmetric normalized Laplacian matrices have 1 or 0 in their diagonals (0 for vertices with no edges), edges are denoted by 1 / sqrt(d_i * d_j) where d_i is the degree of node i.
Left-normalized and right-normalized Laplacian matrices are derived from the unnormalized Laplacian by scaling the row or the column sums to be equal to 1.
Returns the largest cliques of the graph as a list of tuples.
Quite intuitively a clique is considered largest if there is no clique with more vertices in the whole graph. All largest cliques are maximal (i.e. nonextendable) but not all maximal cliques are largest.
clique_number() for the size of the largest cliques or maximal_cliques() for the maximal cliquesReturns the largest independent vertex sets of the graph as a list of tuples.
Quite intuitively an independent vertex set is considered largest if there is no other set with more vertices in the whole graph. All largest sets are maximal (i.e. nonextendable) but not all maximal sets are largest.
independence_number() for the size of the largest independent vertex sets or maximal_independent_vertex_sets() for the maximal (nonextendable) independent vertex setsGenerates a regular lattice.
Place the vertices of a bipartite graph in two layers.
The layout is created by placing the vertices in two rows, according to their types. The positions of the vertices within the rows are then optimized to minimize the number of edge crossings using the heuristic used by the Sugiyama layout algorithm.
Places the vertices of the graph uniformly on a circle or a sphere.
Places the vertices on a 2D plane according to the Davidson-Harel layout algorithm.
The algorithm uses simulated annealing and a sophisticated energy function, which is unfortunately hard to parameterize for different graphs. The original publication did not disclose any parameter values, and the ones below were determined by experimentation.
The algorithm consists of two phases: an annealing phase and a fine-tuning phase. There is no simulated annealing in the second phase.
Places the vertices on a 2D plane or in the 3D space ccording to the DrL layout algorithm.
This is an algorithm suitable for quite large graphs, but it can be surprisingly slow for small ones (where the simpler force-based layouts like layout_kamada_kawai() or layout_fruchterman_reingold() are more useful.
if you give a string argument here, you can select from five default preset parameterisations: default, coarsen for a coarser layout, coarsest for an even coarser layout, refine for refining an existing layout and final for finalizing a layout. If you supply an object that is not a string, the DrL layout parameters are retrieved from the respective keys of the object (so it should be a dict or something else that supports the mapping protocol). The following keys can be used:
- edge_cut: edge cutting is done in the late stages of the algorithm in order to achieve less dense layouts. Edges are cut if there is a lot of stress on them (a large value in the objective function sum). The edge cutting parameter is a value between 0 and 1 with 0 representing no edge cutting and 1 representing maximal edge cutting.
- init_iterations: number of iterations in the initialization phase
- init_temperature: start temperature during initialization
- init_attraction: attraction during initialization
- init_damping_mult: damping multiplier during initialization
- liquid_iterations, liquid_temperature, liquid_attraction, liquid_damping_mult: same parameters for the liquid phase
- expansion_iterations, expansion_temperature, expansion_attraction, expansion_damping_mult: parameters for the expansion phase
- cooldown_...: parameters for the cooldown phase
- crunch_...: parameters for the crunch phase
- simmer_...: parameters for the simmer phase
Instead of a mapping, you can also use an arbitrary Python object here: if the object does not support the mapping protocol, an attribute of the object with the same name is looked up instead. If a parameter cannot be found either as a key or an attribute, the default from the default preset will be used.
Places the vertices on a 2D plane according to the Fruchterman-Reingold algorithm.
This is a force directed layout, see Fruchterman, T. M. J. and Reingold, E. M.: Graph Drawing by Force-directed Placement. Software -- Practice and Experience, 21/11, 1129--1164, 1991
This is a port of the graphopt layout algorithm by Michael Schmuhl. graphopt version 0.4.1 was rewritten in C and the support for layers was removed.
graphopt uses physical analogies for defining attracting and repelling forces among the vertices and then the physical system is simulated until it reaches an equilibrium or the maximal number of iterations is reached.
See http://www.schmuhl.org/graphopt/ for the original graphopt.
Places the vertices of a graph in a 2D or 3D grid.
Places the vertices on a plane according to the Kamada-Kawai algorithm.
This is a force directed layout, see Kamada, T. and Kawai, S.: An Algorithm for Drawing General Undirected Graphs. Information Processing Letters, 31/1, 7--15, 1989.
Places the vertices on a 2D plane according to the Large Graph Layout.
Places the vertices in an Euclidean space with the given number of dimensions using multidimensional scaling.
This layout requires a distance matrix, where the intersection of row i and column j specifies the desired distance between vertex i and vertex j. The algorithm will try to place the vertices in a way that approximates the distance relations prescribed in the distance matrix. igraph uses the classical multidimensional scaling by Torgerson (see reference below).
For unconnected graphs, the method will decompose the graph into weakly connected components and then lay out the components individually using the appropriate parts of the distance matrix.
ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used.Places the vertices of the graph randomly.
Places the vertices on a 2D plane according to the Reingold-Tilford layout algorithm.
This is a tree layout. If the given graph is not a tree, a breadth-first search is executed first to obtain a possible spanning tree.
Circular Reingold-Tilford layout for trees.
This layout is similar to the Reingold-Tilford layout, but the vertices are placed in a circular way, with the root vertex in the center.
See layout_reingold_tilford for the explanation of the parameters.
Calculates a star-like layout for the graph.
Generates a graph from LCF notation.
LCF is short for Lederberg-Coxeter-Frucht, it is a concise notation for 3-regular Hamiltonian graphs. It consists of three parameters, the number of vertices in the graph, a list of shifts giving additional edges to a cycle backbone and another integer giving how many times the shifts should be performed. See http://mathworld.wolfram.com/LCFNotation.html for details.
Returns the line graph of the graph.
The line graph L(G) of an undirected graph is defined as follows: L(G) has one vertex for each edge in G and two vertices in L(G) are connected iff their corresponding edges in the original graph share an end point.
The line graph of a directed graph is slightly different: two vertices are connected by a directed edge iff the target of the first vertex's corresponding edge is the same as the source of the second vertex's corresponding edge.
Lists the triangles of the graph
Returns the maximum degree of a vertex set in the graph.
This method accepts a single vertex ID or a list of vertex IDs as a parameter, and returns the degree of the given vertices (in the form of a single integer or a list, depending on the input parameter).
igraph.Graph Returns the maximum flow between the source and target vertices.
Returns the value of the maximum flow between the source and target vertices.
Returns the maximal cliques of the graph as a list of tuples.
A maximal clique is a clique which can't be extended by adding any other vertex to it. A maximal clique is not necessarily one of the largest cliques in the graph.
largest_cliques() for the largest cliques.Returns the maximal independent vertex sets of the graph as a list of tuples.
A maximal independent vertex set is an independent vertex set which can't be extended by adding any other vertex to it. A maximal independent vertex set is not necessarily one of the largest independent vertex sets in the graph.
largest_independent_vertex_sets() for the largest independent vertex setsConducts a maximum cardinality search on the graph. The function computes a rank alpha for each vertex such that visiting vertices in decreasing rank order corresponds to always choosing the vertex with the most already visited neighbors as the next one to visit.
Maximum cardinality search is useful in deciding the chordality of a graph: a graph is chordal if and only if any two neighbors of a vertex that are higher in rank than the original vertex are connected to each other.
The result of this function can be passed to is_chordal() to speed up the chordality computation if you also need the result of the maximum cardinality search for other purposes.
igraph.Graph Calculates the minimum cut between the source and target vertices or within the whole graph.
The minimum cut is the minimum set of edges that needs to be removed to separate the source and the target (if they are given) or to disconnect the graph (if the source and target are not given). The minimum is calculated using the weights (capacities) of the edges, so the cut with the minimum total capacity is calculated. For undirected graphs and no source and target, the method uses the Stoer-Wagner algorithm. For a given source and target, the method uses the push-relabel algorithm; see the references below.
Graph which wraps the result in a Cut object. It is advised to use that.Returns the minimum cut between the source and target vertices or within the whole graph.
Computes a minimum cycle basis of the graph
Returns a list containing all separator vertex sets of minimum size.
A vertex set is a separator if its removal disconnects the graph. This method lists all the separators for which no smaller separator set exists in the given graph.
igraph.Graph Calculates the modularity of the graph with respect to some vertex types.
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 is defined as Q = 1 ⁄ (2m)*sum(Aij − gamma*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, Ci and cj are the types of the two vertices (i and j), and gamma is a resolution parameter that defaults to 1 for the classical definition of modularity. 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 incident on vertex i, kj is the total weight of edges incident on vertex j and m is the total edge weight in the graph.
Graph to allow VertexClustering objects as a parameter. This method is not strictly necessary, since the VertexClustering class provides a variable called modularity.Counts the number of motifs in the graph
Motifs are small subgraphs of a given structure in a graph. It is argued that the motif profile (ie. the number of different motifs in the graph) is characteristic for different types of networks and network function is related to the motifs in the graph.
Currently we support motifs of size 3 and 4 for directed graphs, and motifs of size 3, 4, 5 or 6 for undirected graphs.
In a big network the total number of motifs can be very large, so it takes a lot of time to find all of them. In such cases, a sampling method can be used. This function is capable of doing sampling via the cut_prob argument. This argument gives the probability that a branch of the motif search tree will not be explored.
isoclass() ). The search will stop when the callback returns an object with a non-zero truth value or raises an exception.Counts the total number of motifs in the graph
Motifs are small subgraphs of a given structure in a graph. This function estimates the total number of motifs in a graph without assigning isomorphism classes to them by extrapolating from a random sample of vertices.
Currently we support motifs of size 3 and 4 for directed graphs, and motifs of size 3, 4, 5 or 6 for undirected graphs.
Counts the total number of motifs in the graph
Motifs are small subgraphs of a given structure in a graph. This function counts the total number of motifs in a graph without assigning isomorphism classes to them.
Currently we support motifs of size 3 and 4 for directed graphs, and motifs of size 3, 4, 5 or 6 for undirected graphs.
For each vertex specified by vertices, returns the vertices reachable from that vertex in at most order steps. If mindist is larger than zero, vertices that are reachable in less than mindist steps are excluded.
For each vertex specified by vertices, returns the number of vertices reachable from that vertex in at most order steps. If mindist is larger than zero, vertices that are reachable in less than mindist steps are excluded.
Returns adjacent vertices to a given vertex.
igraph.Graph Calculates the path length histogram of the graph
Graph . It is advised to use that instead of this version.Permutes the vertices of the graph according to the given permutation and returns the new graph.
Vertex k of the original graph will become vertex permutation[k] in the new graph. No validity checks are performed on the permutation vector.
Calculates the personalized PageRank values of a graph.
The personalized PageRank calculation is similar to the PageRank calculation, but the random walk is reset to a non-uniform distribution over the vertices in every step with probability 1 − damping instead of a uniform distribution.
VertexSeq or a Vertex . Resetting will take place using a uniform distribution over the specified vertices.ARPACKOptions object used to fine-tune the ARPACK eigenvector calculation. If omitted, the module-level variable called arpack_options is used. This argument is ignored if not the ARPACK implementation is used, see the implementation argument.which implementation to use to solve the PageRank eigenproblem. Possible values are:
- "prpack": use the PRPACK library. This is a new implementation in igraph 0.7
- "arpack": use the ARPACK library. This implementation was used from version 0.5, until version 0.7.
Returns the predecessors of a given vertex.
Equivalent to calling the neighbors() method with type="in".
Generates a graph based on vertex types and connection probabilities.
This is practically the nongrowing variant of Establishment . A given number of vertices are generated. Every vertex is assigned to a vertex type according to the given type probabilities. Finally, every vertex pair is evaluated and an edge is created between them with a probability depending on the types of the vertices involved.
Calculates the radius of the graph.
The radius of a graph is defined as the minimum eccentricity of its vertices (see eccentricity() ).
Performs a random walk of a given length from a given node.
igraph.Graph Reads a graph from a file conforming to the DIMACS minimum-cost flow file format.
For the exact description of the format, see http://lpsolve.sourceforge.net/5.5/DIMACS.htm
Restrictions compared to the official description of the format:
- igraph's DIMACS reader requires only three fields in an arc definition, describing the edge's source and target node and its capacity.
- Source vertices are identified by 's' in the FLOW field, target vertices are identified by 't'.
- Node indices start from 1. Only a single source and target node is allowed.
Reads an UCINET DL file and creates a graph based on it.
Reads an edge list from a file and creates a graph based on it.
Please note that the vertex indices are zero-based. A vertex of zero degree will be created for every integer that is in range but does not appear in the edgelist.
Reads a GML file and creates a graph based on it.
Reads a GraphDB format file and creates a graph based on it.
GraphDB is a binary format, used in the graph database for isomorphism testing (see http://amalfi.dis.unina.it/graph/).
Reads a GraphML format file and creates a graph based on it.
Reads an .lgl file used by LGL.
It is also useful for creating graphs from "named" (and optionally weighted) edge lists.
This format is used by the Large Graph Layout program. See the documentation of LGL regarding the exact format description.
LGL originally cannot deal with graphs containing multiple or loop edges, but this condition is not checked here, as igraph is happy with these.
Reads an .ncol file used by LGL.
It is also useful for creating graphs from "named" (and optionally weighted) edge lists.
This format is used by the Large Graph Layout program. See the repository of LGL for more information.
LGL originally cannot deal with graphs containing multiple or loop edges, but this condition is not checked here, as igraph is happy with these.
Reads a file in the Pajek format and creates a graph based on it. Only Pajek network files (.net extension) are supported, not project files (.paj).
Generates a graph from a degree sequence.
This method implements a Havel-Hakimi style graph construction from a given degree sequence. In each step, the algorithm picks two vertices in a deterministic manner and connects them. The way the vertices are picked is defined by the method parameter. The allowed edge types (i.e. whether multiple or loop edges are allowed) are specified in the allowed_edge_types parameter.
controls whether loops or multi-edges are allowed during the generation process. Note that not all combinations are supported for all types of graphs; an exception will be raised for unsupported combinations. Possible values are:
- "simple": simple graphs (no self-loops, no multi-edges)
- "loops": single self-loops allowed, but not multi-edges
- "multi": multi-edges allowed, but not self-loops
- "all": multi-edges and self-loops allowed
controls how the vertices are selected during the generation process. Possible values are:
- smallest: The vertex with smallest remaining degree first.
- largest: The vertex with the largest remaining degree first.
- index: The vertices are selected in order of their index.
Generates a graph based on a stochastic model where the probability of an edge gaining a new node is proportional to the edges gained in a given time window.
Reciprocity defines the proportion of mutual connections in a directed graph. It is most commonly defined as the probability that the opposite counterpart of a directed edge is also included in the graph. This measure is calculated if mode is "default".
Prior to igraph 0.6, another measure was implemented, defined as the probability of mutual connection between a vertex pair if we know that there is a (possibly non-mutual) connection between them. In other words, (unordered) vertex pairs are classified into three groups: (1) disconnected, (2) non-reciprocally connected and (3) reciprocally connected. The result is the size of group (3), divided by the sum of sizes of groups (2) and (3). This measure is calculated if mode is "ratio".
Reverses the direction of some edges in the graph.
This function is a no-op for undirected graphs.
EdgeSeq objects are also accepted here. When omitted, all edges will be reversed.Randomly rewires the graph while preserving the degree distribution.
Please note that the rewiring is done "in-place", so the original graph will be modified. If you want to preserve the original graph, use the copy method before.
Rewires the edges of a graph with constant probability.
Each endpoint of each edge of the graph will be rewired with a constant probability, given in the first argument.
Please note that the rewiring is done "in-place", so the original graph will be modified. If you want to preserve the original graph, use the copy method before.
Generates a ring graph.
Generates a graph based on a stochastic blockmodel.
A given number of vertices are generated. Every vertex is assigned to a vertex type according to the given block sizes. Vertices of the same type will be assigned consecutive vertex IDs. Finally, every vertex pair is evaluated and an edge is created between them with a probability depending on the types of the vertices involved. The probabilities are taken from the preference matrix.
Dice similarity coefficient of vertices.
The Dice similarity coefficient of two vertices is twice the number of their common neighbors divided by the sum of their degrees. This coefficient is very similar to the Jaccard coefficient, but usually gives higher similarities than its counterpart.
Inverse log-weighted similarity coefficient of vertices.
Each vertex is assigned a weight which is 1 / log(degree). The log-weighted similarity of two vertices is the sum of the weights of their common neighbors.
Jaccard similarity coefficient of vertices.
The Jaccard similarity coefficient of two vertices is the number of their common neighbors divided by the number of vertices that are adjacent to at least one of them.
Simplifies a graph by removing self-loops and/or multiple edges.
For example, suppose you have a graph with an edge attribute named weight. graph.simplify(combine_edges=max) will take the maximum of the weights of multiple edges and assign that weight to the collapsed edge. graph.simplify(combine_edges=sum) will take the sum of the weights. You can also write graph.simplify(combine_edges=dict(weight="sum")) or graph.simplify(combine_edges=dict(weight=sum)), since sum is recognised both as a Python built-in function and as a string constant.
specifies how to combine the attributes of multiple edges between the same pair of vertices into a single attribute. If it is None, only one of the edges will be kept and all the attributes will be lost. If it is a function, the attributes of multiple edges will be collected and passed on to that function which will return the new attribute value that has to be assigned to the single collapsed edge. It can also be one of the following string constants:
- "ignore": all the edge attributes will be ignored.
- "sum": the sum of the edge attribute values will be used for the new edge.
- "product": the product of the edge attribute values will be used for the new edge.
- "mean": the mean of the edge attribute values will be used for the new edge.
- "median": the median of the edge attribute values will be used for the new edge.
- "min": the minimum of the edge attribute values will be used for the new edge.
- "max": the maximum of the edge attribute values will be used for the new edge.
- "first": the attribute value of the first edge in the collapsed set will be used for the new edge.
- "last": the attribute value of the last edge in the collapsed set will be used for the new edge.
- "random": a randomly selected value will be used for the new edge
- "concat": the attribute values will be concatenated for the new edge.
You can also use a dict mapping edge attribute names to functions or the above string constants if you want to make the behaviour of the simplification process depend on the name of the attribute. None is a special key in this dict, its value will be used for all the attributes not specified explicitly in the dictionary.
Calculates the minimum cut between the source and target vertices in a graph.
Generates a star graph.
Generates a non-growing graph with edge probabilities proportional to node fitnesses.
The algorithm randomly selects vertex pairs and connects them until the given number of edges are created. Each vertex is selected with a probability proportional to its fitness; for directed graphs, a vertex is selected as a source proportional to its out-fitness and as a target proportional to its in-fitness.
Generates a non-growing graph with prescribed power-law degree distributions.
Returns the strength (weighted degree) of some vertices from the graph
This method accepts a single vertex ID or a list of vertex IDs as a parameter, and returns the strength (that is, the sum of the weights of all incident edges) of the given vertices (in the form of a single integer or a list, depending on the input parameter).
Determines the indices of vertices which are in the same component as a given vertex.
Returns a subgraph spanned by the given edges.
Checks whether a subgraph of the graph is isomorphic to another graph.
The optional domains argument may be used to restrict vertices that may match each other. You can also specify whether you are interested in induced subgraphs only or not.
Checks whether a subgraph of the graph is isomorphic to another graph.
Vertex and edge colors may be used to restrict the isomorphisms, as only vertices and edges with the same color will be allowed to match each other.
Returns the successors of a given vertex.
Equivalent to calling the neighbors() method with type="out".
Converts an undirected graph to directed.
Converts a tree graph into a Prufer sequence.
Converts a directed graph to undirected.
simplify() for more details.Calculates a possible topological sorting of the graph.
Returns a partial sorting and issues a warning if the graph is not a directed acyclic graph.
igraph.Graph Calculates the average of the vertex transitivities of the graph.
The transitivity measures the probability that two neighbors of a vertex are connected. In case of the average local transitivity, this probability is calculated for each vertex and then the average is taken. Vertices with less than two neighbors require special treatment, they will either be left out from the calculation or they will be considered as having zero transitivity, depending on the mode parameter.
Note that this measure is different from the global transitivity measure (see transitivity_undirected() ) as it simply takes the average local transitivity across the whole network.
Calculates the local transitivity (clustering coefficient) of the given vertices in the graph.
The transitivity measures the probability that two neighbors of a vertex are connected. In case of the local transitivity, this probability is calculated separately for each vertex.
Note that this measure is different from the global transitivity measure (see transitivity_undirected() ) as it calculates a transitivity value for each vertex individually.
The traditional local transitivity measure applies for unweighted graphs only. When the weights argument is given, this function calculates the weighted local transitivity proposed by Barrat et al (see references).
Calculates the global transitivity (clustering coefficient) of the graph.
The transitivity measures the probability that two neighbors of a vertex are connected. More precisely, this is the ratio of the triangles and connected triplets in the graph. The result is a single real number. Directed graphs are considered as undirected ones.
Note that this measure is different from the local transitivity measure (see transitivity_local_undirected() ) as it calculates a single value for the whole graph.
Generates a tree in which almost all vertices have the same number of children.
Generates a random tree by sampling uniformly from the set of labelled trees with a given number of nodes.
the generation method to be used. One of the following:
- "prufer" -- samples Prufer sequences uniformly, then converts them to trees
- "lerw" -- performs a loop-erased random walk on the complete graph to uniformly sample its spanning trees (Wilson's algorithm). This is the default choice as it supports both directed and undirected graphs.
igraph.Graph Triad census, as defined by Davis and Leinhardt
Calculating the triad census means classifying every triplets of vertices in a directed graph. A triplet can be in one of 16 states, these are listed in the documentation of the C interface of igraph.
Graph which wraps the result in a TriadCensus object. It is advised to use that. The name of the triplet classes are also documented there.Unfolds the graph using a BFS to a tree by duplicating vertices as necessary.
topological_sorting() to determine a suitable set. A single vertex index is also accepted.Counts the number of vertices.
Calculates the vertex connectivity of the graph or between some vertices.
The vertex connectivity between two given vertices is the number of vertices that have to be removed in order to disconnect the two vertices into two separate components. This is also the number of vertex disjoint directed paths between the vertices (apart from the source and target vertices of course). The vertex connectivity of the graph is the minimal vertex connectivity over all vertex pairs.
This method calculates the vertex connectivity of a given vertex pair if both the source and target vertices are given. If none of them is given (or they are both negative), the overall vertex connectivity is returned.
igraph.Graph Writes the graph in DIMACS format to the given file.
Writes the graph in DOT format to the given file.
DOT is the format used by the GraphViz software package.
Writes the edge list of a graph to a file.
Directed edges are written in (from, to) order.
Writes the graph in GML format to the given file.
Writes the graph to a GraphML file.
Writes the graph to a file in LEDA native format.
The LEDA format supports at most one attribute per vertex and edge. You can specify which vertex and edge attribute you want to use. Note that the name of the attribute is not saved in the LEDA file.
Writes the edge list of a graph to a file in .lgl format.
Note that multiple edges and/or loops break the LGL software, but igraph does not check for this condition. Unless you know that the graph does not have multiple edges and/or loops, it is wise to call simplify() before saving.
Writes the edge list of a graph to a file in .ncol format.
Note that multiple edges and/or loops break the LGL software, but igraph does not check for this condition. Unless you know that the graph does not have multiple edges and/or loops, it is wise to call simplify() before saving.
Writes the graph in Pajek format to the given file.
Returns the igraph graph encapsulated by the Python object as a PyCapsule
.A PyCapsule is practically a regular C pointer, wrapped in a Python object. This function should not be used directly by igraph users, it is useful only in the case when the underlying igraph object must be passed to other C code through Python.
Registers a destructor to be called when the object is freed by Python. This function should not be used directly by igraph users.
Internal function, undocumented.
Internal function, undocumented.
Internal function, undocumented.
Internal function, undocumented.
Internal function, undocumented.
Internal function, undocumented.
Internal function, undocumented.
Use igraph.Matching.is_maximal instead.
Internal function, undocumented.
Internal function, undocumented.
Returns the memory address of the igraph graph encapsulated by the Python object as an ordinary Python integer.
This function should not be used directly by igraph users, it is useful only if you want to access some unwrapped function in the C core of igraph using the ctypes module.
Internal function, undocumented.
Generates a graph from its adjacency matrix.
the mode to be used. Possible values are:
- "directed" - the graph will be directed and a matrix element gives the number of edges between two vertices.
- "undirected" - alias to "max" for convenience.
- "max" - undirected graph will be created and the number of edges between vertex i and j is max(A(i, j), A(j, i))
- "min" - like "max", but with min(A(i, j), A(j, i))
- "plus" - like "max", but with A(i, j) + A(j, i)
- "upper" - undirected graph with the upper right triangle of the matrix (including the diagonal)
- "lower" - undirected graph with the lower left triangle of the matrix (including the diagonal)