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:
inputs (sequence of list[str] or dict[int, list[str]]) – The nodes. If given as a dict, the keys will be taken as the node enumeration rather than
range(len(inputs))
.output (str, optional) – Output indices.
size_dict (dict[str, int], optional) – Size of each index.
- nodes¶
Mapping of node to the list of edges incident to it.
- Type:
dict[int, list[str]]
- edges¶
Mapping of hyper edges to list of nodes it is incident to.
- Type:
dict[str, list[int]]
- num_nodes¶
The number of nodes.
- Type:
int
- num_edges¶
The number of hyper-edges.
- Type:
int
- __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
i
andj
- 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
i
andj
were 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
region
to 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:
p (float, optional) – Once any node has had
H.num_nodes**p
visitors terminate. Set greater than 1.0 for no limit (slower).mu (float, optional) – Let the visitor score decay with this power. The higher this is, the more local connectivity is favored.
- Returns:
scores – The simple hypergraph closenesses - higher being more central.
- Return type:
dict[int, float]
- 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
r
this will create a smooth gradient from one of the hypergraph to the other.closeness_opts – Supplied to
HyperGraph.simple_closeness
as the starting point.
- Return type:
dict[int, float]
- compute_loops(start=None, max_loop_length=None)[source]¶
Generate all loops up to a certain length in this hypergraph.
- Parameters:
start (sequence of int, optional) – Only generate loops including these nodes, defaults to all.
max_loop_length (None or int, optional) – The maximum loop length to search for. If
None
, then this is set automatically by the length of the first loop found.
- 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.
- cotengra.hypergraph.get_hypergraph(inputs, output=None, size_dict=None, accel=False)[source]¶
Single entry-point for creating a, possibly accelerated, HyperGraph.