List of all classes, functions and methods in python-igraph
class VertexClustering(Clustering):
The clustering of the vertex set of a graph.
This class extends Clustering
by linking it to a specific Graph
object and by optionally storing the modularity score of the clustering. It also provides some handy methods like getting the subgraph corresponding to a cluster and such.
Note | since this class is linked to a Graph , destroying the graph by the del operator does not free the memory occupied by the graph if there exists a VertexClustering that references the Graph . |
Method | __init__ |
Creates a clustering object for a given graph. |
Class Method | FromAttribute |
Creates a vertex clustering based on the value of a vertex attribute. |
Method | as_cover |
Returns a VertexCover that contains the same clusters as this clustering. |
Method | cluster_graph |
Returns a graph where each cluster is contracted into a single vertex. |
Method | crossing |
Returns a boolean vector where element i is True iff edge i lies between clusters, False otherwise. |
Property | modularity |
Returns the modularity score |
Property | graph |
Returns the graph belonging to this object |
Method | recalculate_modularity |
Recalculates the stored modularity value. |
Method | subgraph |
Get the subgraph belonging to a given cluster. |
Method | subgraphs |
Gets all the subgraphs belonging to each of the clusters. |
Method | giant |
Returns the largest cluster of the clustered graph. |
Method | __plot__ |
Plots the clustering to the given Cairo context in the given bounding box. |
Class Variable | _default_palette |
Undocumented |
Instance Variable | _graph |
Undocumented |
Instance Variable | _modularity |
Undocumented |
Instance Variable | _modularity_dirty |
Undocumented |
Instance Variable | _modularity_params |
Undocumented |
Method | _recalculate_modularity_safe |
Recalculates the stored modularity value and swallows all exceptions raised by the modularity function (if any). |
Method | _formatted_cluster_iterator |
Iterates over the clusters and formats them into a string to be presented in the summary. |
Inherited from Clustering
:
Method | __getitem__ |
Returns the members of the specified cluster. |
Method | __iter__ |
Iterates over the clusters in this clustering. |
Method | __len__ |
Returns the number of clusters. |
Method | __str__ |
Undocumented |
Method | compare_to |
Compares this clustering to another one using some similarity or distance metric. |
Property | membership |
Returns the membership vector. |
Property | n |
Returns the number of elements covered by this clustering. |
Method | size |
Returns the size of a given cluster. |
Method | sizes |
Returns the size of given clusters. |
Method | size_histogram |
Returns the histogram of cluster sizes. |
Method | summary |
Returns the summary of the clustering. |
Instance Variable | _membership |
Undocumented |
Instance Variable | _len |
Undocumented |
igraph.clustering.Clustering.__init__
Creates a clustering object for a given graph.
Parameters | graph | the graph that will be associated to the clustering |
membership | the membership list. The length of the list must be equal to the number of vertices in the graph. If None , every vertex is assumed to belong to the same cluster. | |
modularity | the modularity score of the clustering. If None , it will be calculated when needed. | |
params | additional parameters to be stored in this object. | |
modularity_params | arguments that should be passed to Graph.modularity when the modularity is (re)calculated. If the original graph was weighted, you should pass a dictionary containing a weight key with the appropriate value here. |
Creates a vertex clustering based on the value of a vertex attribute.
Vertices having the same attribute will correspond to the same cluster.
Parameters | graph | the graph on which we are working |
attribute | name of the attribute on which the clustering is based. | |
intervals | for numeric attributes, you can either pass a single number or a list of numbers here. A single number means that the vertices will be put in bins of that width and vertices ending up in the same bin will be in the same cluster. A list of numbers specify the bin positions explicitly; e.g., [10, 20, 30] means that there will be four categories: vertices with the attribute value less than 10, between 10 and 20, between 20 and 30 and over 30. Intervals are closed from the left and open from the right. | |
params | additional parameters to be stored in this object. | |
Returns | a new VertexClustering object |
igraph.clustering.Clustering.as_cover
Returns a VertexCover
that contains the same clusters as this clustering.
Returns a graph where each cluster is contracted into a single vertex.
In the resulting graph, vertex i represents cluster i in this clustering. Vertex i and j will be connected if there was at least one connected vertex pair (a, b) in the original graph such that vertex a was in cluster i and vertex b was in cluster j.
Parameters | combine_vertices | specifies how to derive the attributes of the vertices in the new graph from the attributes of the old ones. See Graph.contract_vertices() for more details. |
combine_edges | specifies how to derive the attributes of the edges in the new graph from the attributes of the old ones. See Graph.simplify() for more details. If you specify False here, edges will not be combined, and the number of edges between the vertices representing the original clusters will be equal to the number of edges between the members of those clusters in the original graph. | |
Returns | the new graph. |
Returns a boolean vector where element i is True
iff edge i lies between clusters, False
otherwise.
Recalculates the stored modularity value.
This method must be called before querying the modularity score of the clustering through the class member modularity
or q
if the graph has been modified (edges have been added or removed) since the creation of the VertexClustering
object.
Returns | the new modularity score |
Recalculates the stored modularity value and swallows all exceptions raised by the modularity function (if any).
Returns | the new modularity score or None if the modularity function could not be calculated. |
Get the subgraph belonging to a given cluster.
Precondition: the vertex set of the graph hasn't been modified since the moment the cover was constructed.
Parameters | idx | the cluster index |
Returns | a copy of the subgraph |
Gets all the subgraphs belonging to each of the clusters.
Precondition: the vertex set of the graph hasn't been modified since the moment the cover was constructed.
Returns | a list containing copies of the subgraphs |
Returns the largest cluster of the clustered graph.
The largest cluster is a cluster for which no larger cluster exists in the clustering. It may also be known as the giant community if the clustering represents the result of a community detection function.
Precondition: the vertex set of the graph hasn't been modified since the moment the cover was constructed.
Returns | a copy of the largest cluster. | |
Note | there can be multiple largest clusters, this method will return the copy of an arbitrary one if there are multiple largest clusters. |
Plots the clustering to the given Cairo context in the given bounding box.
This is done by calling Graph.__plot__()
with the same arguments, but coloring the graph vertices according to the current clustering (unless overridden by the vertex_color
argument explicitly).
This method understands all the positional and keyword arguments that are understood by Graph.__plot__()
, only the differences will be highlighted here:
mark_groups
: whether to highlight some of the vertex groups by colored polygons. Besides the values accepted by Graph.__plot__
(i.e., a dict mapping colors to vertex indices, a list containing lists of vertex indices, or False
), the following are also accepted:True
: all the groups will be highlighted, the colors matching the corresponding color indices from the current palette (see the palette
keyword argument of Graph.__plot__
.The value of the plotting.mark_groups
configuration key is also taken into account here; if that configuration key is True
and mark_groups
is not given explicitly, it will automatically be set to True
.
In place of lists of vertex indices, you may also use VertexSeq
instances.
In place of color names, you may also use color indices into the current palette. None
as a color name will mean that the corresponding group is ignored.
palette
: the palette used to resolve numeric color indices to RGBA values. By default, this is an instance of ClusterColoringPalette
.See Also | Graph.__plot__() for more supported keyword arguments. |