Theory and computation for structured variational inference