Skip to content

Transforms

Class Description
BaseTransform An abstract class for creating transformations Transforms are a way to modify and customize GraphData by implicitly passing them as arguments in mlx_graphs.dataset.Dataset
Compose Chains several transforms together.
FeaturesNormalizedTransform
ToUndirected Makes a graph undirected by adding the reverse of every edge.
AddSelfLoops Adds a self-loop to every node of a graph.
RemoveSelfLoops Removes the self-loops of a graph, together with their per-edge attributes (e.g. edge_features, edge_labels).
RemoveIsolatedNodes Removes the isolated nodes of a graph.
LargestConnectedComponents Keeps only the largest connected components of a graph.
RandomNodeSplit Randomly splits the nodes of a graph into training, validation and test sets, stored as the boolean masks train_mask, val_mask and test_mask of shape [num_nodes].
RandomLinkSplit Randomly splits the edges of a graph into training, validation and test sets for link prediction.
OneHotDegree Adds the one-hot encoded degree of each node to the node features.
Constant Adds a constant value to the node features of each node.
AddRandomWalkPE Adds the random walk positional encoding of each node, from "Graph Neural Networks with Learnable Structural and Positional Representations".
GCNNorm Applies the GCN normalization from "Semi-supervised Classification with Graph Convolutional Networks" to the edges of a graph and stores the result in edge_weights:
AddRemainingSelfLoops Adds a self-loop to every node of a graph that does not already have one (see add_remaining_self_loops()).
RemoveDuplicatedEdges Removes the duplicated edges of a graph and sorts the edges by source then destination (see coalesce()).
IndexToMask Converts index attributes (named *_index, e.g. train_index) to boolean mask attributes (named *_mask, e.g. train_mask).
MaskToIndex Converts boolean mask attributes (named *_mask, e.g. train_mask) to index attributes (named *_index, e.g. train_index).
KNNGraph Creates a k-NN graph from the node positions pos of a graph.
RadiusGraph Creates the graph connecting the nodes whose positions pos are within a given distance.
NormalizeFeatures Row-normalizes the given attributes to sum up to one, as PyG's NormalizeFeatures.
TargetIndegree Saves the globally normalized in-degree of the target node of each edge in its edge features, as PyG's TargetIndegree:
LocalDegreeProfile Appends the Local Degree Profile (LDP) from "A Simple yet Effective Baseline for Non-attribute Graph Classification" to the node features, as PyG's LocalDegreeProfile:
AddLaplacianEigenvectorPE Adds the Laplacian eigenvector positional encoding from "Benchmarking Graph Neural Networks" to each node, as PyG's AddLaplacianEigenvectorPE.
SVDFeatureReduction Reduces the dimension of the node features with a Singular Value Decomposition, as PyG's SVDFeatureReduction.
SIGN Precomputes the propagated node features of the Scalable Inception Graph Neural Network (SIGN) from "SIGN: Scalable Inception Graph Neural Networks", as PyG's SIGN:
FeaturePropagation Fills in missing node features by propagating the known ones, with the feature propagation algorithm from "On the Unreasonable Effectiveness of Feature propagation in Learning on Graphs with Missing Node Features", as PyG's FeaturePropagation:
VirtualNode Appends a virtual node connected to all the other nodes, as described in "Neural Message Passing for Quantum Chemistry", as PyG's VirtualNode.
TwoHop Adds the two-hop edges to the graph, as PyG's TwoHop.
LineGraph Converts a graph to its line graph, as PyG's LineGraph.
ToDense Converts the edges of a graph to a dense adjacency matrix, as PyG's ToDense.
RemoveTrainingClasses Removes classes from the node-level training set given by train_mask, e.g. to build a zero-shot setting, as PyG's RemoveTrainingClasses.

Point clouds and meshes

Transforms of node positions pos and mesh triangles face. Random transforms draw from mx.random.

Class Description
SamplePoints Uniformly samples a fixed number of points on the faces of a mesh (pos and face), with probabilities proportional to the face areas (with mx.random).
FixedPoints Samples a fixed number of points (nodes) from a point cloud, with all their node-level attributes (with mx.random).
NormalizeScale Centers and scales the node positions pos to the interval \((-1, 1)\).
Center Centers the node positions pos around the origin.
LinearTransformation Transforms the node positions pos with a square transformation matrix: pos @ matrix.T.
RandomJitter Translates each node position pos by a random offset, sampled uniformly from \([-t, t]\) in each dimension (with mx.random).
RandomRotate Rotates the node positions pos by a random angle (in degrees) around an axis, sampled uniformly from degrees (with mx.random).
RandomScale Scales the node positions pos by a random factor sampled uniformly from scales (with mx.random).
FaceToEdge Converts the mesh faces face (triangles [3, num_faces] or tetrahedra [4, num_faces]) to undirected, coalesced edges.
Cartesian Saves the relative Cartesian coordinates of linked nodes in its edge features: \(\mathbf{p}_{\text{src}} - \mathbf{p}_{\text{dst}}\) for each edge, as in PyG.
Distance Saves the Euclidean distance of linked nodes in its edge features.
Polar Saves the polar coordinates (distance and angle in \([0, 2\pi)\)) of linked nodes of 2D graphs in its edge features.
PointPairFeatures Saves the rotation-invariant point pair features of linked nodes in their edge features (see point_pair_features()).