easygraph.classes.hypergraph module#
- class easygraph.classes.hypergraph.Hypergraph(num_v: int, v_property: List[Dict] | None = None, e_list: List[int] | List[List[int]] | None = None, e_weight: float | List[float] | None = None, e_property: List[Dict] | None = None, merge_op: str = 'mean', device: device = device(type='cpu'))[source]#
Bases:
BaseHypergraph
The
Hypergraph
class is developed for hypergraph structures. Please notice that node id in hypergraph is in [0, num_v)- Parameters:
num_v ((int) The number of vertices in the hypergraph) –
e_list ((Union[List[int], List[List[int]]], optional) A list of hyperedges describes how the vertices point to the hyperedges. Defaults to
None
) –v_property (Optional[List[Dict]], A list of node properties. Defaults to
None
) –e_property (Optional[List[Dict]], A list of hyperedges properties. Defaults to
None
) –e_weight ((Union[float, List[float]], optional) A list of weights for hyperedges. If set to None, the value
1
is used for all hyperedges. Defaults to None) –merge_op ((str) The operation to merge those conflicting hyperedges in the same hyperedge group, which can be
'mean'
,'sum'
or'max'
. Defaults to'mean'
) –device ((torch.device, optional) The device to store the hypergraph. Defaults to torch.device('cpu')) –
- Attributes:
D_e
Return the hyperedge degree matrix \(\mathbf{D}_e\) with
torch.sparse_coo_tensor
format.D_e_neg_1
Return the hyperedge degree matrix \(\mathbf{D}_e^{-1}\) with
torch.sparse_coo_tensor
format.D_v
Return the vertex degree matrix \(\mathbf{D}_v\) with
torch.sparse_coo_tensor
format.D_v_neg_1
Return the vertex degree matrix \(\mathbf{D}_v^{-1}\) with
torch.sparse_coo_tensor
format.D_v_neg_1_2
Return the vertex degree matrix \(\mathbf{D}_v^{-\frac{1}{2}}\) with
torch.sparse_coo_tensor
format.H
Return the hypergraph incidence matrix \(\mathbf{H}\) with
torch.Tensor
format.H_T
Return the transpose of the hypergraph incidence matrix \(\mathbf{H}^\top\) with
torch.Tensor
format.H_e2v
Return the hypergraph incidence matrix with
sparse matrix
format.H_v2e
Return the hypergraph incidence matrix with
sparse matrix
format.L_HGNN
Return the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\) of the hypergraph with
torch.sparse_coo_tensor
format.L_rw
Return the random walk Laplacian matrix \(\mathcal{L}_{rw}\) of the hypergraph with
torch.sparse_coo_tensor
format.L_sym
Return the symmetric Laplacian matrix \(\mathcal{L}_{sym}\) of the hypergraph with
torch.sparse_coo_tensor
format.R_e2v
Return the weight matrix of connections (hyperedges point to vertices) with
sparse matrix
format.R_v2e
Return the weight matrix of connections (vertices point to hyperedges) with
sparse matrix
format.W_e
Return the weight matrix \(\mathbf{W}_e\) of hyperedges with
torch.Tensor
format.W_v
Return the vertex weight matrix of the hypergraph.
deg_e
Return the degree list of each hyperedge.
deg_v
Return the degree list of each vertex.
- degree_node
e
Return all hyperedges and weights in the hypergraph.
e2v_dst
Return the destination vertex index vector \(\overrightarrow{e2v}_{dst}\) of the connections (hyperedges point to vertices) in the hypergraph.
e2v_src
Return the source hyperedge index vector \(\overrightarrow{e2v}_{src}\) of the connections (hyperedges point to vertices) in the hypergraph.
e2v_weight
Return the weight vector \(\overrightarrow{e2v}_{weight}\) of the connections (hyperedges point to vertices) in the hypergraph.
- e_property
- e_set
group_names
Return the names of all hyperedge groups in the hypergraph.
- incidence_matrix
- ndata
num_e
Return the number of hyperedges in the hypergraph.
num_groups
Return the number of hyperedge groups in the hypergraph.
num_v
Return the number of vertices in the hypergraph.
state_dict
Get the state dict of the hypergraph.
v
Return the list of vertices.
v2e_dst
Return the destination hyperedge index vector \(\overrightarrow{v2e}_{dst}\) of the connections (vertices point to hyperedges) in the hypergraph.
v2e_src
Return the source vertex index vector \(\overrightarrow{v2e}_{src}\) of the connections (vertices point to hyperedges) in the hypergraph.
v2e_weight
Return the weight vector \(\overrightarrow{v2e}_{weight}\) of the connections (vertices point to hyperedges) in the hypergraph.
- v_property
v_weight
Return the vertex weights of the hypergraph.
vars_for_DL
Return a name list of available variables for deep learning in the hypergraph including
Methods
D_e_neg_1_of_group
(group_name)Return the hyperedge degree matrix \(\mathbf{D}_e^{-1}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.D_e_of_group
(group_name)Return the hyperedge degree matrix \(\mathbf{D}_e\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.D_v_neg_1_2_of_group
(group_name)Return the vertex degree matrix \(\mathbf{D}_v^{-\frac{1}{2}}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.D_v_neg_1_of_group
(group_name)Return the vertex degree matrix \(\mathbf{D}_v^{-1}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.D_v_of_group
(group_name)Return the vertex degree matrix \(\mathbf{D}_v\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.H_T_of_group
(group_name)Return the transpose of the hypergraph incidence matrix \(\mathbf{H}^\top\) of the specified hyperedge group with
torch.Tensor
format.H_e2v_of_group
(group_name)Return the hypergraph incidence matrix with
sparse matrix
format in the specified hyperedge group.H_of_group
(group_name)Return the hypergraph incidence matrix \(\mathbf{H}\) of the specified hyperedge group with
torch.Tensor
format.H_v2e_of_group
(group_name)Return the hypergraph incidence matrix with
sparse matrix
format in the specified hyperedge group.L_HGNN_of_group
(group_name)Return the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.L_rw_of_group
(group_name)Return the random walk Laplacian matrix \(\mathcal{L}_{rw}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.L_sym_of_group
(group_name)Return the symmetric Laplacian matrix \(\mathcal{L}_{sym}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.N_e
(v_idx)Return the neighbor hyperedges of the specified vertex with
torch.Tensor
format.N_e_of_group
(v_idx, group_name)Return the neighbor hyperedges of the specified vertex of the specified hyperedge group with
torch.Tensor
format.N_v
(e_idx)Return the neighbor vertices of the specified hyperedge with
torch.Tensor
format.N_v_of_group
(e_idx, group_name)Return the neighbor vertices of the specified hyperedge of the specified hyperedge group with
torch.Tensor
format.R_e2v_of_group
(group_name)Return the weight matrix of connections (hyperedges point to vertices) with
sparse matrix
format in the specified hyperedge group.R_v2e_of_group
(group_name)Return the weight matrix of connections (vertices point to hyperedges) with
sparse matrix
format in the specified hyperedge group.W_e_of_group
(group_name)Return the weight matrix \(\mathbf{W}_e\) of hyperedges of the specified hyperedge group with
torch.Tensor
format.add_hyperedges
(e_list[, e_weight, ...])Add hyperedges to the hypergraph.
add_hyperedges_from_feature_kNN
(feature, k)Add hyperedges from the feature matrix by k-NN.
add_hyperedges_from_graph
(graph[, group_name])Add hyperedges from edges in the graph.
add_hyperedges_from_graph_kHop
(graph, k[, ...])Add hyperedges from vertices and its k-Hop neighbors in the graph.
adjacency_matrix
([s, weight])The s-adjacency matrix for the dual hypergraph.
clear
()Clear all hyperedges and caches from the hypergraph.
clone
()Return a copy of the hypergraph.
deg_e_of_group
(group_name)Return the degree list of each hyperedge of the specified hyperedge group.
deg_v_of_group
(group_name)Return the degree list of each vertex of the specified hyperedge group.
alias of
dict
diameter
([s])Returns the length of the longest shortest s-walk between nodes in hypergraph
distance
(source[, target, s])- param source:
draw
([e_style, v_label, v_size, v_color, ...])Draw the hypergraph structure.
drop_hyperedges
(drop_rate[, ord])Randomly drop hyperedges from the hypergraph.
drop_hyperedges_of_group
(group_name, drop_rate)Randomly drop hyperedges from the specified hyperedge group.
e2v
(X[, aggr, e2v_weight, drop_rate])Message passing of
hyperedges to vertices
.e2v_aggregation
(X[, aggr, e2v_weight, drop_rate])Message aggregation step of
hyperedges to vertices
.e2v_aggregation_of_group
(group_name, X[, ...])Message aggregation step of
hyperedges to vertices
in specified hyperedge group.e2v_dst_of_group
(group_name)Return the destination vertex index vector \(\overrightarrow{e2v}_{dst}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
e2v_of_group
(group_name, X[, aggr, ...])Message passing of
hyperedges to vertices
in specified hyperedge group.e2v_src_of_group
(group_name)Return the source hyperedge index vector \(\overrightarrow{e2v}_{src}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
e2v_update
(X)Message update step of
hyperedges to vertices
.e2v_update_of_group
(group_name, X)Message update step of
hyperedges to vertices
in specified hyperedge group.e2v_weight_of_group
(group_name)Return the weight vector \(\overrightarrow{e2v}_{weight}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
e_of_group
(group_name)Return all hyperedges and weights of the specified hyperedge group.
edge_adjacency_matrix
([s, weight])The s-adjacency matrix for the dual hypergraph.
edge_diameter
([s])Returns the length of the longest shortest s-walk between edges in hypergraph
edge_distance
(source, target[, s])- param source:
from_feature_kNN
(features, k[, device])Construct the hypergraph from the feature matrix.
from_graph
(graph[, device])Construct the hypergraph from the graph.
from_graph_kHop
(graph, k[, only_kHop, device])Construct the hypergraph from the graph by k-Hop neighbors.
from_hypergraph_hypergcn
(hypergraph, feature)Construct a graph from a hypergraph with methods proposed in HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs paper .
from_state_dict
(state_dict)Load the hypergraph from the state dict.
get_clique_expansion
([s, weight])Get the linegraph of the hypergraph based on the clique expansion.
get_linegraph
([s, weight])Get the linegraph of the hypergraph based on the clique expansion.
The star expansion algorithm creates a graph G*(V*, E*) for every hypergraph G(V, E).
alias of
dict
Order of uniformity if the hypergraph is uniform, or False.
load
(file_path)Load the EasyGraph's hypergraph structure from a file.
nbr_e
(v_idx)Return the neighbor hyperedge list of the specified vertex.
nbr_e_of_group
(v_idx, group_name)Return the neighbor hyperedge list of the specified vertex of the specified hyperedge group.
nbr_v
(e_idx)Return the neighbor vertex list of the specified hyperedge.
nbr_v_of_group
(e_idx, group_name)Return the neighbor vertex list of the specified hyperedge of the specified hyperedge group.
num_e_of_group
(group_name)Return the number of hyperedges of the specified hyperedge group.
remove_group
(group_name)Remove the specified hyperedge group from the hypergraph.
remove_hyperedges
(e_list[, group_name])Remove the specified hyperedges from the hypergraph.
s_connected_components
([s, edges, ...])Returns a generator for the s-edge-connected components or the s-node-connected components of the hypergraph.
save
(file_path)Save the EasyGraph's hypergraph structure a file.
smoothing
(X, L, lamb)Spectral-based smoothing.
smoothing_with_HGNN
(X[, drop_rate])Return the smoothed feature matrix with the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
smoothing_with_HGNN_of_group
(group_name, X)Return the smoothed feature matrix with the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
smoothing_with_HWNN_approx
(X, par, W_d, K1, ...)Return the smoothed feature matrix with the approximated HWNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
smoothing_with_HWNN_wavelet
(X, W_d, W)Return the smoothed feature matrix with original HWNN Laplacian matrix :
to
(device)Move the hypergraph to the specified device.
A function that returns the unique edge sizes.
v2e
(X[, aggr, v2e_weight, e_weight, drop_rate])Message passing of
vertices to hyperedges
.v2e_aggregation
(X[, aggr, v2e_weight, drop_rate])Message aggregation step of
vertices to hyperedges
.v2e_aggregation_of_group
(group_name, X[, ...])Message aggregation step of
vertices to hyperedges
in specified hyperedge group.v2e_dst_of_group
(group_name)Return the destination hyperedge index vector \(\overrightarrow{v2e}_{dst}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
v2e_of_group
(group_name, X[, aggr, ...])Message passing of
vertices to hyperedges
in specified hyperedge group.v2e_src_of_group
(group_name)Return the source vertex index vector \(\overrightarrow{v2e}_{src}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
v2e_update
(X[, e_weight])Message update step of
vertices to hyperedges
.v2e_update_of_group
(group_name, X[, e_weight])Message update step of
vertices to hyperedges
in specified hyperedge group.v2e_weight_of_group
(group_name)Return the weight vector \(\overrightarrow{v2e}_{weight}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
v2v
(X[, aggr, drop_rate, v2e_aggr, ...])Message passing of
vertices to vertices
.v2v_of_group
(group_name, X[, aggr, ...])Message passing of
vertices to vertices
in specified hyperedge group.cluster_coefficient
isOutRange
neighbor_of_node
- property D_e: Tensor#
Return the hyperedge degree matrix \(\mathbf{D}_e\) with
torch.sparse_coo_tensor
format.
- property D_e_neg_1: Tensor#
Return the hyperedge degree matrix \(\mathbf{D}_e^{-1}\) with
torch.sparse_coo_tensor
format.
- D_e_neg_1_of_group(group_name: str) Tensor [source]#
Return the hyperedge degree matrix \(\mathbf{D}_e^{-1}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- D_e_of_group(group_name: str) Tensor [source]#
Return the hyperedge degree matrix \(\mathbf{D}_e\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property D_v: Tensor#
Return the vertex degree matrix \(\mathbf{D}_v\) with
torch.sparse_coo_tensor
format.
- property D_v_neg_1: Tensor#
Return the vertex degree matrix \(\mathbf{D}_v^{-1}\) with
torch.sparse_coo_tensor
format.
- property D_v_neg_1_2: Tensor#
Return the vertex degree matrix \(\mathbf{D}_v^{-\frac{1}{2}}\) with
torch.sparse_coo_tensor
format.
- D_v_neg_1_2_of_group(group_name: str) Tensor [source]#
Return the vertex degree matrix \(\mathbf{D}_v^{-\frac{1}{2}}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- D_v_neg_1_of_group(group_name: str) Tensor [source]#
Return the vertex degree matrix \(\mathbf{D}_v^{-1}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- D_v_of_group(group_name: str) Tensor [source]#
Return the vertex degree matrix \(\mathbf{D}_v\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property H: Tensor#
Return the hypergraph incidence matrix \(\mathbf{H}\) with
torch.Tensor
format.
- property H_T: Tensor#
Return the transpose of the hypergraph incidence matrix \(\mathbf{H}^\top\) with
torch.Tensor
format.
- H_T_of_group(group_name: str) Tensor [source]#
Return the transpose of the hypergraph incidence matrix \(\mathbf{H}^\top\) of the specified hyperedge group with
torch.Tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- H_of_group(group_name: str) Tensor [source]#
Return the hypergraph incidence matrix \(\mathbf{H}\) of the specified hyperedge group with
torch.Tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property L_HGNN: Tensor#
Return the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\) of the hypergraph with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{HGNN} = \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}}\]
- L_HGNN_of_group(group_name: str) Tensor [source]#
Return the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{HGNN} = \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}}\]- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property L_rw: Tensor#
Return the random walk Laplacian matrix \(\mathcal{L}_{rw}\) of the hypergraph with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{rw} = \mathbf{I} - \mathbf{D}_v^{-1} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top\]
- L_rw_of_group(group_name: str) Tensor [source]#
Return the random walk Laplacian matrix \(\mathcal{L}_{rw}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{rw} = \mathbf{I} - \mathbf{D}_v^{-1} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top\]- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property L_sym: Tensor#
Return the symmetric Laplacian matrix \(\mathcal{L}_{sym}\) of the hypergraph with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{sym} = \mathbf{I} - \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}}\]
- L_sym_of_group(group_name: str) Tensor [source]#
Return the symmetric Laplacian matrix \(\mathcal{L}_{sym}\) of the specified hyperedge group with
torch.sparse_coo_tensor
format.\[\mathcal{L}_{sym} = \mathbf{I} - \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}}\]- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- N_e(v_idx: int) Tensor [source]#
Return the neighbor hyperedges of the specified vertex with
torch.Tensor
format.Note
The
v_idx
must be in the range of [0,num_v
).- Parameters:
v_idx (
int
) – The index of the vertex.
- N_e_of_group(v_idx: int, group_name: str) Tensor [source]#
Return the neighbor hyperedges of the specified vertex of the specified hyperedge group with
torch.Tensor
format.Note
The
v_idx
must be in the range of [0,num_v
).- Parameters:
v_idx (
int
) – The index of the vertex.group_name (
str
) – The name of the specified hyperedge group.
- N_v(e_idx: int) Tensor [source]#
Return the neighbor vertices of the specified hyperedge with
torch.Tensor
format.Note
The
e_idx
must be in the range of [0,num_e
).- Parameters:
e_idx (
int
) – The index of the hyperedge.
- N_v_of_group(e_idx: int, group_name: str) Tensor [source]#
Return the neighbor vertices of the specified hyperedge of the specified hyperedge group with
torch.Tensor
format.Note
The
e_idx
must be in the range of [0,num_e_of_group()
).- Parameters:
e_idx (
int
) – The index of the hyperedge.group_name (
str
) – The name of the specified hyperedge group.
- property W_e: Tensor#
Return the weight matrix \(\mathbf{W}_e\) of hyperedges with
torch.Tensor
format.
- W_e_of_group(group_name: str) Tensor [source]#
Return the weight matrix \(\mathbf{W}_e\) of hyperedges of the specified hyperedge group with
torch.Tensor
format.- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- add_hyperedges(e_list: List[int] | List[List[int]], e_weight: float | List[float] | None = None, e_property: Dict | List[Dict] | None = None, merge_op: str = 'sum', group_name: str = 'main')[source]#
Add hyperedges to the hypergraph. If the
group_name
is not specified, the hyperedges will be added to the defaultmain
hyperedge group.- Parameters:
e_list (
Union[List[int], List[List[int]]]
) – A list of hyperedges describes how the vertices point to the hyperedges.e_weight (
Union[float, List[float]]
, optional) – A list of weights for hyperedges. If set toNone
, the value1
is used for all hyperedges. Defaults toNone
.merge_op (
str
) – The merge operation for the conflicting hyperedges. The possible values are"mean"
,"sum"
, and"max"
. Defaults to"mean"
.group_name (
str
, optional) – The target hyperedge group to add these hyperedges. Defaults to themain
hyperedge group.
- add_hyperedges_from_feature_kNN(feature: Tensor, k: int, group_name: str = 'main')[source]#
Add hyperedges from the feature matrix by k-NN. Each hyperedge is constructed by the central vertex and its \(k\)-Nearest Neighbor vertices.
- Parameters:
features (
torch.Tensor
) – The feature matrix.k (
int
) – The number of nearest neighbors.group_name (
str
, optional) – The target hyperedge group to add these hyperedges. Defaults to themain
hyperedge group.
- add_hyperedges_from_graph(graph, group_name: str = 'main')[source]#
Add hyperedges from edges in the graph. Each edge in the graph is treated as a hyperedge.
- Parameters:
graph (
eg.Graph
) – The graph to join the hypergraph.group_name (
str
, optional) – The target hyperedge group to add these hyperedges. Defaults to themain
hyperedge group.
- add_hyperedges_from_graph_kHop(graph, k: int, only_kHop: bool = False, group_name: str = 'main')[source]#
Add hyperedges from vertices and its k-Hop neighbors in the graph. Each hyperedge in the hypergraph is constructed by the central vertex and its \(k\)-Hop neighbor vertices.
Note
If the graph have \(|\mathcal{V}|\) vertices, the constructed hypergraph will have \(|\mathcal{V}|\) vertices and equal to or less than \(|\mathcal{V}|\) hyperedges.
- Parameters:
graph (
eg.Graph
) – The graph to join the hypergraph.k (
int
) – The number of hop neighbors.only_kHop (
bool
) – If set toTrue
, only the central vertex and its \(k\)-th Hop neighbors are used to construct the hyperedges. By default, the constructed hyperedge will include the central vertex and its [ \(1\)-th, \(2\)-th, \(\cdots\), \(k\)-th ] Hop neighbors. Defaults toFalse
.group_name (
str
, optional) – The target hyperedge group to add these hyperedges. Defaults to themain
hyperedge group.
- adjacency_matrix(s=1, weight=False)[source]#
The s-adjacency matrix for the dual hypergraph.
- Parameters:
s (int, optional, default 1) –
- Returns:
adjacency_matrix
- Return type:
scipy.sparse.csr.csr_matrix
- clone() Hypergraph [source]#
Return a copy of the hypergraph.
- property deg_e: List[int]#
Return the degree list of each hyperedge.
- deg_e_of_group(group_name: str) List[int] [source]#
Return the degree list of each hyperedge of the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property deg_v: List[int]#
Return the degree list of each vertex.
- deg_v_of_group(group_name: str) List[int] [source]#
Return the degree list of each vertex of the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- degree_data_dict#
alias of
dict
- property degree_node#
- diameter(s=1)[source]#
Returns the length of the longest shortest s-walk between nodes in hypergraph
- Parameters:
s (int, optional, default 1) –
- Returns:
diameter
- Return type:
int
- Raises:
EasyGraphError – If hypergraph is not s-edge-connected
Notes
Two nodes are s-adjacent if they share s edges. Two nodes v_start and v_end are s-walk connected if there is a sequence of nodes v_start, v_1, v_2, … v_n-1, v_end such that consecutive nodes are s-adjacent. If the graph is not connected, an error will be raised.
- distance(source, target=None, s=1)[source]#
- Parameters:
source (node in the hypergraph) –
target (node in the hypergraph) –
s (positive integer) – the number of edges
- Returns:
s-walk distance
- Return type:
int
Notes
The s-distance is the shortest s-walk length between the nodes. An s-walk between nodes is a sequence of nodes that pairwise share at least s edges. The length of the shortest s-walk is 1 less than the number of nodes in the path sequence.
Uses the EasyGraph’s Dijkstra method on the graph generated by the s-adjacency matrix.
- draw(e_style: str = 'circle', v_label: List[str] | None = None, v_size: float | list = 1.0, v_color: str | list = 'r', v_line_width: str | list = 1.0, e_color: str | list = 'gray', e_fill_color: str | list = 'whitesmoke', e_line_width: str | list = 1.0, font_size: float = 1.0, font_family: str = 'sans-serif', push_v_strength: float = 1.0, push_e_strength: float = 1.0, pull_e_strength: float = 1.0, pull_center_strength: float = 1.0)[source]#
Draw the hypergraph structure.
- Parameters:
e_style (
str
) – The style of hyperedges. The available styles are only'circle'
. Defaults to'circle'
.v_label (
list
) – The labels of vertices. Defaults toNone
.v_size (
float
orlist
) – The size of vertices. Defaults to1.0
.v_color (
str
orlist
) – The color of vertices. Defaults to'r'
.v_line_width (
float
orlist
) – The line width of vertices. Defaults to1.0
.e_color (
str
orlist
) –The color of hyperedges. Defaults to
'gray'
.e_fill_color (
str
orlist
) –The fill color of hyperedges. Defaults to
'whitesmoke'
.e_line_width (
float
orlist
) – The line width of hyperedges. Defaults to1.0
.font_size (
float
) – The font size of labels. Defaults to1.0
.font_family (
str
) – The font family of labels. Defaults to'sans-serif'
.push_v_strength (
float
) – The strength of pushing vertices. Defaults to1.0
.push_e_strength (
float
) – The strength of pushing hyperedges. Defaults to1.0
.pull_e_strength (
float
) – The strength of pulling hyperedges. Defaults to1.0
.pull_center_strength (
float
) – The strength of pulling vertices to the center. Defaults to1.0
.
- drop_hyperedges(drop_rate: float, ord='uniform')[source]#
Randomly drop hyperedges from the hypergraph. This function will return a new hypergraph with non-dropped hyperedges.
- Parameters:
drop_rate (
float
) – The drop rate of hyperedges.ord (
str
) – The order of dropping edges. Currently, only'uniform'
is supported. Defaults touniform
.
- drop_hyperedges_of_group(group_name: str, drop_rate: float, ord='uniform')[source]#
Randomly drop hyperedges from the specified hyperedge group. This function will return a new hypergraph with non-dropped hyperedges.
- Parameters:
group_name (
str
) – The name of the hyperedge group.drop_rate (
float
) – The drop rate of hyperedges.ord (
str
) – The order of dropping edges. Currently, only'uniform'
is supported. Defaults touniform
.
- property e: Tuple[List[List[int]], List[float]]#
Return all hyperedges and weights in the hypergraph.
- e2v(X: Tensor, aggr: str = 'mean', e2v_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message passing of
hyperedges to vertices
. The combination ofe2v_aggregation
ande2v_update
.- Parameters:
X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- e2v_aggregation(X: Tensor, aggr: str = 'mean', e2v_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggregation step of
hyperedges to vertices
.- Parameters:
X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- e2v_aggregation_of_group(group_name: str, X: Tensor, aggr: str = 'mean', e2v_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggregation step of
hyperedges to vertices
in specified hyperedge group.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- property e2v_dst: Tensor#
Return the destination vertex index vector \(\overrightarrow{e2v}_{dst}\) of the connections (hyperedges point to vertices) in the hypergraph.
- e2v_dst_of_group(group_name: str) Tensor [source]#
Return the destination vertex index vector \(\overrightarrow{e2v}_{dst}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- e2v_of_group(group_name: str, X: Tensor, aggr: str = 'mean', e2v_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message passing of
hyperedges to vertices
in specified hyperedge group. The combination ofe2v_aggregation_of_group
ande2v_update_of_group
.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- property e2v_src: Tensor#
Return the source hyperedge index vector \(\overrightarrow{e2v}_{src}\) of the connections (hyperedges point to vertices) in the hypergraph.
- e2v_src_of_group(group_name: str) Tensor [source]#
Return the source hyperedge index vector \(\overrightarrow{e2v}_{src}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- e2v_update(X: Tensor)[source]#
Message update step of
hyperedges to vertices
.- Parameters:
X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).
- e2v_update_of_group(group_name: str, X: Tensor)[source]#
Message update step of
hyperedges to vertices
in specified hyperedge group.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).
- property e2v_weight: Tensor#
Return the weight vector \(\overrightarrow{e2v}_{weight}\) of the connections (hyperedges point to vertices) in the hypergraph.
- e2v_weight_of_group(group_name: str) Tensor [source]#
Return the weight vector \(\overrightarrow{e2v}_{weight}\) of the connections (hyperedges point to vertices) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- e_of_group(group_name: str) Tuple[List[List[int]], List[float]] [source]#
Return all hyperedges and weights of the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property e_set#
- edge_adjacency_matrix(s=1, weight=False)[source]#
The s-adjacency matrix for the dual hypergraph.
- Parameters:
s (int, optional, default 1) –
- Returns:
adjacency_matrix
- Return type:
scipy.sparse.csr.csr_matrix
- edge_diameter(s=1)[source]#
Returns the length of the longest shortest s-walk between edges in hypergraph
- Parameters:
s (int, optional, default 1) –
- Returns:
edge_diameter
- Return type:
int
- Raises:
EasyGraphXError – If hypergraph is not s-edge-connected
Notes
Two edges are s-adjacent if they share s nodes. Two nodes e_start and e_end are s-walk connected if there is a sequence of edges e_start, e_1, e_2, … e_n-1, e_end such that consecutive edges are s-adjacent. If the graph is not connected, an error will be raised.
- edge_distance(source, target, s=1)[source]#
- Parameters:
source –
target –
s –
- Returns:
s- walk distance
- Return type:
the shortest s-walk edge distance
Notes
The s-distance is the shortest s-walk length between the edges. An s-walk between edges is a sequence of edges such that consecutive pairwise edges intersect in at least s nodes. The length of the shortest s-walk is 1 less than the number of edges in the path sequence.
- static from_feature_kNN(features: Tensor, k: int, device: device = device(type='cpu'))[source]#
Construct the hypergraph from the feature matrix. Each hyperedge in the hypergraph is constructed by the central vertex and its \(k-1\) neighbor vertices.
Note
The constructed hypergraph is a k-uniform hypergraph. If the feature matrix has the size \(N \times C\), the number of vertices and hyperedges of the constructed hypergraph are both \(N\).
- Parameters:
features (
torch.Tensor
) – The feature matrix.k (
int
) – The number of nearest neighbors.device (
torch.device
, optional) – The device to store the hypergraph. Defaults totorch.device('cpu')
.
- static from_graph(graph, device: device = device(type='cpu')) Hypergraph [source]#
Construct the hypergraph from the graph. Each edge in the graph is treated as a hyperedge in the constructed hypergraph.
Note
The constructed hypergraph is a 2-uniform hypergraph, and has the same number of vertices and edges/hyperedges as the graph.
- Parameters:
graph (
eg.Graph
) – The graph to construct the hypergraph.device (
torch.device
, optional) – The device to store the hypergraph. Defaults totorch.device('cpu')
.
- static from_graph_kHop(graph, k: int, only_kHop: bool = False, device: device = device(type='cpu')) Hypergraph [source]#
Construct the hypergraph from the graph by k-Hop neighbors. Each hyperedge in the hypergraph is constructed by the central vertex and its \(k\)-Hop neighbor vertices.
Note
If the graph have \(|\mathcal{V}|\) vertices, the constructed hypergraph will have \(|\mathcal{V}|\) vertices and equal to or less than \(|\mathcal{V}|\) hyperedges.
- Parameters:
graph (
eg.Graph
) – The graph to construct the hypergraph.k (
int
) – The number of hop neighbors.only_kHop (
bool
) – If set toTrue
, only the central vertex and its \(k\)-th Hop neighbors are used to construct the hyperedges. By default, the constructed hyperedge will include the central vertex and its [ \(1\)-th, \(2\)-th, \(\cdots\), \(k\)-th ] Hop neighbors. Defaults toFalse
.device (
torch.device
, optional) – The device to store the hypergraph. Defaults totorch.device('cpu')
.
- static from_hypergraph_hypergcn(hypergraph, feature, with_mediator=False, remove_selfloop=True)[source]#
Construct a graph from a hypergraph with methods proposed in HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs paper .
- Parameters:
hypergraph (
Hypergraph
) – The source hypergraph.feature (
torch.Tensor
) – The feature of the vertices.with_mediator (
str
) – Whether to use mediator to transform the hyperedges to edges in the graph. Defaults toFalse
.remove_selfloop (
bool
) – Whether to remove self-loop. Defaults toTrue
.device (
torch.device
) – The device to store the graph. Defaults totorch.device("cpu")
.
- static from_state_dict(state_dict: dict)[source]#
Load the hypergraph from the state dict.
- Parameters:
state_dict (
dict
) – The state dict to load the hypergraph.
- get_clique_expansion(s=1, weight=True)[source]#
Get the linegraph of the hypergraph based on the clique expansion. The hypergraph nodes will be the vertices of the line graph. Two vertices are connected if the nodes they correspond to share at least s incident hyper edges.
- Parameters:
s (Two vertices are connected if the nodes they correspond to share) –
edges. (at least s incident hyper) –
edge (If edges=True (default)then the edges will be the vertices of the line) –
the (graph. Two vertices are connected by an s-line-graph edge if) –
nodes. (corresponding hypergraph edges intersect in at least s hypergraph) –
edges=False (If) –
line (the hypergraph nodes will be the vertices of the) –
graph. –
weight –
- Returns:
Graph
- Return type:
easygraph.Graph, the clique expansion of the hypergraph.
- get_linegraph(s=1, weight=True)[source]#
Get the linegraph of the hypergraph based on the clique expansion. The edges will be the vertices of the line graph. Two vertices are connected by an s-line-graph edge if the corresponding hypergraph edges intersect in at least s hypergraph nodes.
- Parameters:
s (Two vertices are connected if the nodes they correspond to share) –
edges. (at least s incident hyper) –
edge (If edges=True (default)then the edges will be the vertices of the line) –
the (graph. Two vertices are connected by an s-line-graph edge if) –
nodes. (corresponding hypergraph edges intersect in at least s hypergraph) –
edges=False (If) –
line (the hypergraph nodes will be the vertices of the) –
graph. –
weight –
- Returns:
Graph
- Return type:
easygraph.Graph, the linegraph of the hypergraph.
- get_star_expansion()[source]#
The star expansion algorithm creates a graph G*(V*, E*) for every hypergraph G(V, E). The graph G*(V*, E*) introduces a node e∈E for each hyperedge in G(V, E), where V* = V ∪ E. Each node e is connected to all the nodes belonging to the hyperedge it originates from, i.e., E* = {(u, e): u∈e, e∈E}. It is worth noting that each hyperedge in the set E corresponds to a star-shaped structure in the graph G*(V*, E*), and G* is a bipartite graph. The star expansion redistributes the weights of hyperedges to their corresponding ordinary pairwise graph edges.
$ omega ^{*}(u,e)=frac{omega(e)}{delta(e)} $
References
Antelmi, Alessia, et al. “A survey on hypergraph representation learning.” ACM Computing Surveys 56.1 (2023): 1-38.
- gnn_data_dict_factory#
alias of
dict
- property group_names: List[str]#
Return the names of all hyperedge groups in the hypergraph.
- property incidence_matrix#
- is_uniform()[source]#
Order of uniformity if the hypergraph is uniform, or False.
A hypergraph is uniform if all its edges have the same order.
Returns d if the hypergraph is d-uniform, that is if all edges in the hypergraph (excluding singletons) have the same degree d. Returns False if not uniform.
- Returns:
d – If the hypergraph is d-uniform, return d, or False otherwise.
- Return type:
int or False
Examples
This function can be used as a boolean check:
>>> import easygraph as eg >>> H = eg.Hypergraph(v_num = 5, e_list = [(0, 1, 2), (1, 2, 3), (2, 3, 4)]) >>> H.is_uniform() 2
- static load(file_path: str | Path)[source]#
Load the EasyGraph’s hypergraph structure from a file.
- Parameters:
file_path (
Union[str, Path]
) – The file path to load the EasyGraph’s hypergraph structure.
- nbr_e(v_idx: int) List[int] [source]#
Return the neighbor hyperedge list of the specified vertex.
- Parameters:
v_idx (
int
) – The index of the vertex.
- nbr_e_of_group(v_idx: int, group_name: str) List[int] [source]#
Return the neighbor hyperedge list of the specified vertex of the specified hyperedge group.
- Parameters:
v_idx (
int
) – The index of the vertex.group_name (
str
) – The name of the specified hyperedge group.
- nbr_v(e_idx: int) List[int] [source]#
Return the neighbor vertex list of the specified hyperedge.
- Parameters:
e_idx (
int
) – The index of the hyperedge.
- nbr_v_of_group(e_idx: int, group_name: str) List[int] [source]#
Return the neighbor vertex list of the specified hyperedge of the specified hyperedge group.
- Parameters:
e_idx (
int
) – The index of the hyperedge.group_name (
str
) – The name of the specified hyperedge group.
- property ndata#
- property num_e: int#
Return the number of hyperedges in the hypergraph.
- num_e_of_group(group_name: str) int [source]#
Return the number of hyperedges of the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- property num_groups: int#
Return the number of hyperedge groups in the hypergraph.
- property num_v: int#
Return the number of vertices in the hypergraph.
- remove_group(group_name: str)[source]#
Remove the specified hyperedge group from the hypergraph.
- Parameters:
group_name (
str
) – The name of the hyperedge group to remove.
- remove_hyperedges(e_list: List[int] | List[List[int]], group_name: str | None = None)[source]#
Remove the specified hyperedges from the hypergraph.
- Parameters:
e_list (
Union[List[int], List[List[int]]]
) – A list of hyperedges describes how the vertices point to the hyperedges.group_name (
str
, optional) – Remove these hyperedges from the specified hyperedge group. If not specified, the function will remove those hyperedges from all hyperedge groups. Defaults to theNone
.
- s_connected_components(s=1, edges=True, return_singletons=False)[source]#
Returns a generator for the s-edge-connected components or the s-node-connected components of the hypergraph.
- Parameters:
s (int, optional, default 1) –
edges (boolean, optional, default = True) – If True will return edge components, if False will return node components
return_singletons (bool, optional, default = False) –
Notes
If edges=True, this method returns the s-edge-connected components as lists of lists of edge uids. An s-edge-component has the property that for any two edges e1 and e2 there is a sequence of edges starting with e1 and ending with e2 such that pairwise adjacent edges in the sequence intersect in at least s nodes. If s=1 these are the path components of the hypergraph.
If edges=False this method returns s-node-connected components. A list of sets of uids of the nodes which are s-walk connected. Two nodes v1 and v2 are s-walk-connected if there is a sequence of nodes starting with v1 and ending with v2 such that pairwise adjacent nodes in the sequence share s edges. If s=1 these are the path components of the hypergraph.
Example
>>> S = {'A':{1,2,3},'B':{2,3,4},'C':{5,6},'D':{6}} >>> H = Hypergraph(S)
>>> list(H.s_components(edges=True)) [{'C', 'D'}, {'A', 'B'}] >>> list(H.s_components(edges=False)) [{1, 2, 3, 4}, {5, 6}]
- Yields:
s_connected_components (iterator) – Iterator returns sets of uids of the edges (or nodes) in the s-edge(node) components of hypergraph.
- save(file_path: str | Path)[source]#
Save the EasyGraph’s hypergraph structure a file.
- Parameters:
file_path (
Union[str, Path]
) – The file path to store the EasyGraph’s hypergraph structure.
- smoothing(X: Tensor, L: Tensor, lamb: float) Tensor [source]#
Spectral-based smoothing.
\[X_{smoothed} = X + \lambda \mathcal{L} X\]- Parameters:
X (
torch.Tensor
) – The vertex feature matrix. Size \((|\mathcal{V}|, C)\).L (
torch.Tensor
) – The Laplacian matrix withtorch.sparse_coo_tensor
format. Size \((|\mathcal{V}|, |\mathcal{V}|)\).lamb (
float
) – \(\lambda\), the strength of smoothing.
- smoothing_with_HGNN(X: Tensor, drop_rate: float = 0.0) Tensor [source]#
Return the smoothed feature matrix with the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
\[\mathbf{X} = \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}} \mathbf{X}\]- Parameters:
X (
torch.Tensor
) – The feature matrix. Size \((|\mathcal{V}|, C)\).drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- smoothing_with_HGNN_of_group(group_name: str, X: Tensor, drop_rate: float = 0.0) Tensor [source]#
Return the smoothed feature matrix with the HGNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
\[\mathbf{X} = \mathbf{D}_v^{-\frac{1}{2}} \mathbf{H} \mathbf{W}_e \mathbf{D}_e^{-1} \mathbf{H}^\top \mathbf{D}_v^{-\frac{1}{2}} \mathbf{X}\]- Parameters:
group_name (
str
) – The name of the specified hyperedge group.X (
torch.Tensor
) – The feature matrix. Size \((|\mathcal{V}|, C)\).drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- smoothing_with_HWNN_approx(X: Tensor, par: Parameter, W_d: Parameter, K1: int, K2: int, W: Parameter) Tensor [source]#
Return the smoothed feature matrix with the approximated HWNN Laplacian matrix \(\mathcal{L}_{HGNN}\).
\[\mathbf{X} = \mathbf{theta}_{sum} \mathbf{Lambda}_{beta} \mathbf{theta'}_{sum}\]- Parameters:
X (
torch.Tensor
) – The feature matrix. Size \((|\mathcal{V}|, C)\).par (
torch.nn.Parameter
) – A learnable parameter used in the HWNN approximation.W_d (
torch.nn.Parameter
) – A trainable weight matrix for feature transformation.K1 (
int
) – The order of approximation for the first transformation step.K2 (
int
) – The order of approximation for the second transformation step.W (
torch.nn.Parameter
) – A learnable weight matrix applied in the feature transformation step.
- smoothing_with_HWNN_wavelet(X: Tensor, W_d: Parameter, W: Parameter) Tensor [source]#
Return the smoothed feature matrix with original HWNN Laplacian matrix :
\[\mathbf{X} = \mathbf{Psi}_{s} \mathbf{Lambda}_{beta} \mathbf{Psi}_{s}^{-1}\]- Parameters:
X (
torch.Tensor
) – The feature matrix. Size \((|\mathcal{V}|, C)\).par (
torch.nn.Parameter
) – A learnable parameter used in the HWNN approximation.W_d (
torch.nn.Parameter
) – A trainable weight matrix for feature transformation.K1 (
int
) – The order of approximation for the first transformation step.K2 (
int
) – The order of approximation for the second transformation step.W (
torch.nn.Parameter
) – A learnable weight matrix applied in the feature transformation step.
- property state_dict: Dict[str, Any]#
Get the state dict of the hypergraph.
- to(device: device)[source]#
Move the hypergraph to the specified device.
- Parameters:
device (
torch.device
) – The target device.
- unique_edge_sizes()[source]#
A function that returns the unique edge sizes.
- Returns:
The unique edge sizes in ascending order by size.
- Return type:
list()
- property v: List[int]#
Return the list of vertices.
- v2e(X: Tensor, aggr: str = 'mean', v2e_weight: Tensor | None = None, e_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message passing of
vertices to hyperedges
. The combination ofv2e_aggregation
andv2e_update
.- Parameters:
X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- v2e_aggregation(X: Tensor, aggr: str = 'mean', v2e_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggregation step of
vertices to hyperedges
.- Parameters:
X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- v2e_aggregation_of_group(group_name: str, X: Tensor, aggr: str = 'mean', v2e_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggregation step of
vertices to hyperedges
in specified hyperedge group.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- property v2e_dst: Tensor#
Return the destination hyperedge index vector \(\overrightarrow{v2e}_{dst}\) of the connections (vertices point to hyperedges) in the hypergraph.
- v2e_dst_of_group(group_name: str) Tensor [source]#
Return the destination hyperedge index vector \(\overrightarrow{v2e}_{dst}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- v2e_of_group(group_name: str, X: Tensor, aggr: str = 'mean', v2e_weight: Tensor | None = None, e_weight: Tensor | None = None, drop_rate: float = 0.0)[source]#
Message passing of
vertices to hyperedges
in specified hyperedge group. The combination ofe2v_aggregation_of_group
ande2v_update_of_group
.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.
- property v2e_src: Tensor#
Return the source vertex index vector \(\overrightarrow{v2e}_{src}\) of the connections (vertices point to hyperedges) in the hypergraph.
- v2e_src_of_group(group_name: str) Tensor [source]#
Return the source vertex index vector \(\overrightarrow{v2e}_{src}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- v2e_update(X: Tensor, e_weight: Tensor | None = None)[source]#
Message update step of
vertices to hyperedges
.- Parameters:
X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.
- v2e_update_of_group(group_name: str, X: Tensor, e_weight: Tensor | None = None)[source]#
Message update step of
vertices to hyperedges
in specified hyperedge group.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Hyperedge feature matrix. Size \((|\mathcal{E}|, C)\).e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.
- property v2e_weight: Tensor#
Return the weight vector \(\overrightarrow{v2e}_{weight}\) of the connections (vertices point to hyperedges) in the hypergraph.
- v2e_weight_of_group(group_name: str) Tensor [source]#
Return the weight vector \(\overrightarrow{v2e}_{weight}\) of the connections (vertices point to hyperedges) in the specified hyperedge group.
- Parameters:
group_name (
str
) – The name of the specified hyperedge group.
- v2v(X: Tensor, aggr: str = 'mean', drop_rate: float = 0.0, v2e_aggr: str | None = None, v2e_weight: Tensor | None = None, v2e_drop_rate: float | None = None, e_weight: Tensor | None = None, e2v_aggr: str | None = None, e2v_weight: Tensor | None = None, e2v_drop_rate: float | None = None)[source]#
Message passing of
vertices to vertices
. The combination ofv2e
ande2v
.- Parameters:
X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, thisaggr
will be used to bothv2e
ande2v
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.v2e_aggr (
str
, optional) – The aggregation method for hyperedges to vertices. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, it will override theaggr
ine2v
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.v2e_drop_rate (
float
, optional) – Dropout rate for hyperedges to vertices. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. If specified, it will override thedrop_rate
ine2v
. Default:None
.e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e2v_aggr (
str
, optional) – The aggregation method for vertices to hyperedges. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, it will override theaggr
inv2e
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e2v_drop_rate (
float
, optional) – Dropout rate for vertices to hyperedges. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. If specified, it will override thedrop_rate
inv2e
. Default:None
.
- v2v_of_group(group_name: str, X: Tensor, aggr: str = 'mean', drop_rate: float = 0.0, v2e_aggr: str | None = None, v2e_weight: Tensor | None = None, v2e_drop_rate: float | None = None, e_weight: Tensor | None = None, e2v_aggr: str | None = None, e2v_weight: Tensor | None = None, e2v_drop_rate: float | None = None)[source]#
Message passing of
vertices to vertices
in specified hyperedge group. The combination ofv2e_of_group
ande2v_of_group
.- Parameters:
group_name (
str
) – The specified hyperedge group.X (
torch.Tensor
) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).aggr (
str
) – The aggregation method. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, thisaggr
will be used to bothv2e_of_group
ande2v_of_group
.drop_rate (
float
) – Dropout rate. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. Default:0.0
.v2e_aggr (
str
, optional) – The aggregation method for hyperedges to vertices. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, it will override theaggr
ine2v_of_group
.v2e_weight (
torch.Tensor
, optional) – The weight vector attached to connections (vertices point to hyperedges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.v2e_drop_rate (
float
, optional) – Dropout rate for hyperedges to vertices. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. If specified, it will override thedrop_rate
ine2v_of_group
. Default:None
.e_weight (
torch.Tensor
, optional) – The hyperedge weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e2v_aggr (
str
, optional) – The aggregation method for vertices to hyperedges. Can be'mean'
,'sum'
and'softmax_then_sum'
. If specified, it will override theaggr
inv2e_of_group
.e2v_weight (
torch.Tensor
, optional) – The weight vector attached to connections (hyperedges point to vertices). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone
.e2v_drop_rate (
float
, optional) – Dropout rate for vertices to hyperedges. Randomly dropout the connections in incidence matrix with probabilitydrop_rate
. If specified, it will override thedrop_rate
inv2e_of_group
. Default:None
.
- property vars_for_DL: List[str]#
Return a name list of available variables for deep learning in the hypergraph including
Sparse Matrices:
\[\mathbf{H}, \mathbf{H}^\top, \mathcal{L}_{sym}, \mathcal{L}_{rw} \mathcal{L}_{HGNN},\]Sparse Diagnal Matrices:
\[\mathbf{W}_e, \mathbf{D}_v, \mathbf{D}_v^{-1}, \mathbf{D}_v^{-\frac{1}{2}}, \mathbf{D}_e, \mathbf{D}_e^{-1},\]Vectors:
\[\begin{split}\overrightarrow{v2e}_{src}, \overrightarrow{v2e}_{dst}, \overrightarrow{v2e}_{weight},\\ \overrightarrow{e2v}_{src}, \overrightarrow{e2v}_{dst}, \overrightarrow{e2v}_{weight}\end{split}\]