Approximate Inference by Compilation to Arithmetic Circuits