Use reproducible random starts and retain the best successful result:
rng = np.random.default_rng(2024)
starts = rng.uniform(-4, 4, size=100)
results = [opt.minimize(lambda z: f(z[0]), x0=[x0]) for x0 in starts]
successful = [result for result in results if result.success]
best = min(successful, key=lambda result: result.fun)
print(best.x[0], best.fun)Here an analytic check is possible. For , the envelope gives , above the candidate. On , . In the remaining interval , the derivative condition is equivalent, with , to . The left side decreases strictly from to while the right side increases, giving one minimum. This certifies the selected well as global rather than relying only on the restart experiment.
Random-restart optimization Created 2026-10-20 Updated 2026-11-05
Random-restart optimization repeatedly runs a local optimization algorithm from independently sampled starting points and retains the best result. It exploits multiple basins of attraction without requiring the local solver itself to escape a local extremum.
If each restart has probability of entering a desired basin, independent restarts miss it with probability after attempts. This formula quantifies the benefit only for the specified starting distribution and basin; neither nor a finite run certifies a global extremum. Recording the starting distribution and stopping rule makes computational comparisons reproducible.