easygraph.classes.base module#
- class easygraph.classes.base.BaseHypergraph(num_v: int, v_property: Dict | List[Dict] | None = None, e_list: List[int] | List[List[int]] | None = None, e_property: Dict | List[Dict] | None = None, e_weight: float | List[float] | None = None, extra_selfloop: bool = False, device: str = 'cpu')[source]#
Bases:
objectThe
BaseHypergraphclass is the base class for all hypergraph structures.- Parameters:
num_v (
int) – The number of vertices.e_list (
Union[List[int], List[List[int]]], optional) – Edge list. Defaults toNone.e_weight (
Union[float, List[float]], optional) – A list of weights for edges. Defaults toNone.extra_selfloop (
bool, optional) – Whether to add extra self-loop to the graph. Defaults toFalse.device (
torch.device, optional) – The device to store the graph. Defaults totorch.device('cpu').
- abstract property H: torch.Tensor#
Return the hypergraph incidence matrix.
- property H_e2v: torch.Tensor#
Return the hypergraph incidence matrix with
sparse matrixformat.
- H_e2v_of_group(group_name: str) torch.Tensor[source]#
Return the hypergraph incidence matrix with
sparse matrixformat in the specified hyperedge group.- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- abstract property H_of_group: torch.Tensor#
Return the hypergraph incidence matrix in the specified hyperedge group.
- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property H_v2e: torch.Tensor#
Return the hypergraph incidence matrix with
sparse matrixformat.
- H_v2e_of_group(group_name: str) torch.Tensor[source]#
Return the hypergraph incidence matrix with
sparse matrixformat in the specified hyperedge group.- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property R_e2v: torch.Tensor#
Return the weight matrix of connections (hyperedges point to vertices) with
sparse matrixformat.
- R_e2v_of_group(group_name: str) torch.Tensor[source]#
Return the weight matrix of connections (hyperedges point to vertices) with
sparse matrixformat in the specified hyperedge group.- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property R_v2e: torch.Tensor#
Return the weight matrix of connections (vertices point to hyperedges) with
sparse matrixformat.
- R_v2e_of_group(group_name: str) torch.Tensor[source]#
Return the weight matrix of connections (vertices point to hyperedges) with
sparse matrixformat in the specified hyperedge group.- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property W_e: torch.Tensor#
Return the hyperedge weight matrix of the hypergraph.
- W_e_of_group(group_name: str) torch.Tensor[source]#
Return the hyperedge weight matrix of the specified hyperedge group.
- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property W_v: torch.Tensor#
Return the vertex weight matrix of the hypergraph.
- add_hyperedges(e_list_v2e: List[int] | List[List[int]], e_list_e2v: List[int] | List[List[int]], w_list_v2e: List[float] | List[List[float]] | None = None, w_list_e2v: List[float] | List[List[float]] | None = None, e_weight: float | List[float] | None = None, merge_op: str = 'mean', group_name: str = 'main')[source]#
Add hyperedges to the hypergraph. If the
group_nameis not specified, the hyperedges will be added to the defaultmainhyperedge group.- Parameters:
num_v (
int) – The number of vertices in the hypergraph.e_list_v2e (
Union[List[int], List[List[int]]]) – A list of hyperedges describes how the vertices point to the hyperedges.e_list_e2v (
Union[List[int], List[List[int]]]) – A list of hyperedges describes how the hyperedges point to the vertices.w_list_v2e (
Union[List[float], List[List[float]]], optional) – The weights are attached to the connections from vertices to hyperedges, which has the same shape ase_list_v2e. If set toNone, the value1is used for all connections. Defaults toNone.w_list_e2v (
Union[List[float], List[List[float]]], optional) – The weights are attached to the connections from the hyperedges to the vertices, which has the same shape toe_list_e2v. If set toNone, the value1is used for all connections. Defaults toNone.e_weight (
Union[float, List[float]], optional) – A list of weights for hyperedges. If set toNone, the value1is used for all hyperedges. Defaults toNone.merge_op (
str) – The merge operation for the conflicting hyperedges. The possible values aremean,sum,max, andmin. Defaults tomean.group_name (
str, optional) – The target hyperedge group to add these hyperedges. Defaults to themainhyperedge group.
- abstract clone() BaseHypergraph[source]#
Return a copy of this type of hypergraph.
- abstract 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.
- abstract 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.
- abstract property e: Tuple[List[List[int]], List[float]]#
Return all hyperedges and weights in the hypergraph.
- abstract e2v(X: torch.Tensor, aggr: str = 'mean', e2v_weight: torch.Tensor | None = None, v_weight: torch.Tensor | None = None)[source]#
Message passing of
hyperedges to vertices. The combination ofe2v_aggregationande2v_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.v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract e2v_aggregation(X: torch.Tensor, aggr: str = 'mean', e2v_weight: torch.Tensor | None = None)[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.
- abstract e2v_aggregation_of_group(group_name: str, X: torch.Tensor, aggr: str = 'mean', e2v_weight: torch.Tensor | None = None)[source]#
Message aggregation step of
hyperedges to verticesin 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.
- abstract e2v_of_group(group_name: str, X: torch.Tensor, aggr: str = 'mean', e2v_weight: torch.Tensor | None = None, v_weight: torch.Tensor | None = None)[source]#
Message passing of
hyperedges to verticesin specified hyperedge group. The combination ofe2v_aggregation_of_groupande2v_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.v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract e2v_update(X: torch.Tensor, v_weight: torch.Tensor | None = None)[source]#
Message update step of
hyperedges to vertices.- Parameters:
X (
torch.Tensor) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract e2v_update_of_group(group_name: str, X: torch.Tensor, v_weight: torch.Tensor | None = None)[source]#
Message update step of
hyperedges to verticesin specified hyperedge group.- Parameters:
group_name (
str) – The specified hyperedge group.X (
torch.Tensor) – Vertex feature matrix. Size \((|\mathcal{V}|, C)\).v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract e_of_group(group_name: str) Tuple[List[List[int]], List[float]][source]#
Return all hyperedges and weights in the specified hyperedge group.
- Parameters:
group_name (
str) – The name of the specified hyperedge group.
- property e_property#
- abstract static from_state_dict(state_dict: dict)[source]#
Load the EasyGraph’s hypergraph structure from the state dict.
- Parameters:
state_dict (
dict) – The state dict to load the EasyGraph’s hypergraph.
- property group_names: List[str]#
Return the names of hyperedge groups in the hypergraph.
- abstract static load(file_path: str | Path)[source]#
Load the EasyGraph’s hypergraph structure from a file.
- Parameters:
file_path (
str) – The file path to load the DEasyGraph’s hypergraph structure.
- 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 in 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_hyperedges(e_list_v2e: List[int] | List[List[int]], e_list_e2v: List[int] | List[List[int]], group_name: str | None = None)[source]#
Remove the specified hyperedges from the hypergraph.
- Parameters:
e_list_v2e (
Union[List[int], List[List[int]]]) – A list of hyperedges describes how the vertices point to the hyperedges.e_list_e2v (
Union[List[int], List[List[int]]]) – A list of hyperedges describes how the hyperedges point to the vertices.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.
- abstract save(file_path: str | Path)[source]#
Save the EasyGraph’s hypergraph structure to a file.
- Parameters:
file_path (
str) – The file_path to store the EasyGraph’s hypergraph structure.
- smoothing(X: torch.Tensor, L: torch.Tensor, lamb: float) torch.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_tensorformat. Size \((|\mathcal{V}|, |\mathcal{V}|)\).lamb (
float) – \(\lambda\), the strength of smoothing.
- abstract property state_dict: Dict[str, Any]#
Get the state dict of the hypergraph.
- to(device: str = 'cpu') BaseHypergraph[source]#
Move the hypergraph to the specified device.
- Parameters:
device (
torch.device) – The device to store the hypergraph.
- property v: List[int]#
Return the list of vertices.
- abstract v2e(X: torch.Tensor, aggr: str = 'mean', v2e_weight: torch.Tensor | None = None, e_weight: torch.Tensor | None = None)[source]#
Message passing of
vertices to hyperedges. The combination ofv2e_aggregationandv2e_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 hyepredges). 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.
- abstract v2e_aggregation(X: torch.Tensor, aggr: str = 'mean', v2e_weight: torch.Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggretation 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 hyepredges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract v2e_aggregation_of_group(group_name: str, X: torch.Tensor, aggr: str = 'mean', v2e_weight: torch.Tensor | None = None, drop_rate: float = 0.0)[source]#
Message aggregation step of
vertices to hyperedgesin 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 hyepredges). If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract v2e_of_group(group_name: str, X: torch.Tensor, aggr: str = 'mean', v2e_weight: torch.Tensor | None = None, e_weight: torch.Tensor | None = None)[source]#
Message passing of
vertices to hyperedgesin specified hyperedge group. The combination ofe2v_aggregation_of_groupande2v_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 hyepredges). 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.
- abstract v2e_update(X: torch.Tensor, e_weight: torch.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.
- abstract v2e_update_of_group(group_name: str, X: torch.Tensor, e_weight: torch.Tensor | None = None)[source]#
Message update step of
vertices to hyperedgesin 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.
- abstract v2v(X: torch.Tensor, aggr: str = 'mean', v2e_aggr: str | None = None, v2e_weight: torch.Tensor | None = None, e_weight: torch.Tensor | None = None, e2v_aggr: str | None = None, e2v_weight: torch.Tensor | None = None, v_weight: torch.Tensor | None = None)[source]#
Message passing of
vertices to vertices. The combination ofv2eande2v.- 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, thisaggrwill be used to bothv2eande2v.v2e_aggr (
str, optional) – The aggregation method for hyperedges to vertices. Can be'mean','sum'and'softmax_then_sum'. If specified, it will override theaggrine2v.v2e_weight (
torch.Tensor, optional) – The weight vector attached to connections (vertices point to hyepredges). 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.e2v_aggr (
str, optional) – The aggregation method for vertices to hyperedges. Can be'mean','sum'and'softmax_then_sum'. If specified, it will override theaggrinv2e.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.v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- abstract v2v_of_group(group_name: str, X: torch.Tensor, aggr: str = 'mean', v2e_aggr: str | None = None, v2e_weight: torch.Tensor | None = None, e_weight: torch.Tensor | None = None, e2v_aggr: str | None = None, e2v_weight: torch.Tensor | None = None, v_weight: torch.Tensor | None = None)[source]#
Message passing of
vertices to verticesin specified hyperedge group. The combination ofv2e_of_groupande2v_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, thisaggrwill be used to bothv2e_of_groupande2v_of_group.v2e_aggr (
str, optional) – The aggregation method for hyperedges to vertices. Can be'mean','sum'and'softmax_then_sum'. If specified, it will override theaggrine2v_of_group.v2e_weight (
torch.Tensor, optional) – The weight vector attached to connections (vertices point to hyepredges). 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.e2v_aggr (
str, optional) – The aggregation method for vertices to hyperedges. Can be'mean','sum'and'softmax_then_sum'. If specified, it will override theaggrinv2e_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.v_weight (
torch.Tensor, optional) – The vertex weight vector. If not specified, the function will use the weights specified in hypergraph construction. Defaults toNone.
- property v_property#
- property v_weight: List[float]#
Return the vertex weights of the hypergraph.
- abstract property vars_for_DL: List[str]#
Return a name list of available variables for deep learning in this type of hypergraph.