Adaptive sequential optimization with applications to machine learning