mixle.doe.trust_region module¶
Trust-region Bayesian optimization (TuRBO, Eriksson et al. 2019) for higher-dimensional problems.
Global GP-BO degrades in high dimensions: one global surrogate is hard to fit and the acquisition is over-exploratory. TuRBO instead keeps a trust region – a box centered on the best point – and runs the BO only inside it, via Thompson sampling. The box side length grows after consecutive improvements and shrinks after consecutive failures; when it collapses, the search restarts from a fresh design. This local, self-tuning focus makes BO work for tens of dimensions where global EI stalls.
turbo_minimize() is the optimization loop (it calls your objective); TrustRegion is the
expand/shrink state if you want to drive the loop yourself. Both fit the torch GP surrogate.
- class TrustRegion(dim, length=0.8, length_min=0.0078125, length_max=1.6, success_tol=3, failure_tol=0)[source]
Bases:
objectExpand/shrink state of a TuRBO trust region (side length in normalized
[0, 1]^dcoordinates).The length doubles after
success_tolconsecutive improving batches and halves afterfailure_tolconsecutive non-improving ones;collapsedis True once it drops belowlength_minand the caller should restart.failure_toldefaults to the dimension (Eriksson 2019).__post_init__validates the complete region invariant (MXR-080-0196):dimis an exact positive integer;length,length_min, andlength_maxare finite with0 < length_min <= length <= length_max(so the region can never start collapsed, inverted, or unboundedly sized);success_tolis an exact positive integer andfailure_tolan exact non-negative one (0is the “default todim” sentinel resolved right below). Anything outside that invariant raises immediately instead of accepting geometry with no sensible search meaning – e.g. alength_max < length_minwould let a “successful” expansion (min(length * 2, length_max)) silently shrink the region, and a non-finite/non-positivelengthwould make every candidate box_tr_candidates()draws undefined or empty.- Parameters:
- property collapsed: bool
Return whether the trust-region length has shrunk below its usable minimum.
- update(improved)[source]
Return the next validated state after recording one batch outcome.
States are immutable: callers must retain the returned instance. This prevents a region that passed construction validation from later being assigned invalid geometry.
- Parameters:
improved (bool)
- Return type:
TrustRegion
- turbo_minimize(objective, bounds, *, n_init=None, max_evals=100, batch_size=1, maximize=False, n_candidates=None, seed=None, fit_kwargs=None)[source]
Optimize a black-box
objectiveoverboundswith TuRBO (trust-region BO).Starts from a Latin-hypercube design of
n_initpoints (default2*d), then repeatedly fits a GP on the normalized data, draws Thompson candidates inside the current trust region, evaluates the bestbatch_sizeof them, and resizes the region by success/failure. On collapse it restarts from a new design. Runs untilmax_evalsobjective calls.n_init(default2*d),max_evals,batch_size, andn_candidates(defaultmin(2000, 100*d)) must each be exact positive integers – none is silently truncated or coerced.max_evals >= n_initand1 <= batch_size <= n_candidatesare both required up front: the first because the initial design alone spendsn_initreal evaluations before any GP step can begin, the second because a batch can never select more distinct candidates than the trust region generates for it, no matter how many times it retries (MXR-080-0196).A well-defined numerical failure while fitting the local GP or sampling its joint posterior (a singular or indefinite covariance –
numpy/torchlinalg.LinAlgError) shrinks the trust region and retries next iteration, the same policy as an ordinary non-improving batch. Anything else (a configuration or programming bug – a badfit_kwargsoptimizer name, a missing torch install, …) propagates instead of being silently caught and relabeled “model failure” (MXR-080-0197).Returns
{'x', 'y', 'X', 'Y', 'n_restarts', 'n_bayes_batches', 'n_fit_failures', 'last_fit_error', 'degraded_to_random_search', 'stopped_reason'}: the best point/value and the full evaluation history; how many trust-region collapses restarted from a fresh Latin-hypercube design (n_restarts); how many batches were genuine GP-guided Thompson proposals (n_bayes_batches) versus caught numerical failures (n_fit_failures, with the most recent one’s diagnostic string inlast_fit_error, elseNone);degraded_to_random_searchis True iff every batch attempt failed numerically, meaning the entire result came from Latin-hypercube restarts and the GP-guided search never once ran; andstopped_reasonis always"budget_exhausted"(this loop’s only normal termination) for any call that returns rather than raises.