Learning a trajectory using adjoint functions and teacher forcing