An error analysis of generative adversarial networks for learning distributions