Latent space analysis and generalization to out-of-distribution data