Differentiating Metropolis-Hastings to Optimize Intractable Densities