PNAConv
¶
PNAConv(
node_features_dim: int,
out_features_dim: int,
aggregators: List[str],
scalers: List[str],
deg: Union[array, ndarray, Sequence[int]],
edge_features_dim: Optional[int] = None,
towers: int = 1,
pre_layers: int = 1,
post_layers: int = 1,
divide_input: bool = False,
act: Union[str, Callable, None] = "relu",
train_norm: bool = False,
**kwargs,
)
Bases: MessagePassing
Principal Neighbourhood Aggregation graph convolution from "Principal Neighbourhood Aggregation for Graph Nets" paper.
with
where \(h_{\mathbf{\Theta}}\) (pre_layers linear layers) and
\(\gamma_{\mathbf{\Theta}}\) (post_layers linear layers) are MLPs,
applied separately in each of the towers, followed by a final linear
layer. The aggregation is a
DegreeScalerAggregation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input node features. |
required |
out_features_dim
|
int
|
Size of the output node embeddings. Must be
divisible by |
required |
aggregators
|
List[str]
|
Aggregations, among |
required |
scalers
|
List[str]
|
Scalers, among |
required |
deg
|
Union[array, ndarray, Sequence[int]]
|
Histogram of the in-degrees of the training nodes, see
|
required |
edge_features_dim
|
Optional[int]
|
Size of the edge features, if any. Default: |
None
|
towers
|
int
|
Number of towers. Default: |
1
|
pre_layers
|
int
|
Number of layers of the message MLP. Default: |
1
|
post_layers
|
int
|
Number of layers of the update MLP. Default: |
1
|
divide_input
|
bool
|
If |
False
|
act
|
Union[str, Callable, None]
|
Activation of the pre- and post-MLPs: a name of an |
'relu'
|
train_norm
|
bool
|
Whether the degree normalization constants are
learnable. Default: |
False
|
**kwargs
|
Additional arguments of
|
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import PNAConv
edge_index = mx.array([[0, 1, 2, 3, 4], [1, 0, 1, 4, 3]])
node_features = mx.random.normal((5, 16))
deg = PNAConv.get_degree_histogram([(edge_index, 5)])
conv = PNAConv(
16,
32,
aggregators=["mean", "min", "max", "std"],
scalers=["identity", "amplification", "attenuation"],
deg=deg,
towers=4,
)
>>> conv(edge_index, node_features).shape
(5, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of PNAConv. |
get_degree_histogram |
Histogram of the in-degrees of the nodes of |
Source code in mlx_graphs/nn/conv/pna_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_features: Optional[array] = None,
) -> array
Computes the forward pass of PNAConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features of shape
|
required |
edge_features
|
Optional[array]
|
Optional edge features of shape
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
The node embeddings, of shape |
Source code in mlx_graphs/nn/conv/pna_conv.py
get_degree_histogram
staticmethod
¶
get_degree_histogram(graphs: Iterable) -> array
Histogram of the in-degrees of the nodes of graphs, to pass as
deg to PNAConv, PNA or
DegreeScalerAggregation.
deg[i] is the number of nodes with in-degree i (number of
edges edge_index[1] == node). It is computed on the host with
numpy, once, before training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graphs
|
Iterable
|
A |
required |
Returns:
| Type | Description |
|---|---|
array
|
An integer array with the degree histogram. |
Example:
from mlx_graphs.loaders import Dataloader
from mlx_graphs.nn import PNAConv
deg = PNAConv.get_degree_histogram(Dataloader(train_dataset, 128))
Source code in mlx_graphs/nn/conv/pna_conv.py
from mlx_graphs.nn import PNAConv · mlx_graphs/nn/conv/pna_conv.py