Core Modules

The core modules provide the fundamental data structures and operations for hypernetwork manipulation.

hiper.core.hypernetwork

hypernetwork.py

High-performance Hypernetwork using dict-of-sets representation.

class hiper.core.hypernetwork.Hypernetwork[source]

Bases: object

Hypernetwork implemented with two dicts: - nodes_map: node_id -> set of edge_ids - edges_map: edge_id -> set of node_ids

All operations are optimized to O(1) amortized where possible.

__init__()[source]
lightweight_copy()[source]

Create a lightweight copy of the hypernetwork.

Return type:

Hypernetwork

Returns:

A new Hypernetwork instance with copied structure

add_node(node_id)[source]

Add a node if not present.

Return type:

None

remove_node(node_id)[source]

Remove a node and its incidences.

Return type:

None

add_hyperedge(edge_id, members)[source]

Add a hyperedge linking given node IDs.

Return type:

None

add_node_to_hyperedge(edge_id, node_id)[source]

Add a node to an existing hyperedge.

Return type:

None

remove_node_from_hyperedge(edge_id, node_id)[source]

Remove a node from a given hyperedge.

Return type:

None

remove_hyperedge(edge_id)[source]

Remove a hyperedge and its incidences (nodes remain).

Return type:

None

get_nodes(edge_id)[source]

List node IDs in a given hyperedge.

Return type:

List[int]

get_hyperedges(node_id)[source]

List hyperedge IDs containing a given node.

Return type:

List[int]

get_neighbors(node_id)[source]

List neighbors of a given node.

Return type:

List[int]

degree(node_id)[source]

Return degree (number of neighbors) of a node.

Return type:

int

hyperdegree(node_id)[source]

Return hyperdegree (number of hyperedges) of a node.

Return type:

int

order()[source]

Return number of nodes.

Return type:

int

size()[source]

Return number of hyperedges.

Return type:

int

avg_deg()[source]

Return average node degree.

Return type:

float

avg_hyperdegree()[source]

Return average hyperdegree of nodes.

Return type:

float

hyperedge_size(edge_id)[source]

Return size (number of nodes) of a hyperedge.

Return type:

int

avg_hyperedge_size()[source]

Return average hyperedge size.

Return type:

float

line_graph()[source]

Return line graph (edge_ids, intersecting hyperedges).

Return type:

Tuple[List[int], List[Tuple[int, int]]]

print_info()[source]

Print basic hypernetwork metrics.

Return type:

None

property nodes: Dict[int, Set[int]]

Expose mapping of node IDs to hyperedge sets.

property edges: Dict[int, Set[int]]

Expose mapping of hyperedge IDs to node sets.

hiper.core.node

node.py

Defines the Node class for hypernetworks.

class hiper.core.node.Node(node_id)[source]

Bases: object

Represents a vertex, holding head pointer to incidence list.

__init__(node_id)[source]
node_id
first_incidence: Optional[Incidence]

hiper.core.hyperedge

hyperedge.py

Defines the Hyperedge class for hypernetworks.

class hiper.core.hyperedge.Hyperedge(edge_id)[source]

Bases: object

Represents a hyperedge, holding head pointer to incidence list.

__init__(edge_id)[source]
edge_id
first_incidence: Optional[Incidence]

hiper.core.incidence

incidence.py

Defines the Incidence class linking Node and Hyperedge.

class hiper.core.incidence.Incidence(node, edge)[source]

Bases: object

Links a Node to a Hyperedge in two doubly-linked lists.

__init__(node, edge)[source]
node
edge
prev_in_node: Optional[Incidence]
next_in_node: Optional[Incidence]
prev_in_edge: Optional[Incidence]
next_in_edge: Optional[Incidence]