topobench.transforms.data_manipulations package#

Data manipulations module with automated exports.

class CalculateSimplicialCurvature(**kwargs)#

Bases: BaseTransform

A 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: BaseTransform

Combined 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: BaseTransform

A 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: BaseTransform

Calculates 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: BaseTransform

An 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: BaseTransform

Transform 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: BaseTransform

Class 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: BaseTransform

Class 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: BaseTransform

A 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: BaseTransform

Laplacian 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. If data.x is 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: BaseTransform

Calculates 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: BaseTransform

A 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: BaseTransform

A 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: BaseTransform

Class 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: BaseTransform

Random 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. If data.x is 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: BaseTransform

An 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#