Generic graph.
This class is built on top of GraphBase
, so the order of the methods in the generated API documentation is a little bit obscure: inherited methods come after the ones implemented directly in the subclass. Graph
provides many functions that GraphBase
does not, mostly because these functions are not speed critical and they were easier to implement in Python than in pure C. An example is the attribute handling in the constructor: the constructor of Graph
accepts three dictionaries corresponding to the graph, vertex and edge attributes while the constructor of GraphBase
does not. This extension was needed to make Graph
serializable through the pickle module. Graph
also overrides some functions from GraphBase
to provide a more convenient interface; e.g., layout functions return a Layout
instance from Graph
instead of a list of coordinate pairs.
Graphs can also be indexed by strings or pairs of vertex indices or vertex names. When a graph is indexed by a string, the operation translates to the retrieval, creation, modification or deletion of a graph attribute:
>>> g = Graph.Full(3) >>> g["name"] = "Triangle graph" >>> g["name"] 'Triangle graph' >>> del g["name"]
When a graph is indexed by a pair of vertex indices or names, the graph itself is treated as an adjacency matrix and the corresponding cell of the matrix is returned:
>>> g = Graph.Full(3) >>> g.vs["name"] = ["A", "B", "C"] >>> g[1, 2] 1 >>> g["A", "B"] 1 >>> g["A", "B"] = 0 >>> g.ecount() 2
Assigning values different from zero or one to the adjacency matrix will be translated to one, unless the graph is weighted, in which case the numbers will be treated as weights:
>>> g.is_weighted() False >>> g["A", "B"] = 2 >>> g["A", "B"] 1 >>> g.es["weight"] = 1.0 >>> g.is_weighted() True >>> g["A", "B"] = 2 >>> g["A", "B"] 2 >>> g.es["weight"] [1.0, 1.0, 2]
Class Method |
|
Deprecated alias to Graph.Biadjacency() . |
Method | __bool__ |
Returns True if the graph has at least one vertex, False otherwise. |
Method | __coerce__ |
Coercion rules. |
Method | __init__ |
__init__(n=0, edges=None, directed=False, graph_attrs=None, vertex_attrs=None, edge_attrs=None) |
Method | __reduce__ |
Support for pickling. |
Method | __str__ |
Returns a string representation of the graph. |
Method | dfs |
Conducts a depth first search (DFS) on the graph. |
Method | dyad |
Calculates the dyad census of the graph. |
Method | get |
Calculates all the simple paths from a given node to some other nodes (or all of them) in a graph. |
Method | get |
Deprecated alias to Graph.get_biadjacency() . |
Method | is |
Returns whether the graph is named. |
Method | is |
Returns whether the graph is weighted. |
Method | path |
Returns the path length histogram of the graph |
Method | spanning |
Calculates a minimum spanning tree for a graph. |
Method | summary |
Returns the summary of the graph. |
Method | transitivity |
Calculates the average of the vertex transitivities of the graph. |
Method | triad |
Calculates the triad census of the graph. |
Constant | GRG |
Undocumented |
Class Variable | __add__ |
Undocumented |
Class Variable | __and__ |
Undocumented |
Class Variable | __hash__ |
Undocumented |
Class Variable | __iadd__ |
Undocumented |
Class Variable | __isub__ |
Undocumented |
Class Variable | __iter__ |
Undocumented |
Class Variable | __mul__ |
Undocumented |
Class Variable | __or__ |
Undocumented |
Class Variable | __sub__ |
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable | disjoint |
Undocumented |
Class Variable |
|
Undocumented |
Class Variable | from |
Undocumented |
Class Variable | from |
Undocumented |
Class Variable |
|
Undocumented |
Class Variable | intersection |
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable |
|
Undocumented |
Class Variable | union |
Undocumented |
Class Variable |
|
Undocumented |
Property | es |
The edge sequence of the graph |
Property | vs |
The vertex sequence of the graph |
Class Method | _reconstruct |
Reconstructs a Graph object from Python's pickled format. |
Property | _as |
Undocumented |
Inherited from GraphBase
:
Method | __new__ |
Create and return a new object. See help(type) for accurate signature. |
Method | add |
Adds edges to the graph. |
Method | add |
Adds vertices to the graph. |
Method |
|
Generates a graph from its adjacency matrix. |
Method | all |
Returns a list containing all the minimal s-t separators of a graph. |
Method | all |
Returns all the cuts between the source and target vertices in a directed graph. |
Method | all |
Returns all minimum cuts between the source and target vertices in a directed graph. |
Method | are |
Decides whether two given vertices are directly connected. |
Method | articulation |
Returns the list of articulation points in the graph. |
Method | assortativity |
Returns the assortativity of the graph based on numeric properties of the vertices. |
Method | assortativity |
Returns the assortativity of a graph based on vertex degrees. |
Method | assortativity |
Returns the assortativity of the graph based on vertex categories. |
Method |
|
Generates a graph based on asymmetric vertex types and connection probabilities. |
Method |
|
Generates a graph from the Graph Atlas. |
Method | attributes |
No summary |
Method | authority |
Calculates Kleinberg's authority score for the vertices of the graph |
Method | automorphism |
Calculates the generators of the automorphism group of a graph using the BLISS isomorphism algorithm. |
Method | average |
Calculates the average path length in a graph. |
Method |
|
Generates a graph based on the Barabási-Albert model. |
Method | betweenness |
Calculates or estimates the betweenness of vertices in a graph. |
Method | bfs |
Conducts a breadth first search (BFS) on the graph. |
Method | bfsiter |
Constructs a breadth first search (BFS) iterator of the graph. |
Method | bibcoupling |
Calculates bibliographic coupling scores for given vertices in a graph. |
Method | biconnected |
Calculates the biconnected components of the graph. |
Method | bipartite |
Internal function, undocumented. |
Method | bipartite |
Internal function, undocumented. |
Method | bridges |
Returns the list of bridges in the graph. |
Method | canonical |
Calculates the canonical permutation of a graph using the BLISS isomorphism algorithm. |
Method | chordal |
Returns the list of edges needed to be added to the graph to make it chordal. |
Method | clique |
Returns the clique number of the graph. |
Method | cliques |
Returns some or all cliques of the graph as a list of tuples. |
Method | closeness |
Calculates the closeness centralities of given vertices in a graph. |
Method | cocitation |
Calculates cocitation scores for given vertices in a graph. |
Method | cohesive |
Calculates the cohesive block structure of the graph. |
Method | community |
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... |
Method | community |
Finds the community structure of the graph according to the algorithm of Clauset et al based on the greedy optimization of modularity. |
Method | community |
Finds the community structure of the network according to the Infomap method of Martin Rosvall and Carl T. Bergstrom. |
Method | community |
Finds the community structure of the graph according to the label propagation method of Raghavan et al. |
Method | community |
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. |
Method | community |
Finds the community structure of the graph using the Leiden algorithm of Traag, van Eck & Waltman. |
Method | community |
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... |
Method | community |
Calculates the optimal modularity score of the graph and the corresponding community structure. |
Method | community |
Finds the community structure of the graph according to the spinglass community detection method of Reichardt & Bornholdt. |
Method | community |
Finds the community structure of the graph according to the random walk method of Latapy & Pons. |
Method | complementer |
Returns the complementer of the graph |
Method | compose |
Returns the composition of two graphs. |
Method | connected |
Calculates the (strong or weak) connected components for a given graph. |
Method | constraint |
Calculates Burt's constraint scores for given vertices in a graph. |
Method | contract |
Contracts some vertices in the graph, i.e. replaces groups of vertices with single vertices. Edges are not affected. |
Method | convergence |
Undocumented (yet). |
Method | convergence |
Undocumented (yet). |
Method | copy |
Creates a copy of the graph. |
Method | coreness |
Finds the coreness (shell index) of the vertices of the network. |
Method | count |
Calculates the number of automorphisms of a graph using the BLISS isomorphism algorithm. |
Method | count |
Determines the number of isomorphisms between the graph and another one |
Method | count |
Counts the multiplicities of the given edges. |
Method | count |
Determines the number of subisomorphisms between the graph and another one |
Method |
|
Generates a de Bruijn graph with parameters (m, n) |
Method | decompose |
Decomposes the graph into subgraphs. |
Method | degree |
Returns some vertex degrees from the graph. |
Method |
|
Generates a graph with a given degree sequence. |
Method | delete |
Removes edges from the graph. |
Method | delete |
Deletes vertices and all its edges from the graph. |
Method | density |
Calculates the density of the graph. |
Method | dfsiter |
Constructs a depth first search (DFS) iterator of the graph. |
Method | diameter |
Calculates the diameter of the graph. |
Method | difference |
Subtracts the given graph from the original |
Method | distances |
Calculates shortest path lengths for given vertices in a graph. |
Method | diversity |
Calculates the structural diversity index of the vertices. |
Method | dominator |
Returns the dominator tree from the given root node |
Method | eccentricity |
Calculates the eccentricities of given vertices in a graph. |
Method | ecount |
Counts the number of edges. |
Method | edge |
No summary |
Method | edge |
Calculates or estimates the edge betweennesses in a graph. |
Method | edge |
Calculates the edge connectivity of the graph or between some vertices. |
Method | eigen |
Undocumented |
Method | eigenvector |
Calculates the eigenvector centralities of the vertices in a graph. |
Method |
|
Generates a graph based on the Erdős-Rényi model. |
Method |
|
Generates a graph based on a simple growing model with vertex types. |
Method |
|
Generates a famous graph based on its name. |
Method | farthest |
Returns two vertex IDs whose distance equals the actual diameter of the graph. |
Method | feedback |
Calculates an approximately or exactly minimal feedback arc set. |
Method |
|
Generates a graph based on the forest fire model |
Method |
|
Generates a full graph (directed or undirected, with or without loops). |
Method |
|
Generates a full citation graph |
Method | fundamental |
Finds a single fundamental cycle basis of the graph |
Method | get |
Returns the adjacency matrix of a graph. |
Method | get |
Calculates all of the shortest paths from/to a given node in a graph. |
Method | get |
Internal function, undocumented. |
Method | get |
Returns a path with the actual diameter of the graph. |
Method | get |
Returns the edge list of a graph. |
Method | get |
Returns the edge ID of an arbitrary edge between vertices v1 and v2 |
Method | get |
Returns the edge IDs of some edges between some vertices. |
Method | get |
Returns all isomorphisms between the graph and another one |
Method | get |
Calculates the k shortest paths from/to a given node in a graph. |
Method | get |
Calculates the shortest path from a source vertex to a target vertex in a graph. |
Method | get |
Calculates the shortest path from a source vertex to a target vertex in a graph using the A-Star algorithm and a heuristic function. |
Method | get |
Calculates the shortest paths from/to a given node in a graph. |
Method | get |
Returns all subisomorphisms between the graph and another one using the LAD algorithm. |
Method | get |
Returns all subisomorphisms between the graph and another one |
Method | girth |
Returns the girth of the graph. |
Method | gomory |
Internal function, undocumented. |
Method |
|
Generates a growing random graph. |
Method | harmonic |
Calculates the harmonic centralities of given vertices in a graph. |
Method | has |
Checks whether the graph has multiple edges. |
Method |
|
Generates a regular hexagonal lattice. |
Method | hub |
Calculates Kleinberg's hub score for the vertices of the graph |
Method | incident |
Returns the edges a given vertex is incident on. |
Method | independence |
Returns the independence number of the graph. |
Method | independent |
Returns some or all independent vertex sets of the graph as a list of tuples. |
Method | induced |
Returns a subgraph spanned by the given vertices. |
Method | is |
Returns whether the graph is acyclic (i.e. contains no cycles). |
Method | is |
Decides whether the graph is biconnected. |
Method | is |
Decides whether the graph is bipartite or not. |
Method | is |
Returns whether the graph is chordal or not. |
Method | is |
Decides whether the graph is connected. |
Method | is |
Checks whether the graph is a DAG (directed acyclic graph). |
Method | is |
Checks whether the graph is directed. |
Method | is |
Checks whether a specific set of edges contain loop edges |
Method | is |
Decides whether the given vertex set is a minimal separator. |
Method | is |
Checks whether an edge is a multiple edge. |
Method | is |
Checks whether an edge has an opposite pair. |
Method | is |
Decides whether the removal of the given vertices disconnects the graph. |
Method | is |
Checks whether the graph is simple (no loop or multiple edges). |
Method | is |
Checks whether the graph is a (directed or undirected) tree graph. |
Method |
|
Generates a graph with a given isomorphism class. |
Method | isoclass |
Returns the isomorphism class of the graph or its subgraph. |
Method | isomorphic |
Checks whether the graph is isomorphic to another graph. |
Method | isomorphic |
Checks whether the graph is isomorphic to another graph, using the BLISS isomorphism algorithm. |
Method | isomorphic |
Checks whether the graph is isomorphic to another graph, using the VF2 isomorphism algorithm. |
Method |
|
Generates a k-regular random graph |
Method |
|
Generates a Kautz graph with parameters (m, n) |
Method | knn |
Calculates the average degree of the neighbors for each vertex, and the same quantity as the function of vertex degree. |
Method | laplacian |
Returns the Laplacian matrix of a graph. |
Method | largest |
Returns the largest cliques of the graph as a list of tuples. |
Method | largest |
Returns the largest independent vertex sets of the graph as a list of tuples. |
Method |
|
Generates a regular square lattice. |
Method | layout |
Place the vertices of a bipartite graph in two layers. |
Method | layout |
Places the vertices of the graph uniformly on a circle or a sphere. |
Method | layout |
Places the vertices on a 2D plane according to the Davidson-Harel layout algorithm. |
Method | layout |
Places the vertices on a 2D plane or in the 3D space ccording to the DrL layout algorithm. |
Method | layout |
Places the vertices on a 2D plane according to the Fruchterman-Reingold algorithm. |
Method | layout |
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. |
Method | layout |
Places the vertices of a graph in a 2D or 3D grid. |
Method | layout |
Places the vertices on a plane according to the Kamada-Kawai algorithm. |
Method | layout |
Places the vertices on a 2D plane according to the Large Graph Layout. |
Method | layout |
Places the vertices in an Euclidean space with the given number of dimensions using multidimensional scaling. |
Method | layout |
Places the vertices of the graph randomly. |
Method | layout |
Places the vertices on a 2D plane according to the Reingold-Tilford layout algorithm. |
Method | layout |
Circular Reingold-Tilford layout for trees. |
Method | layout |
Calculates a star-like layout for the graph. |
Method | layout |
Uniform Manifold Approximation and Projection (UMAP). |
Method | LCF |
Generates a graph from LCF notation. |
Method | linegraph |
Returns the line graph of the graph. |
Method | list |
Lists the triangles of the graph |
Method | maxdegree |
Returns the maximum degree of a vertex set in the graph. |
Method | maxflow |
Returns the maximum flow between the source and target vertices. |
Method | maxflow |
Returns the value of the maximum flow between the source and target vertices. |
Method | maximal |
Returns the maximal cliques of the graph as a list of tuples. |
Method | maximal |
Returns the maximal independent vertex sets of the graph as a list of tuples. |
Method | maximum |
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. |
Method | mincut |
Calculates the minimum cut between the source and target vertices or within the whole graph. |
Method | mincut |
Returns the minimum cut between the source and target vertices or within the whole graph. |
Method | minimum |
Computes a minimum cycle basis of the graph |
Method | minimum |
Returns a list containing all separator vertex sets of minimum size. |
Method | modularity |
Calculates the modularity of the graph with respect to some vertex types. |
Method | modularity |
Calculates the modularity matrix of the graph. |
Method | motifs |
Counts the number of motifs in the graph |
Method | motifs |
Counts the total number of motifs in the graph |
Method | motifs |
Counts the total number of motifs in the graph |
Method | 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. |
Method | neighborhood |
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... |
Method | neighbors |
Returns adjacent vertices to a given vertex. |
Method | permute |
Permutes the vertices of the graph according to the given permutation and returns the new graph. |
Method | personalized |
Calculates the personalized PageRank values of a graph. |
Method | predecessors |
Returns the predecessors of a given vertex. |
Method |
|
Generates a graph based on vertex types and connection probabilities. |
Method |
|
Generates a tree from its Prüfer sequence. |
Method | radius |
Calculates the radius of the graph. |
Method | random |
Performs a random walk of a given length from a given node. |
Method |
|
Reads a graph from a file conforming to the DIMACS minimum-cost flow file format. |
Method |
|
Reads an UCINET DL file and creates a graph based on it. |
Method |
|
Reads an edge list from a file and creates a graph based on it. |
Method |
|
Reads a GML file and creates a graph based on it. |
Method |
|
Reads a GraphDB format file and creates a graph based on it. |
Method |
|
Reads a GraphML format file and creates a graph based on it. |
Method |
|
Reads an .lgl file used by LGL. |
Method |
|
Reads an .ncol file used by LGL. |
Method |
|
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). |
Method |
|
Generates a bipartite graph from the degree sequences of its partitions. |
Method |
|
Generates a graph from a degree sequence. |
Method |
|
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. |
Method | 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... |
Method | reverse |
Reverses the direction of some edges in the graph. |
Method | rewire |
Randomly rewires the graph while preserving the degree distribution. |
Method | rewire |
Rewires the edges of a graph with constant probability. |
Method |
|
Generates a ring graph. |
Method | SBM |
Generates a graph based on a stochastic block model. |
Method | similarity |
Dice similarity coefficient of vertices. |
Method | similarity |
Inverse log-weighted similarity coefficient of vertices. |
Method | similarity |
Jaccard similarity coefficient of vertices. |
Method | simplify |
Simplifies a graph by removing self-loops and/or multiple edges. |
Method | st |
Calculates the minimum cut between the source and target vertices in a graph. |
Method |
|
Generates a star graph. |
Method |
|
Generates a non-growing graph with edge probabilities proportional to node fitnesses. |
Method |
|
Generates a non-growing graph with prescribed power-law degree distributions. |
Method | strength |
Returns the strength (weighted degree) of some vertices from the graph |
Method | subcomponent |
Determines the indices of vertices which are in the same component as a given vertex. |
Method | subgraph |
Returns a subgraph spanned by the given edges. |
Method | subisomorphic |
Checks whether a subgraph of the graph is isomorphic to another graph. |
Method | subisomorphic |
Checks whether a subgraph of the graph is isomorphic to another graph. |
Method | successors |
Returns the successors of a given vertex. |
Method | to |
Converts an undirected graph to directed. |
Method | to |
Converts a tree graph into a Prüfer sequence. |
Method | to |
Converts a directed graph to undirected. |
Method | topological |
Calculates a possible topological sorting of the graph. |
Method | transitivity |
Calculates the local transitivity (clustering coefficient) of the given vertices in the graph. |
Method | transitivity |
Calculates the global transitivity (clustering coefficient) of the graph. |
Method |
|
Generates a tree in which almost all vertices have the same number of children. |
Method |
|
Generates a random tree by sampling uniformly from the set of labelled trees with a given number of nodes. |
Method |
|
Generates a regular triangular lattice. |
Method | unfold |
Unfolds the graph using a BFS to a tree by duplicating vertices as necessary. |
Method | vcount |
Counts the number of vertices. |
Method | vertex |
No summary |
Method | vertex |
Calculates a greedy vertex coloring for the graph based on some heuristics. |
Method | vertex |
Calculates the vertex connectivity of the graph or between some vertices. |
Method |
|
This function generates networks with the small-world property based on a variant of the Watts-Strogatz model. The network is obtained by first creating a periodic undirected lattice, then rewiring both endpoints of each edge with probability ... |
Method | write |
Writes the graph in DIMACS format to the given file. |
Method | write |
Writes the graph in DOT format to the given file. |
Method | write |
Writes the edge list of a graph to a file. |
Method | write |
Writes the graph in GML format to the given file. |
Method | write |
Writes the graph to a GraphML file. |
Method | write |
Writes the graph to a file in LEDA native format. |
Method | write |
Writes the edge list of a graph to a file in .lgl format. |
Method | write |
Writes the edge list of a graph to a file in .ncol format. |
Method | write |
Writes the graph in Pajek format to the given file. |
Method | __graph |
Returns the igraph graph encapsulated by the Python object as a PyCapsule |
Method | __invalidate |
Invalidates the internal cache of the low-level C graph object that the Python object wraps. This function should not be used directly by igraph users, but it may be useful for benchmarking or debugging purposes. |
Method | __register |
Registers a destructor to be called when the object is freed by Python. This function should not be used directly by igraph users. |
Method | _ |
Internal function, undocumented. |
Method | _ |
Internal function, undocumented. |
Method | _ |
Internal function, undocumented. |
Method | _get |
Internal function, undocumented. |
Method | _GRG |
Internal function, undocumented. |
Method | _is |
Internal function, undocumented. |
Method | _is |
Internal function, undocumented. |
Method | _layout |
Internal function, undocumented. |
Method | _maximum |
Internal function, undocumented. |
Method | _ |
Internal function, undocumented. |
Method | _raw |
Returns the memory address of the igraph graph encapsulated by the Python object as an ordinary Python integer. |
Method | _spanning |
Internal function, undocumented. |
Method | _ |
Generates a graph from its adjacency matrix. |
Coercion rules.
This method is needed to allow the graph to react to additions with lists, tuples, integers, strings, vertices, edges and so on.
__init__(n=0, edges=None, directed=False, graph_attrs=None, vertex_attrs=None, edge_attrs=None)
Constructs a graph from scratch.
Parameters | |
*args | Undocumented |
n | the number of vertices. Can be omitted, the default is zero. Note that if the edge list contains vertices with indexes larger than or equal to n, then the number of vertices will be adjusted accordingly. |
edges | the edge list where every list item is a pair of integers. If any of the integers is larger than n − 1, the number of vertices is adjusted accordingly. None means no edges. |
directed | whether the graph should be directed |
graph | the attributes of the graph as a dictionary. |
vertex | the attributes of the vertices as a dictionary. The keys of the dictionary must be the names of the attributes; the values must be iterables with exactly n items where n is the number of vertices. |
edge | the attributes of the edges as a dictionary. The keys of the dictionary must be the names of the attributes; the values must be iterables with exactly m items where m is the number of edges. |
Returns a string representation of the graph.
Behind the scenes, this method constructs a GraphSummary
instance and invokes its __str__ method with a verbosity of 1 and attribute printing turned off.
See the documentation of GraphSummary
for more details about the output.
Conducts a depth first search (DFS) on the graph.
Parameters | |
vid | the root vertex ID |
mode | either "in" or "out" or "all", ignored for undirected graphs. |
Returns | |
a tuple with the following items:
|
igraph.GraphBase.dyad_census
Calculates the dyad census of the graph.
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 from a to b or from b to a but not the other way round) and null (there is no connection between a and b).
Reference: Holland, P.W. and Leinhardt, S. A Method for Detecting Structure in Sociometric Data. American Journal of Sociology, 70, 492-513, 1970.
Returns | |
a DyadCensus object. |
Calculates all the simple paths from a given node to some other nodes (or all of them) in a graph.
A path is simple if its vertices are unique, i.e. no vertex is visited more than once.
Note that potentially there are exponentially many paths between two vertices of a graph, especially if your graph is lattice-like. In this case, you may run out of memory when using this function.
Parameters | |
v | the source for the calculated paths |
to | a vertex selector describing the destination for the calculated paths. This can be a single vertex ID, a list of vertex IDs, a single vertex name, a list of vertex names or a VertexSeq object. None means all the vertices. |
cutoff | maximum length of path that is considered. If negative, paths of all lengths are considered. |
mode | the directionality of the paths. "in" means to calculate incoming paths, "out" means to calculate outgoing paths, "all" means to calculate both ones. |
Returns | |
all of the simple paths from the given node to every other reachable node in the graph in a list. Note that in case of mode="in", the vertices in a path are returned in reversed order! |
Returns whether the graph is named.
A graph is named if and only if it has a "name" vertex attribute.
Returns whether the graph is weighted.
A graph is weighted if and only if it has a "weight" edge attribute.
igraph.GraphBase.path_length_hist
Returns the path length histogram of the graph
Parameters | |
directed | whether to consider directed paths. Ignored for undirected graphs. |
Returns | |
a Histogram object. The object will also have an unconnected attribute that stores the number of unconnected vertex pairs (where the second vertex can not be reached from the first one). The latter one will be of type long (and not a simple integer), since this can be very large. |
Calculates a minimum spanning tree for a graph.
Reference: Prim, R.C. Shortest connection networks and some generalizations. Bell System Technical Journal 36:1389-1401, 1957.
Parameters | |
weights | a vector containing weights for every edge in the graph. None means that the graph is unweighted. |
return | whether to return the minimum spanning tree (when return_tree is True) or to return the IDs of the edges in the minimum spanning tree instead (when return_tree is False). The default is True for historical reasons as this argument was introduced in igraph 0.6. |
Returns | |
the spanning tree as a Graph object if return_tree is True or the IDs of the edges that constitute the spanning tree if return_tree is False. |
Returns the summary of the graph.
The output of this method is similar to the output of the __str__ method. If verbosity is zero, only the header line is returned (see __str__ for more details), otherwise the header line and the edge list is printed.
Behind the scenes, this method constructs a GraphSummary
object and invokes its __str__ method.
Parameters | |
verbosity | if zero, only the header line is returned (see __str__ for more details), otherwise the header line and the full edge list is printed. |
width | the number of characters to use in one line. If None, no limit will be enforced on the line lengths. |
*args | Undocumented |
**kwds | Undocumented |
Returns | |
the summary of the graph. |
Calculates the average of the vertex transitivities of the graph.
In the unweighted case, 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. The calculation is slightly more involved for weighted graphs; in this case, weights are taken into account according to the formula of Barrat et al (see the references).
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.
References
- Watts DJ and Strogatz S: Collective dynamics of small-world networks. Nature 393(6884):440-442, 1998.
- Barrat A, Barthelemy M, Pastor-Satorras R and Vespignani A: The architecture of complex weighted networks. PNAS 101, 3747 (2004). http://arxiv.org/abs/cond-mat/0311416.
Parameters | |
mode | defines how to treat vertices with degree less than two. If TRANSITIVITY_ZERO or "zero", these vertices will have zero transitivity. If TRANSITIVITY_NAN or "nan", these vertices will be excluded from the average. |
weights | edge weights to be used. Can be a sequence or iterable or even an edge attribute name. |
See Also | |
transitivity_undirected() , transitivity_local_undirected() |
igraph.GraphBase.triad_census
Calculates the triad census of the graph.
Reference: Davis, J.A. and Leinhardt, S. The Structure of Positive Interpersonal Relations in Small Groups. In: J. Berger (Ed.), Sociological Theories in Progress, Volume 2, 218-251. Boston: Houghton Mifflin (1972).
Returns | |
a TriadCensus object. |