Equilibrium and non-equilibrium regimes in the learning of restricted Boltzmann machines