Discriminative Optimization: Theory and Applications to Computer Vision