Skip to content

Instantly share code, notes, and snippets.

@iperov
Last active October 30, 2023 07:22
Show Gist options
  • Save iperov/b2735b2ab09b9bf82fb5a00ed96f4ca4 to your computer and use it in GitHub Desktop.
Save iperov/b2735b2ab09b9bf82fb5a00ed96f4ca4 to your computer and use it in GitHub Desktop.
Latent Variables on Spheres for Autoencoders in High Dimensions
# pytorch implementation of
# Latent Variables on Spheres for Autoencoders in High Dimensions
# https://arxiv.org/pdf/1912.10233.pdf
# if implementation is wrong, please comment this gist
# x is (N, latent_size)
x = x - x.sum(-1, keepdim=True) / x.shape[-1]
x = x / torch.sqrt( (x**2).sum(-1, keepdim=True) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment