cotengra.hypergraph¶
Simple hypergraph (and also linegraph) representations for simulating contractions.
Attributes¶
Classes¶
Simple hypergraph builder and writer. |
|
Very simple line-graph builder and file writer. |
Functions¶
|
Single entry-point for creating a, possibly accelerated, HyperGraph. |
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- cotengra.hypergraph.HyperGraphRust = None¶
- class cotengra.hypergraph.HyperGraph(inputs, output=None, size_dict=None)[source]¶
Simple hypergraph builder and writer.
- Parameters:
- __slots__ = ('inputs', 'output', 'size_dict', 'nodes', 'edges', 'node_counter')¶
- inputs¶
- output = []¶
- size_dict¶
- edges¶
- node_counter¶
- property num_nodes¶
- property num_edges¶
- contract_pair_cost(i, j)[source]¶
Get the cost of contracting nodes
iandj- the product of the dimensions of the indices involved.
- neighbor_edges(i)[source]¶
Get the edges incident to all neighbors of node
i, (including its own edges).
- add_node(inds, node=None)[source]¶
Add a node with
inds, and optional identifiernode. The identifier will be generated if not given and returned.
- compress(chi, edges=None)[source]¶
‘Compress’ multiedges, combining their size up to a maximum of
chi.
- candidate_contraction_size(i, j, chi=None)[source]¶
Get the size of the node created if
iandjwere contracted, optionally including the effect of first compressing bonds to sizechi.
- simple_distance(region, p=2)[source]¶
Compute a simple distance metric from nodes in
regionto all others. Unlike graph distance, relative connectedness is taken into account.
- simple_closeness(p=0.75, mu=0.5)[source]¶
Compute a rough hypergraph ‘closeness’.
- Parameters:
- Returns:
scores – The simple hypergraph closenesses - higher being more central.
- Return type:
- simple_centrality(r=None, smoothness=2, **closeness_opts)[source]¶
A simple algorithm for large hypergraph centrality. First we find a rough closeness centrality, then relax / smooth this by nodes iteratively radiating their centrality to their neighbors.
- Parameters:
r (None or int, optional) – Number of iterations. Defaults to
max(10, int(self.num_nodes**0.5)).smoothness (float, optional) – The smoothness. In conjunction with a high value of
rthis will create a smooth gradient from one of the hypergraph to the other.closeness_opts – Supplied to
HyperGraph.simple_closenessas the starting point.
- Return type:
- compute_loops(start=None, max_loop_length=None)[source]¶
Generate all loops up to a certain length in this hypergraph.
- Parameters:
- Yields:
loop (tuple[int]) – A set of nodes that form a loop.
- resistance_centrality(rescale=True)[source]¶
Compute the centrality in terms of the total resistance distance to all other nodes.
- to_networkx(as_tree_leaves=None)[source]¶
Convert to a networkx Graph, with hyperedges represented as nodes.
- Parameters:
as_tree_leaves (callable, optional) – If supplied this function is used to convert the nodes to ‘tree leaf’ form, i.e. map node
ito single element subgraphs, to match the nodes in aContractionTree.
- cotengra.hypergraph.get_hypergraph(inputs, output=None, size_dict=None, accel=False)[source]¶
Single entry-point for creating a, possibly accelerated, HyperGraph.