topobench.transforms.data_manipulations.one_hot_degree_features module#

One hot degree features transform.

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.

one_hot(index, num_classes=None, dtype=None)#

Taskes a one-dimensional index tensor and returns a one-hot encoded representation of it with shape [*, num_classes] that has zeros everywhere except where the index of last dimension matches the corresponding value of the input tensor, in which case it will be 1.

Note

This is a more memory-efficient version of torch.nn.functional.one_hot() as you can customize the output dtype.

Parameters:
  • index (torch.Tensor) – The one-dimensional input tensor.

  • num_classes (int, optional) – The total number of classes. If set to None, the number of classes will be inferred as one greater than the largest class value in the input tensor. (default: None)

  • dtype (torch.dtype, optional) – The dtype of the output tensor.