Gradient and Hamiltonian Dynamics Applied to Learning in Neural Networks