Thermodynamics of Restricted Boltzmann Machines and Related Learning Dynamics