VGAE
¶
VGAE(encoder: Module, decoder: Optional[Module] = None)
Bases: GAE
The Variational Graph Auto-Encoder model from the "Variational Graph Auto-Encoders" paper.
The encoder returns a tuple (mu, logstd). In training mode,
encode() samples \(\mathbf{Z} = \mu + \epsilon \cdot
\exp(\log\sigma)\); in evaluation mode it returns \(\mu\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder
|
Module
|
The encoder module computing \(\mu\) and \(\log\sigma\). |
required |
decoder
|
Optional[Module]
|
The decoder module. Default: |
None
|
Example:
def loss_fn(model, edge_index, node_features):
z = model.encode(edge_index, node_features)
loss = model.recon_loss(z, edge_index)
return loss + model.kl_loss() / num_nodes
References
Methods:
| Name | Description |
|---|---|
reparametrize |
Samples latent variables in training mode, returns |
encode |
Runs the encoder and samples the latent node embeddings. |
kl_loss |
KL divergence between the latent distribution and a unit Gaussian. |
Source code in mlx_graphs/nn/models/autoencoder.py
reparametrize
¶
Samples latent variables in training mode, returns mu otherwise.
Source code in mlx_graphs/nn/models/autoencoder.py
encode
¶
Runs the encoder and samples the latent node embeddings.
Source code in mlx_graphs/nn/models/autoencoder.py
kl_loss
¶
KL divergence between the latent distribution and a unit Gaussian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mu
|
Optional[array]
|
\(\mu\). If |
None
|
logstd
|
Optional[array]
|
\(\log\sigma\). If |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The scalar loss, averaged over the nodes. |
Source code in mlx_graphs/nn/models/autoencoder.py
from mlx_graphs.nn import VGAE · mlx_graphs/nn/models/autoencoder.py