Variational approximations for stochastic dynamics on graphs