Skip to content

ARGA

ARGA(encoder: Module, discriminator: Module, decoder: Optional[Module] = None)

Bases: GAE

The Adversarially Regularized Graph Auto-Encoder model from the "Adversarially Regularized Graph Autoencoder for Graph Embedding" paper.

Parameters:

Name Type Description Default
encoder Module

The encoder module.

required
discriminator Module

The discriminator module, mapping latent embeddings to one logit per node.

required
decoder Optional[Module]

The decoder module. Default: InnerProductDecoder

None

Methods:

Name Description
reg_loss

Regularization loss of the encoder: fooling the discriminator.

discriminator_loss

Loss of the discriminator, telling Gaussian samples (real) from

Source code in mlx_graphs/nn/models/autoencoder.py
def __init__(
    self,
    encoder: nn.Module,
    discriminator: nn.Module,
    decoder: Optional[nn.Module] = None,
):
    super().__init__(encoder, decoder)
    self.discriminator = discriminator

reg_loss

reg_loss(z: array) -> array

Regularization loss of the encoder: fooling the discriminator.

Parameters:

Name Type Description Default
z array

The latent space \(\mathbf{Z}\)

required
Source code in mlx_graphs/nn/models/autoencoder.py
def reg_loss(self, z: mx.array) -> mx.array:
    """Regularization loss of the encoder: fooling the discriminator.

    Args:
        z: The latent space :math:`\\mathbf{Z}`
    """
    real = mx.sigmoid(self.discriminator(z))
    return -mx.log(real + EPS).mean()

discriminator_loss

discriminator_loss(z: array) -> array

Loss of the discriminator, telling Gaussian samples (real) from latent embeddings (fake). No gradient flows into z.

Parameters:

Name Type Description Default
z array

The latent space \(\mathbf{Z}\)

required
Source code in mlx_graphs/nn/models/autoencoder.py
def discriminator_loss(self, z: mx.array) -> mx.array:
    """Loss of the discriminator, telling Gaussian samples (real) from
    latent embeddings (fake). No gradient flows into ``z``.

    Args:
        z: The latent space :math:`\\mathbf{Z}`
    """
    real = mx.sigmoid(self.discriminator(mx.random.normal(z.shape)))
    fake = mx.sigmoid(self.discriminator(mx.stop_gradient(z)))
    real_loss = -mx.log(real + EPS).mean()
    fake_loss = -mx.log(1 - fake + EPS).mean()
    return real_loss + fake_loss

from mlx_graphs.nn import ARGA · mlx_graphs/nn/models/autoencoder.py