Optimal Control For Learning With Applications In Dynamic Mri