Implement 1D convex minimization in Python
UberMachine Learning Engineer · Technical ScreenLast updated
An Uber Machine Learning Engineer technical-screen question on derivative-free 1D convex optimization: minimize a black-box convex function on a closed interval using only function evaluations. It tests method selection (golden-section vs ternary search), stopping criteria and tolerances, function-evaluation and time/space complexity analysis, and robust handling of flat regions, boundary optima, noisy evaluations, and numerical precision.
Question
Implement, in Python, an algorithm that minimizes a 1D black-box convex function F(x) over a closed interval [a, b]. Assume F is convex (hence unimodal) on [a, b], gradients are unavailable, and you may use only function evaluations.
Your answer should address all of the following:
- Method selection and justification. Choose an appropriate derivative-free method (e.g., golden-section search or ternary search) and justify the choice, especially with respect to the number of function evaluations each requires.
- Stopping criteria and tolerances. Specify your stopping rules (absolute/relative tolerance on the bracket width, an optional function-value tolerance, and a maximum-iteration / evaluation-budget guardrail).
- Complexity and function-evaluation count. Analyze time and space complexity and the number of function evaluations needed to reach a given tolerance.
- Robustness to edge cases. Explain how you handle:
- non-strict convexity and flat regions,
- boundary optima (the minimum at
aorb), - noisy function evaluations,
- numerical precision near machine epsilon, and invalid inputs.
- Working code. Provide a complete, runnable implementation.
- Testing and verification. Explain how you would test and verify correctness.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.