An efficient quantum algorithm for generative machine learning