Learning to Optimize Computational Resources: Frugal Training with Generalization Guarantees