GAE
¶
GAE(encoder: Module, decoder: Optional[Module] = None)
Bases: Module
The Graph Auto-Encoder model from the "Variational Graph Auto-Encoders" paper, based on user-defined encoder and decoder models.
The decoder is called as decoder(edge_index, z, sigmoid=...), like
InnerProductDecoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder
|
Module
|
The encoder module, mapping its inputs (e.g. |
required |
decoder
|
Optional[Module]
|
The decoder module. Default: |
None
|
Example:
import mlx.core as mx
import mlx.nn as nn
import mlx.optimizers as optim
from mlx_graphs.nn import GAE, GCN
model = GAE(GCN(node_features_dim, 32, num_layers=2, out_features_dim=16))
optimizer = optim.Adam(learning_rate=0.01)
def loss_fn(model, edge_index, node_features):
z = model.encode(edge_index, node_features)
return model.recon_loss(z, edge_index)
loss_and_grad = nn.value_and_grad(model, loss_fn)
loss, grads = loss_and_grad(model, edge_index, node_features)
optimizer.update(model, grads)
z = model.encode(edge_index, node_features)
auc, ap = model.test(z, test_pos_edge_index, test_neg_edge_index)
References
Methods:
| Name | Description |
|---|---|
__call__ |
Alias for |
encode |
Runs the encoder and computes the latent node embeddings. |
decode |
Runs the decoder and computes edge probabilities. |
recon_loss |
Binary cross entropy of the reconstruction of positive edges and of |
test |
Computes the area under the ROC curve (AUC) and the average |
Source code in mlx_graphs/nn/models/autoencoder.py
__call__
¶
encode
¶
decode
¶
recon_loss
¶
recon_loss(
z: array, pos_edge_index: array, neg_edge_index: Optional[array] = None
) -> array
Binary cross entropy of the reconstruction of positive edges and of negative edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
array
|
The latent space \(\mathbf{Z}\) |
required |
pos_edge_index
|
array
|
The positive edges to train against |
required |
neg_edge_index
|
Optional[array]
|
The negative edges to train against. If |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The scalar loss. |
Source code in mlx_graphs/nn/models/autoencoder.py
test
¶
Computes the area under the ROC curve (AUC) and the average precision (AP) of the predictions for positive and negative edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
array
|
The latent space \(\mathbf{Z}\) |
required |
pos_edge_index
|
array
|
The positive edges to evaluate against |
required |
neg_edge_index
|
array
|
The negative edges to evaluate against |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
A tuple |
Source code in mlx_graphs/nn/models/autoencoder.py
from mlx_graphs.nn import GAE · mlx_graphs/nn/models/autoencoder.py