Algorithms for solving inverse problems using generative models