Skip to content

SIGN

SIGN(K: int)

Bases: BaseTransform

Precomputes the propagated node features of the Scalable Inception Graph Neural Network (SIGN) from "SIGN: Scalable Inception Graph Neural Networks", as PyG's SIGN:

\[ \mathbf{X}^{(i)} = {\left( \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2} \right)}^i \mathbf{X} \]

for \(i \in \{ 1, \ldots, K \}\), stored in the attributes x1, x2, ... xK. \(\mathbf{D}\) is the weighted in-degree, the edge_weights attribute is used as \(\mathbf{A}\) if it exists, and no self-loops are added. Messages flow from the source to the destination of each edge.

Parameters:

Name Type Description Default
K int

Number of hops.

required

Example:

graph = GraphData(
    edge_index=mx.array([[0, 1], [1, 0]]),
    node_features=mx.array([[1.0], [2.0]]),
)
graph = SIGN(K=2)(graph)
graph.x1, graph.x2
# mx.array([[2.0], [1.0]]), mx.array([[1.0], [2.0]])

Methods:

Name Description
process

Adds the propagated node features x1 ... xK to data.

Source code in mlx_graphs/transforms/propagation.py
def __init__(self, K: int):
    self.K = K

process

process(data: GraphData) -> GraphData

Adds the propagated node features x1 ... xK to data.

Parameters:

Name Type Description Default
data GraphData

The graph to transform.

required

Returns:

Type Description
GraphData

The graph with the propagated features.

Source code in mlx_graphs/transforms/propagation.py
def process(self, data: GraphData) -> GraphData:
    """Adds the propagated node features ``x1`` ... ``xK`` to ``data``.

    Args:
        data: The graph to transform.

    Returns:
        The graph with the propagated features.
    """
    if data.node_features is None:
        raise ValueError("SIGN requires node features")
    num_nodes = _num_nodes(data)
    src, dst = _host_edges(data)
    weights = _sym_norm_weights(src, dst, _edge_weights(data), num_nodes)
    src_mx, dst_mx = mx.array(src), mx.array(dst)
    weights_mx = mx.array(weights.astype(np.float32))

    features = data.node_features
    for i in range(1, self.K + 1):
        features = _propagate(features, src_mx, dst_mx, weights_mx, num_nodes)
        setattr(data, f"x{i}", features)
    return data

from mlx_graphs.transforms import SIGN · mlx_graphs/transforms/propagation.py