Contextual Sequence Prediction with Application to Control Library Optimization