A Machine Learning Approach to Optimal Control