Skip to content

Instantly share code, notes, and snippets.

@iperov
iperov / gist:b2735b2ab09b9bf82fb5a00ed96f4ca4
Last active October 30, 2023 07:22
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) )