xgi.algorithms.connected#
Algorithms related to connected components of a hypergraph.
Functions
- connected_components(H)[source]#
A function to find the connected components of a hypergraph.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
- Returns:
An iterator where each entry is a component of the hypergraph.
- Return type:
iterable of sets
See also
is_connected
,number_connected_components
,largest_connected_component
,largest_connected_hypergraph
Example
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.1, 0.01], seed=1) >>> print([len(component) for component in xgi.connected_components(H)]) [50]
- is_connected(H)[source]#
A function to determine whether a hypergraph is connected.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
- Returns:
Whether the hypergraph is connected.
- Return type:
bool
See also
connected_components
,number_connected_components
,largest_connected_component
,largest_connected_hypergraph
Example
>>> import xgi >>> H = xgi.random_hypergraph(10, [0.5, 0.01], seed=1) >>> print(xgi.is_connected(H)) True
- largest_connected_component(H)[source]#
A function to find the largest connected component of a hypergraph.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
- Returns:
The largest connected component (a set of nodes) of the hypergraph.
- Return type:
set
Example
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.1, 0.01], seed=1) >>> print(len(xgi.largest_connected_component(H))) 50
- largest_connected_hypergraph(H, in_place=False)[source]#
A function to find the largest connected hypergraph from a data set.
- Parameters:
H (Hypergraph) – The hypergraph of interest
in_place (bool, optional) – If False, creates a copy; if True, modifies the existing hypergraph. By default, True.
- Returns:
None – If in_place: modifies the existing hypergraph
Hypergraph – If not in_place: the hypergraph induced on the nodes of the largest connected component.
Example
>>> import xgi >>> H = xgi.random_hypergraph(10, [0.1, 0.01], seed=1) >>> H_gcc = xgi.largest_connected_hypergraph(H) >>> print(H_gcc.num_nodes) 6
- node_connected_component(H, n)[source]#
A function to find the connected component of which a node in the hypergraph is a part.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
n (hashable) – Node label
See also
- Returns:
Returns the connected component of which the specified node in the hypergraph is a part.
- Return type:
set
Example
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.1, 0.01], seed=1) >>> comp = xgi.node_connected_component(H, 0) >>> print(type(comp), len(comp)) <class 'set'> 50
- number_connected_components(H)[source]#
A function to find the number of connected components of a hypergraph.
- Parameters:
H (Hypergraph object) – The hypergraph of interest
- Returns:
The number of connected components of the hypergraph.
- Return type:
int
See also
is_connected
,connected_components
,largest_connected_component
,largest_connected_hypergraph
Example
>>> import xgi >>> H = xgi.random_hypergraph(50, [0.1, 0.01], seed=1) >>> print(xgi.number_connected_components(H)) 1