Stein's lemma and subsampling in large-scale optimization