RECT_L
¶
RECT_L(
node_features_dim: int,
hidden_features_dim: int,
normalize: bool = True,
dropout: float = 0.0,
)
Bases: Module
The RECT model, i.e. its supervised RECT-L part, from the "Network Embedding with Completely-imbalanced Labels" paper.
A one-layer GCN is trained to reconstruct semantic class knowledge (the
class centers given by get_semantic_labels()), and its hidden
embeddings (embed()) are used as node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input node features. |
required |
hidden_features_dim
|
int
|
Size of the hidden node embeddings. |
required |
normalize
|
bool
|
Whether to add self-loops and apply the symmetric GCN
normalization. Default: |
True
|
dropout
|
float
|
Dropout probability. Default: |
0.0
|
Example:
import mlx.nn as nn
from mlx_graphs.nn import RECT_L
model = RECT_L(200, 200, normalize=False, dropout=0.0)
target = model.get_semantic_labels(node_features, labels, train_mask)
def loss_fn(model):
out = model(edge_index, node_features)
return nn.losses.mse_loss(out[train_idx], target)
embeddings = model.embed(edge_index, node_features)
Methods:
| Name | Description |
|---|---|
__call__ |
Reconstructs the semantic labels of the nodes. |
embed |
Returns the node embeddings (the GCN output), without gradient. |
get_semantic_labels |
Replaces the labels of the masked nodes by their class centers, i.e. |
Source code in mlx_graphs/nn/models/rect.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
) -> array
Reconstructs the semantic labels of the nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features |
required |
edge_weights
|
Optional[array]
|
Optional weight of each edge. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape |
Source code in mlx_graphs/nn/models/rect.py
embed
¶
embed(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
) -> array
Returns the node embeddings (the GCN output), without gradient.
Source code in mlx_graphs/nn/models/rect.py
get_semantic_labels
¶
Replaces the labels of the masked nodes by their class centers, i.e. the mean features of the masked nodes of each class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Input node features |
required |
y
|
array
|
Integer labels of all the nodes, shape |
required |
mask
|
array
|
Boolean mask or index array of the labeled nodes |
required |
Returns:
| Type | Description |
|---|---|
array
|
The class center of each masked node, shape |
array
|
|
Source code in mlx_graphs/nn/models/rect.py
from mlx_graphs.nn import RECT_L · mlx_graphs/nn/models/rect.py