🧮 Linear Algebra¶
Submodules¶
hypergraphx.linalg.linalg module¶
- hypergraphx.linalg.linalg.adjacency_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix of the hypergraph. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the number of hyperedges where both i and j are contained.
- Parameters:
hypergraph (the hypergraph.)
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the adjacency matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The adjacency matrix of the hypergraph.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.linalg.adjacency_matrix_by_order(hypergraph, order, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix of the hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the number of hyperedges of a given order where both i and j are contained.
- Parameters:
hypergraph (the hypergraph.)
order (the order.)
- Return type:
The adjacency matrix of the hypergraph for a given order and the dictionary of node mappings.
- hypergraphx.linalg.linalg.adjacency_tensor(hypergraph)[source]¶
Compute the tensor of a uniform hypergraph. For a hypergraph of order m, create a tensor of order m+1 where i,j,k… is 1 if the hyperedge (i,j,k…) is in the hypergraph and 0 otherwise
- Parameters:
hypergraph (Hypergraph) – The uniform hypergraph on which the tensor is computed.
- Returns:
T – The tensor of the hypergraph.
- Return type:
np.ndarray
- hypergraphx.linalg.linalg.annealed_adjacency_matrices_all_orders(temporal_hypergraph)[source]¶
Compute the annealed adjacency matrices of the temporal hypergraph for all orders. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix of order d counts the average number of hyperedges of order d where both i and j are contained over time.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
- Returns:
annealed_adjacency_matrices_order – The annealed adjacency matrix for all orders, i.e., {order : annealed adjacency matrix}.
- Return type:
dict[int, sparse.csc_array]
- hypergraphx.linalg.linalg.annealed_adjacency_matrix(temporal_hypergraph, return_mapping=False, format='csr')[source]¶
Compute the annealed adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the average number of hyperedges of a given order where both i and j are contained over time.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
matrix (sparse.csc_array) – The annealed adjacency matrix for a given order.
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- hypergraphx.linalg.linalg.binary_incidence_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Produce the binary incidence matrix representing a hypergraph. For any node i and hyperedge e, the entry (i, e) of the binary incidence matrix is 1 if the node belongs to the hyperedge, 0 otherwise.
- Parameters:
hypergraph (instance of the class Hypergraph.) – Every hyperedge is represented as either a tuple or list of nodes.
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the incidence matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The binary adjacency matrix representing the hyperedges.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.linalg.compute_multiorder_laplacian(hypergraph, sigmas, order_weighted=False, degree_weighted=True)[source]¶
- hypergraphx.linalg.linalg.degree_matrix(hypergraph, order, mapping=None, return_mapping=False, format='csr')[source]¶
Compute the degree matrix of the hypergraph for a given order.
The returned matrix is node-indexed: entry (i, i) equals the degree of node mapping[i] considering only hyperedges of the given order.
- hypergraphx.linalg.linalg.dual_random_walk_adjacency(hypergraph, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix matrix associated to the dual hypergraph random walk. For any two hyperedges e, f in the hypergraph, the entry (e, f) of the random walk adjacency has value 1 if their intersection is non-null, else 0. This is the matrix of adjacency between hyperedges in the dual hypergraph.
- Parameters:
hypergraph (the hypergraph.)
return_mapping – If True, return a mapping from edge indices in the matrix (0..E-1) back to the corresponding hyperedge keys in the input hypergraph.
format – Sparse format of the returned matrix (“csr” by default).
- Returns:
The random walk adjacency matrix of the hypergraph.
If return_mapping is True, return the dictionary of edge mappings.
- hypergraphx.linalg.linalg.hye_list_to_binary_incidence(hye_list, shape=None)[source]¶
Convert a list of hyperedges into a scipy sparse COO array. The hyperedges need to be list of integers, representing nodes, starting from 0. If no shape is provided, this is inferred from the hyperedge list as (N, E). N is the number of nodes, given by the maximum integer observed in the hyperedge list plus one (since the node index starts from 0). E is the number of hyperedges in the list. If not None, the shape can only specify a tuple (N’, E’) where N’ is greater or equal than the N inferred from the hyperedge list, and E’ is greater or equal than the number of hyperedges in the list.
- Parameters:
hye_list (the list of hyperedges.) – Every hyperedge is represented as a tuple of integer nodes.
shape (the shape of the adjacency matrix, passed to the array constructor.) – If None, it is inferred.
- Return type:
The binary adjacency matrix representing the hyperedges.
- hypergraphx.linalg.linalg.incidence_matrices_all_orders(hypergraph, shape=None, keep_isolated_nodes=False, return_mapping=False, format='csr')[source]¶
Produce the incidence matrices of a hypergraph at all orders. For any node i and hyperedge e, the entry (i, e) of the incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph – The hypergraph.
shape – The shape of the incidence matrix.
keep_isolated_nodes – If True, keep the isolated nodes in the incidence matrix.
return_mapping – If True, return the dictionary mapping the node indices in the matrix to the hypergraph nodes.
- Return type:
Dictionary mapping each order to its incidence matrix.
- hypergraphx.linalg.linalg.incidence_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Produce the incidence matrix representing a hypergraph. For any node i and hyperedge e, the entry (i, e) of the binary incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph (instance of the class Hypergraph.) – Every hyperedge is represented as either a tuple or list of nodes.
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the incidence matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The binary adjacency matrix representing the hyperedges.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.linalg.incidence_matrix_by_order(hypergraph, order, shape=None, keep_isolated_nodes=False, return_mapping=False, format='csr')[source]¶
Produce the incidence matrix of a hypergraph at a given order. For any node i and hyperedge e, the entry (i, e) of the incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph – The hypergraph.
order – The order of the hyperedges to consider.
shape – The shape of the incidence matrix.
keep_isolated_nodes – If True, keep the isolated nodes in the incidence matrix.
return_mapping – If True, return the dictionary mapping the node indices in the matrix to the hypergraph nodes.
- Returns:
The incidence matrix.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.linalg.laplacian_matrices_all_orders(hypergraph, weighted=False, shape=None, return_mapping=False, format='csr')[source]¶
- hypergraphx.linalg.linalg.laplacian_matrix_by_order(hypergraph, order, weighted=False, shape=None, return_mapping=False, format='csr')[source]¶
- hypergraphx.linalg.linalg.temporal_adjacency_matrices_all_orders(temporal_hypergraph, max_order=None, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrices of the temporal hypergraph for all orders. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix of order d at time t counts the number of hyperedges of order d, existing at time t, where both i and j are contained.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
max_order (int | None, optional) – The maximum order of the hypergraph. If not specified will be automatically selected
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
temporal_adjacencies (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {order : {time : adjacency matrix}}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.
- hypergraphx.linalg.linalg.temporal_adjacency_matrix(temporal_hypergraph, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix at time t counts the number of hyperedges of a given order, existing at time t, where both i and j are contained. :param temporal_hypergraph: :type temporal_hypergraph: TemporalHypergraph. :param return_mapping: Return the dictionary mapping the new node indices to the Temporal Hypergraph :type return_mapping: bool,optional
- Returns:
temporal_adjacency_matrixes (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {time : adjacency matrix}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.
- hypergraphx.linalg.linalg.temporal_adjacency_matrix_by_order(temporal_hypergraph, order, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix at time t counts the number of hyperedges of a given order, existing at time t, where both i and j are contained.
- Parameters:
temporal_hypergraph (TemporalHypergraph.)
order (int) – The specific order to evaluate
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
temporal_adjacency_matrixes (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {time : adjacency matrix}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.
Module contents¶
- hypergraphx.linalg.adjacency_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix of the hypergraph. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the number of hyperedges where both i and j are contained.
- Parameters:
hypergraph (the hypergraph.)
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the adjacency matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The adjacency matrix of the hypergraph.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.adjacency_matrix_by_order(hypergraph, order, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix of the hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the number of hyperedges of a given order where both i and j are contained.
- Parameters:
hypergraph (the hypergraph.)
order (the order.)
- Return type:
The adjacency matrix of the hypergraph for a given order and the dictionary of node mappings.
- hypergraphx.linalg.adjacency_tensor(hypergraph)[source]¶
Compute the tensor of a uniform hypergraph. For a hypergraph of order m, create a tensor of order m+1 where i,j,k… is 1 if the hyperedge (i,j,k…) is in the hypergraph and 0 otherwise
- Parameters:
hypergraph (Hypergraph) – The uniform hypergraph on which the tensor is computed.
- Returns:
T – The tensor of the hypergraph.
- Return type:
np.ndarray
- hypergraphx.linalg.annealed_adjacency_matrices_all_orders(temporal_hypergraph)[source]¶
Compute the annealed adjacency matrices of the temporal hypergraph for all orders. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix of order d counts the average number of hyperedges of order d where both i and j are contained over time.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
- Returns:
annealed_adjacency_matrices_order – The annealed adjacency matrix for all orders, i.e., {order : annealed adjacency matrix}.
- Return type:
dict[int, sparse.csc_array]
- hypergraphx.linalg.annealed_adjacency_matrix(temporal_hypergraph, return_mapping=False, format='csr')[source]¶
Compute the annealed adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix counts the average number of hyperedges of a given order where both i and j are contained over time.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
matrix (sparse.csc_array) – The annealed adjacency matrix for a given order.
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- hypergraphx.linalg.binary_incidence_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Produce the binary incidence matrix representing a hypergraph. For any node i and hyperedge e, the entry (i, e) of the binary incidence matrix is 1 if the node belongs to the hyperedge, 0 otherwise.
- Parameters:
hypergraph (instance of the class Hypergraph.) – Every hyperedge is represented as either a tuple or list of nodes.
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the incidence matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The binary adjacency matrix representing the hyperedges.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.compute_multiorder_laplacian(hypergraph, sigmas, order_weighted=False, degree_weighted=True)[source]¶
- hypergraphx.linalg.degree_matrix(hypergraph, order, mapping=None, return_mapping=False, format='csr')[source]¶
Compute the degree matrix of the hypergraph for a given order.
The returned matrix is node-indexed: entry (i, i) equals the degree of node mapping[i] considering only hyperedges of the given order.
- hypergraphx.linalg.dual_random_walk_adjacency(hypergraph, return_mapping=False, format='csr')[source]¶
Compute the adjacency matrix matrix associated to the dual hypergraph random walk. For any two hyperedges e, f in the hypergraph, the entry (e, f) of the random walk adjacency has value 1 if their intersection is non-null, else 0. This is the matrix of adjacency between hyperedges in the dual hypergraph.
- Parameters:
hypergraph (the hypergraph.)
return_mapping – If True, return a mapping from edge indices in the matrix (0..E-1) back to the corresponding hyperedge keys in the input hypergraph.
format – Sparse format of the returned matrix (“csr” by default).
- Returns:
The random walk adjacency matrix of the hypergraph.
If return_mapping is True, return the dictionary of edge mappings.
- hypergraphx.linalg.hye_list_to_binary_incidence(hye_list, shape=None)[source]¶
Convert a list of hyperedges into a scipy sparse COO array. The hyperedges need to be list of integers, representing nodes, starting from 0. If no shape is provided, this is inferred from the hyperedge list as (N, E). N is the number of nodes, given by the maximum integer observed in the hyperedge list plus one (since the node index starts from 0). E is the number of hyperedges in the list. If not None, the shape can only specify a tuple (N’, E’) where N’ is greater or equal than the N inferred from the hyperedge list, and E’ is greater or equal than the number of hyperedges in the list.
- Parameters:
hye_list (the list of hyperedges.) – Every hyperedge is represented as a tuple of integer nodes.
shape (the shape of the adjacency matrix, passed to the array constructor.) – If None, it is inferred.
- Return type:
The binary adjacency matrix representing the hyperedges.
- hypergraphx.linalg.incidence_matrices_all_orders(hypergraph, shape=None, keep_isolated_nodes=False, return_mapping=False, format='csr')[source]¶
Produce the incidence matrices of a hypergraph at all orders. For any node i and hyperedge e, the entry (i, e) of the incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph – The hypergraph.
shape – The shape of the incidence matrix.
keep_isolated_nodes – If True, keep the isolated nodes in the incidence matrix.
return_mapping – If True, return the dictionary mapping the node indices in the matrix to the hypergraph nodes.
- Return type:
Dictionary mapping each order to its incidence matrix.
- hypergraphx.linalg.incidence_matrix(hypergraph, return_mapping=False, format='csr')[source]¶
Produce the incidence matrix representing a hypergraph. For any node i and hyperedge e, the entry (i, e) of the binary incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph (instance of the class Hypergraph.) – Every hyperedge is represented as either a tuple or list of nodes.
return_mapping (return the dictionary mapping the new node indices to the hypergraph) – nodes. The node indices in the incidence matrix vary from 0 to N-1, where N is the total number of distinct nodes.
- Returns:
The binary adjacency matrix representing the hyperedges.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.incidence_matrix_by_order(hypergraph, order, shape=None, keep_isolated_nodes=False, return_mapping=False, format='csr')[source]¶
Produce the incidence matrix of a hypergraph at a given order. For any node i and hyperedge e, the entry (i, e) of the incidence matrix is the weight of the hyperedge if the node belongs to it, 0 otherwise.
- Parameters:
hypergraph – The hypergraph.
order – The order of the hyperedges to consider.
shape – The shape of the incidence matrix.
keep_isolated_nodes – If True, keep the isolated nodes in the incidence matrix.
return_mapping – If True, return the dictionary mapping the node indices in the matrix to the hypergraph nodes.
- Returns:
The incidence matrix.
If return_mapping is True, return the dictionary of node mappings.
- hypergraphx.linalg.laplacian_matrices_all_orders(hypergraph, weighted=False, shape=None, return_mapping=False, format='csr')[source]¶
- hypergraphx.linalg.laplacian_matrix_by_order(hypergraph, order, weighted=False, shape=None, return_mapping=False, format='csr')[source]¶
- hypergraphx.linalg.temporal_adjacency_matrices_all_orders(temporal_hypergraph, max_order=None, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrices of the temporal hypergraph for all orders. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix of order d at time t counts the number of hyperedges of order d, existing at time t, where both i and j are contained.
- Parameters:
temporal_hypergraph (TemporalHypergraph)
max_order (int | None, optional) – The maximum order of the hypergraph. If not specified will be automatically selected
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
temporal_adjacencies (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {order : {time : adjacency matrix}}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.
- hypergraphx.linalg.temporal_adjacency_matrix(temporal_hypergraph, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix at time t counts the number of hyperedges of a given order, existing at time t, where both i and j are contained. :param temporal_hypergraph: :type temporal_hypergraph: TemporalHypergraph. :param return_mapping: Return the dictionary mapping the new node indices to the Temporal Hypergraph :type return_mapping: bool,optional
- Returns:
temporal_adjacency_matrixes (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {time : adjacency matrix}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.
- hypergraphx.linalg.temporal_adjacency_matrix_by_order(temporal_hypergraph, order, return_mapping=False, format='csr')[source]¶
Compute the temporal adjacency matrix of the temporal hypergraph by order. For any two nodes i, j in the hypergraph, the entry (i, j) of the adjacency matrix at time t counts the number of hyperedges of a given order, existing at time t, where both i and j are contained.
- Parameters:
temporal_hypergraph (TemporalHypergraph.)
order (int) – The specific order to evaluate
return_mapping (bool,optional) – Return the dictionary mapping the new node indices to the Temporal Hypergraph
- Returns:
temporal_adjacency_matrixes (Dict[int, sparse.csc_array]) – A dictionary encoding the temporal adjacency matrixes, i.e., {time : adjacency matrix}
mapping (Dict[int, Dict[int,int]]) – The dictionary of node mappings for each adjacency matrix.