Optimizing neural networks via Koopman operator theory