Tree-based reparameterization for approximate inference on loopy graphs