topobench.transforms.data_manipulations package#
Data manipulations module with automated exports.
- class CalculateSimplicialCurvature(**kwargs)#
Bases:
BaseTransformA transform that calculates the simplicial curvature of the input graph.
- Parameters:
- **kwargsoptional
Parameters for the transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- one_cell_curvature(data)#
Calculate the one cell curvature of the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
Data with the one cell curvature.
- two_cell_curvature(data)#
Calculate the two cell curvature of the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
Data with the two cell curvature.
- zero_cell_curvature(data)#
Calculate the zero cell curvature of the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
Data with the zero cell curvature.
- class CombinedPSEs(encodings, parameters=None, **kwargs)#
Bases:
BaseTransformCombined PSEs transform.
Applies one or more pre-defined positional or structural encoding transforms (LapPE, RWSE) to a graph, storing their outputs and optionally concatenating them to data.x.
- Parameters:
- encodingslist of str
List of structural encodings to apply. Supported values are “LapPE” for Laplacian Positional Encoding and “RWSE” for Random Walk Structural Encoding.
- parametersdict, optional
Additional parameters for the encoding transforms.
- **kwargsdict, optional
Additional keyword arguments.
- __init__(encodings, parameters=None, **kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data with added structural encodings.
- class EqualGausFeatures(**kwargs)#
Bases:
BaseTransformA transform that generates equal Gaussian features for all nodes.
- Parameters:
- **kwargsoptional
Additional arguments for the class. It should contain the following keys: - mean (float): The mean of the Gaussian distribution. - std (float): The standard deviation of the Gaussian distribution. - num_features (int): The number of features to generate.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class GroupCombinatorialHomophily(**kwargs)#
Bases:
BaseTransformCalculates group combinatorial homophily of the input hypergraph.
This transformation implements the methodology from the paper: “Combinatorial Characterizations and Impossibilities for Higher-order Homophily”. It computes homophily metrics for hypergraphs by analyzing the relationship between node labels within hyperedges.
- Parameters:
- **kwargsdict, optional
Additional parameters for the transform. - top_k : int, default=3
Number of top hyperedge cardinalities to analyze.
- Attributes:
- typestr
Identifier for the transform type.
- top_kint
Number of top hyperedge cardinalities to analyze.
- __init__(**kwargs)#
- calculate_D_matrix(H, labels, he_cardinalities, unique_labels, class_node_idxs)#
Calculate the degree matrices D and D_t for the hypergraph.
- Parameters:
- Htorch.Tensor
Dense incidence matrix of the hypergraph.
- labelstorch.Tensor
Node labels.
- he_cardinalitiestorch.Tensor
Cardinality of each hyperedge.
- unique_labelsdict
Dictionary mapping labels to their counts.
- class_node_idxsdict
Dictionary mapping labels to node indices.
- Returns:
- tuple[torch.Tensor, torch.Tensor]
D_t_class : Type-t degree distribution matrix for each class
D : Degree matrix counting same-label nodes in hyperedges
- calculate_affinity_score(n_nodes, X_mod, t, k)#
Calculate affinity score.
- Parameters:
- n_nodesint
Total number of nodes.
- X_modint
Total number of nodes in a class.
- tint
Type-t degree.
- kint
Max hyperedge cardinality.
- Returns:
- torch.Tensor
The affinity matrix.
- calculate_baseline_matrix(he_cardinalities, unique_labels, class_node_idxs, count_labels, n_nodes)#
Calculate the baseline affinity matrix for comparison.
- Parameters:
- he_cardinalitiestorch.Tensor
Cardinality of each hyperedge.
- unique_labelsdict
Dictionary mapping labels to their counts.
- class_node_idxsdict
Dictionary mapping labels to node indices.
- count_labelstorch.Tensor
Count of nodes for each label.
- n_nodesint
Total number of nodes in the hypergraph.
- Returns:
- torch.Tensor
Baseline matrix containing expected affinity scores for each class and degree type.
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class IdentityTransform(**kwargs)#
Bases:
BaseTransformAn identity transform that does nothing to the input data.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The same data.
- class InfereKNNConnectivity(**kwargs)#
Bases:
BaseTransformTransform to infer point cloud connectivity.
The transform generates the k-nearest neighbor connectivity of the input point cloud.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class InfereRadiusConnectivity(**kwargs)#
Bases:
BaseTransformClass to infer point cloud connectivity.
The transform generates the radius connectivity of the input point cloud.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class KeepOnlyConnectedComponent(**kwargs)#
Bases:
BaseTransformClass to keep only the largest connected components of the input graph.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class KeepSelectedDataFields(**kwargs)#
Bases:
BaseTransformA transform that keeps only the selected fields of the input data.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class LapPE(max_pe_dim, include_eigenvalues=False, include_first=False, concat_to_x=True, **kwargs)#
Bases:
BaseTransformLaplacian Positional Encoding (LapPE) transform.
This computes the smallest eigenvectors of the normalized Laplacian matrix and appends them as node features (structural encodings). Optionally pads to a fixed dimension.
- Parameters:
- max_pe_dimint
Maximum number of eigenvectors to use (dimensionality of the encoding).
- include_eigenvaluesbool, optional
If True, concatenates eigenvalues alongside eigenvectors. Shape then becomes
[num_nodes, 2 * max_pe_dim]. Default is False.- include_firstbool, optional
If False, removes eigenvectors corresponding to (near-)zero eigenvalues (constant eigenvector in connected graphs). Default is False.
- concat_to_xbool, optional
If True, concatenates the encodings with existing node features in
data.x. Ifdata.xis None, creates it. Default is True.- **kwargsdict
Additional arguments (not used).
- __init__(max_pe_dim, include_eigenvalues=False, include_first=False, concat_to_x=True, **kwargs)#
- forward(data)#
Compute the Laplacian positional encodings for the input graph.
- Parameters:
- dataData
Input graph data object.
- Returns:
- Data
Graph data object with Laplacian positional encodings added.
- class MessagePassingHomophily(**kwargs)#
Bases:
BaseTransformCalculates message passing homophily of the input data.
This transformation implements the methodology from the paper: “Hypergraph Neural Networks through the Lens of Message Passing: A Common Perspective to Homophily and Architecture Design”. It computes homophily metrics for hypergraphs by analyzing the relationship between node labels within hyperedges.
- Parameters:
- **kwargsdict, optional
Additional parameters for the transform. - top_k : int, default=3
Number of top hyperedge cardinalities to analyze.
- Attributes:
- typestr
Identifier for the transform type.
- top_kint
Number of top hyperedge cardinalities to analyze.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class NodeDegrees(**kwargs)#
Bases:
BaseTransformA transform that calculates the node degrees of the input graph.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- calculate_node_degrees(data, field)#
Calculate the node degrees of the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- fieldstr
The field to calculate the node degrees.
- Returns:
- torch_geometric.data.Data
The transformed data.
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class NodeFeaturesToFloat(**kwargs)#
Bases:
BaseTransformA transform that converts the node features of the input graph to float.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class OneHotDegreeFeatures(max_degree, degrees_fields, features_fields, cat=False, **kwargs)#
Bases:
BaseTransformClass for one hot degree features transform.
A transform that adds the node degree as one hot encodings to the node features.
- Parameters:
- max_degreeint
The maximum degree of the graph.
- degrees_fieldsstr
The field containing the node degrees.
- features_fieldsstr
The field containing the node features.
- catbool, optional
If set to True, the one hot encodings are concatenated to the node features (default: False).
- **kwargsoptional
Additional arguments for the class.
- __init__(max_degree, degrees_fields, features_fields, cat=False, **kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The transformed data.
- class RWSE(max_pe_dim, concat_to_x=True, **kwargs)#
Bases:
BaseTransformRandom Walk Structural Encoding (RWSE) transform.
Computes return probabilities of random walks of length 1..K for each node in the graph, and appends them as structural encodings to node features.
- Parameters:
- max_pe_dimint
Maximum walk length (number of RWSE dimensions).
- concat_to_xbool, optional
If True, concatenates the encodings with existing node features in
data.x. Ifdata.xis None, creates it. Default is True.- **kwargsdict
Additional arguments (not used).
- __init__(max_pe_dim, concat_to_x=True, **kwargs)#
- forward(data)#
Compute the RWSE for the input graph.
- Parameters:
- dataData
Input graph data object.
- Returns:
- Data
Graph data object with RWSE added.
- class RedefineSimplicialNeighbourhoods(**kwargs)#
Bases:
BaseTransformAn transform that redifines simplicial complex neighbourhood.
- Parameters:
- **kwargsoptional
Parameters for the base transform.
- __init__(**kwargs)#
- forward(data)#
Apply the transform to the input data.
- Parameters:
- datatorch_geometric.data.Data
The input data.
- Returns:
- torch_geometric.data.Data
The same data.
Submodules#
- topobench.transforms.data_manipulations.calculate_simplicial_curvature module
- topobench.transforms.data_manipulations.equal_gaus_features module
- topobench.transforms.data_manipulations.group_homophily module
- topobench.transforms.data_manipulations.identity_transform module
- topobench.transforms.data_manipulations.infere_knn_connectivity module
- topobench.transforms.data_manipulations.infere_radius_connectivity module
- topobench.transforms.data_manipulations.keep_only_connected_component module
- topobench.transforms.data_manipulations.keep_selected_data_fields module
- topobench.transforms.data_manipulations.laplacian_encodings module
BaseTransformDataData.__init__()Data.connected_components()Data.debug()Data.edge_subgraph()Data.from_dict()Data.get_all_edge_attrs()Data.get_all_tensor_attrs()Data.is_edge_attr()Data.is_node_attr()Data.stores_as()Data.subgraph()Data.to_dict()Data.to_heterogeneous()Data.to_namedtuple()Data.update()Data.validate()Data.batchData.edge_attrData.edge_indexData.edge_storesData.edge_weightData.faceData.node_storesData.num_edge_featuresData.num_edge_typesData.num_facesData.num_featuresData.num_node_featuresData.num_node_typesData.num_nodesData.posData.storesData.timeData.xData.y
LapPEeigsh()get_laplacian()to_scipy_sparse_matrix()
- topobench.transforms.data_manipulations.mp_homophily module
- topobench.transforms.data_manipulations.node_degrees module
- topobench.transforms.data_manipulations.node_features_to_float module
- topobench.transforms.data_manipulations.one_hot_degree_features module
- topobench.transforms.data_manipulations.positional_and_structural_encodings module
BaseTransformCombinedPSEsDataData.__init__()Data.connected_components()Data.debug()Data.edge_subgraph()Data.from_dict()Data.get_all_edge_attrs()Data.get_all_tensor_attrs()Data.is_edge_attr()Data.is_node_attr()Data.stores_as()Data.subgraph()Data.to_dict()Data.to_heterogeneous()Data.to_namedtuple()Data.update()Data.validate()Data.batchData.edge_attrData.edge_indexData.edge_storesData.edge_weightData.faceData.node_storesData.num_edge_featuresData.num_edge_typesData.num_facesData.num_featuresData.num_node_featuresData.num_node_typesData.num_nodesData.posData.storesData.timeData.xData.y
- topobench.transforms.data_manipulations.random_walk_encodings module
BaseTransformDataData.__init__()Data.connected_components()Data.debug()Data.edge_subgraph()Data.from_dict()Data.get_all_edge_attrs()Data.get_all_tensor_attrs()Data.is_edge_attr()Data.is_node_attr()Data.stores_as()Data.subgraph()Data.to_dict()Data.to_heterogeneous()Data.to_namedtuple()Data.update()Data.validate()Data.batchData.edge_attrData.edge_indexData.edge_storesData.edge_weightData.faceData.node_storesData.num_edge_featuresData.num_edge_typesData.num_facesData.num_featuresData.num_node_featuresData.num_node_typesData.num_nodesData.posData.storesData.timeData.xData.y
RWSEdegree()
- topobench.transforms.data_manipulations.redefine_simplicial_neighbourhoods module