mixle.doe package¶
Design and analysis of computer experiments for mixle.
This package covers the full loop of reasoning about an expensive black-box model f(x) over a
bounded input space:
Designs – space-filling (Latin hypercube, maximin, Sobol’/Halton, MaxPro maximum-projection), classical factorial / fractional-factorial / Plackett-Burman / response-surface / mixture, and optimal designs (D/A/I/G/E/c criteria).
Bayesian optimization – the single-point acquisitions (EI/PI/UCB/Thompson/knowledge-gradient), plus the research frontier: rigorous Monte-Carlo q-EI and local-penalization batch design, Max-value Entropy Search, trust-region BO (TuRBO) for high dimensions, constrained and multi-objective BO, and cost-aware multi-fidelity BO.
Active learning & optimal design – sequential design to learn a surrogate (ALM / ALC-IMSE) or model parameters (expected information gain, closed-form and nested-Monte-Carlo).
Analysis – global sensitivity (Sobol’/Morris/FAST/DGSM), forward uncertainty propagation, and Kennedy-O’Hagan calibration to field data. (These were the standalone
mixle.uqpackage; folded in here they share this package’s quasi-Monte-Carlo sampling, GP surrogate, and kernels.)
The space-filling and classical design generators all return a plain (n, d) numpy matrix of
input points scaled into the supplied per-dimension bounds:
>>> from mixle.doe import latin_hypercube
>>> x = latin_hypercube([(0.0, 1.0), (-2.0, 2.0)], n=8, seed=0)
>>> x.shape
(8, 2)
- full_factorial(bounds, levels)[source]
Return a full-factorial grid design over
bounds.levelsis the number of evenly-spaced levels per dimension (a scalar applied to all dimensions, or one entry per dimension, each>= 1). The result hasprod(levels)rows in row-major (last axis fastest) order. A dimension with one level is placed at its midpoint.
- halton_design(bounds, n, seed=None, *, scramble=True)[source]
Return an
n-point Halton low-discrepancy design overbounds.Halton is a quasi-random sequence (coprime van der Corput sequences per axis) that, like Sobol’, fills space more evenly than iid uniform sampling and works for any
n(no power-of-two preference).scramble=Truerandomizes it reproducibly fromseed.
- latin_hypercube(bounds, n, seed=None, *, center=False)[source]
Return an
n-point Latin hypercube design overbounds.Each of the
daxes is partitioned intonequal strata and exactly one sample falls in each stratum (the defining LHS property), with the per-axis stratum assignments independently permuted. Withcenter=Trueeach sample sits at its stratum midpoint; otherwise it is drawn uniformly within the stratum.
- maximin_latin_hypercube(bounds, n, seed=None, *, trials=32)[source]
Return the best of
trialsLatin hypercube designs by the maximin criterion.Generates
trialsindependent LHS designs and keeps the one whose minimum pairwise (Euclidean, bound-normalized) distance is largest, a simple way to improve space-fillingness.
- maxpro_design(bounds, n, seed=None, *, restarts=3, swaps=1500, maxiter=300)[source]
Return a maximum-projection (MaxPro) space-filling design (Joseph, Gul & Ba 2015).
MaxPro minimizes
sum_{i<j} 1 / prod_k (x_ik - x_jk)^2, which forces the points to spread out in every subspace projection, not just the full space – the design of choice when only some inputs turn out to matter (factor screening / sloppy models), since the points stay space-filling even projected onto the active subset.Built by the paper’s two-stage procedure, repeated from
restartsLatin-hypercube starts: (1) a MaxProLHD coordinate-exchange phase (swapswithin-column swaps) finds a good basin while keeping the LHS structure, then (2) continuous L-BFGS-B optimization (analytic gradient,maxitersteps) moves the points off the grid to the true MaxPro optimum – the refinement that cuts the criterion by far more than the swap phase alone. The best design over restarts is returned as an(n, d)array.
- random_design(bounds, n, seed=None)[source]
Return
niid uniform points overboundsas an(n, d)array.
- sobol_design(bounds, n, seed=None, *, scramble=True)[source]
Return an
n-point Sobol’ low-discrepancy design overbounds.Sobol’ is a quasi-random sequence whose discrepancy (deviation from perfectly even coverage) is far lower than iid uniform sampling, so it fills the space more evenly for moderate
n.scramble=Trueapplies Owen scrambling, which randomizes the sequence reproducibly fromseedwhile preserving the low-discrepancy structure;scramble=Falsereturns the raw deterministic sequence. Balance properties are best whennis a power of two.
- fractional_factorial(bounds, generators, *, coded=False)[source]
Two-level fractional factorial
2**(k-p)from pyDOE-style generator strings.generatorsnames one column per factor as a product of base factors, e.g."a b c ab ac"– a2**(5-2)design whose factorsd, eare deliberately aliased asd = ab,e = ac. Base factors are the distinct single letters; each token is the elementwise product of its letters, optionally negated with a leading-. The number of tokens must equallen(bounds).Returns a
(2**k, d)design (k= number of base factors) mapped intobounds– or the raw coded+/-1matrix ifcoded=True.
- plackett_burman(bounds, *, coded=False)[source]
Plackett-Burman two-level screening design for
len(bounds)factors.Returns
Nruns whereNis the smallest multiple of four that is at leastd + 1(so the design is saturated or near-saturated, ideal for screening many factors in few runs). ForNa power of two the design is a Hadamard matrix (a resolution-III fractional factorial); forNin{12, 20, 24}a known cyclic generator is used; otherwiseNis rounded up to the next power of two so a design always exists. Main effects are mutually orthogonal but aliased with two-factor interactions – use it to find the few large effects, then follow up with a fuller design.
- central_composite(bounds, *, center=4, alpha='rotatable', coded=False)[source]
Central-composite design (CCD) for fitting a full second-order response surface.
A CCD stacks three parts: the
2**dtwo-level factorial corners (estimate linear and interaction terms),2*daxial / star points at distancealphaon each axis (estimate the pure-quadratic curvature), andcenterreplicates at the centre (estimate pure error and curvature).alphasets the axial distance:"rotatable"(default) –alpha = (2**d)**0.25, so prediction variance depends only on distance from the centre;"orthogonal"– the value making the second-order terms orthogonal (depends oncenter);"face"(a face-centred CCD / CCF) –alpha = 1, keeping every run inside the cube;a positive float – used directly.
Returns
(2**d + 2*d + center, d)rows mapped intobounds(or coded ifcoded=True).
- box_behnken(bounds, *, center=None, coded=False)[source]
Box-Behnken response-surface design (3 levels per factor, no corner runs).
For every pair of factors it runs the four
(+/-1, +/-1)combinations with all other factors at the centre, pluscentercentre replicates. Unlike a CCD it never sets all factors to an extreme at once (no cube corners), which is useful when those combinations are expensive or infeasible, and it needs only three levels per factor. Requiresd >= 3.Returns
(4 * C(d, 2) + center, d)rows mapped intobounds(or coded ifcoded=True).
- simplex_lattice(q, m)[source]
{q, m}simplex-lattice design forqmixture components.Each component takes one of the
m + 1evenly spaced proportions0, 1/m, ..., 1and the proportions in a blend sum to one. The design is exactly the set of such blends –C(q+m-1, m)points – and supports a degree-mScheffe mixture polynomial.Returns a
(C(q+m-1, m), q)array of blends (rows sum to 1).
- simplex_centroid(q)[source]
Simplex-centroid design for
qmixture components.Runs the centroid of every non-empty subset of components: the
qpure components, theC(q,2)binary 1/2:1/2 blends, … up to the overall centroid (all components at1/q) –2**q - 1blends in total. Supports the special cubic mixture model.Returns a
(2**q - 1, q)array of blends (rows sum to 1).
- to_pseudocomponents(blends, lower)[source]
Map canonical simplex blends onto pseudo-components with per-component lower bounds.
With lower bounds
l_i(summing to< 1), a constrained mixture’s feasible region is itself a smaller simplex; this maps a canonical blendxonto the real proportionsa_i = l_i + (1 - sum l) * x_i(the standard L-pseudocomponent transform), so any simplex design above can be run inside the constrained region. Rows still sum to 1.
- factorial_effects(design, y, *, interactions=True, coded=False)[source]
Estimate main effects and two-factor interactions from a two-level design.
Fits the linear model
y ~ 1 + x_i (+ x_i x_j)in coded+/-1units by least squares; the coefficients are half the classical effects.designis the(n, d)run matrix (the real factor levels, coded to+/-1automatically – or passcoded=Trueif it is already+/-1),ythe measured responses. Setinteractions=Falsefor a main-effects-only (e.g. screening) fit.
- class FactorialEffects(terms, coef, effects, intercept, residual_std)[source]
Bases:
objectEstimated effects from a two-level factorial / fractional-factorial / Plackett-Burman design.
- Parameters:
- coef
least-squares regression coefficients in coded
+/-1units.- Type:
- effects
the classical effect per term – the change in mean response as a factor moves from its low to its high level, i.e.
2 * coef(the intercept entry is just the grand mean).- Type:
- intercept
the grand mean of the response.
- Type:
- residual_std
residual standard deviation when the design has spare runs (else
None).- Type:
float | None
- coef: ndarray
- effects: ndarray
- intercept: float
- response_surface(x, y)[source]
Fit a full second-order (quadratic) response surface and analyse its stationary point.
Least-squares-fits
y = b0 + sum b_i x_i + sum_{i<=j} b_{ij} x_i x_jto the design runsx(n, d)and responsesy, then solves for the stationary pointx* = -1/2 B^{-1} band classifies it from the eigenvalues of the quadratic matrixB. Fit on the coded design for a well-conditioned model (the classic central-composite / Box-Behnken workflow).- Return type:
ResponseSurface
- class ResponseSurface(coef, terms, b, B, stationary_point, eigenvalues, kind, residual_std)[source]
Bases:
objectA fitted second-order response surface
y = b0 + b'x + x'Bxand its canonical analysis.- Parameters:
- coef
full coefficient vector (intercept, linears, then the upper-triangular second-order terms).
- Type:
- b
linear coefficient vector
(d,).- Type:
- B
symmetric
(d, d)matrix of quadratic coefficients (cross terms split onto both halves).- Type:
- stationary_point
x*solvinggrad = b + 2 B x = 0(least-squares ifBis singular).- Type:
- eigenvalues
eigenvalues of
B– all negative => the stationary point is a maximum, all positive => a minimum, mixed signs => a saddle (a ridge if some are ~0).- Type:
- kind
"maximum"/"minimum"/"saddle".- Type:
- residual_std
residual standard deviation when the design has spare runs (else
None).- Type:
float | None
- coef: ndarray
- b: ndarray
- B: ndarray
- stationary_point: ndarray
- eigenvalues: ndarray
- kind: str
- predict(x)[source]
Predict the response at points
x(m, d)from the fitted surface.- Return type:
- design_diagnostics(design, model, *, ref=None)[source]
Quality diagnostics for a design under a model – “is this a good design to run?”.
Builds the model matrix
F = model(design)and reports, relative to a hypothetical perfectly orthogonal design (where each is1.0):d_efficiency–det(M)**(1/p) / n: overall coefficient-estimation precision;a_efficiency–p / (n * trace(M^-1)): average coefficient variance;g_efficiency–p / (n * max prediction variance)overref(or the design itself);condition_numberofM(large => near-collinear / fragile to fit);max_correlation– the largest absolute pairwise correlation among the non-intercept model columns (the aliasing check;0for an orthogonal design).
modelis a model-matrix function such asmixle.doe.optimal.polynomial_features(). Use it on the coded design for meaningful efficiencies.- Return type:
- class OptimizationResult(x, y)[source]
Bases:
objectCommon outcome of a model-based optimization run: the full evaluation history.
xis the(N, d)matrix of evaluated points andythe corresponding objective values (an(N,)vector for single-objective runs, an(N, M)matrix for multi-objective). Concrete result types extend this with their best-point / Pareto-front fields.- x: ndarray
- y: ndarray
- class BayesOptResult(x, y, best_x, best_y)[source]
Bases:
OptimizationResultOutcome of a Bayesian-optimization run.
- best_x: ndarray
- best_y: float
- expected_improvement(mean, std, best, xi=0.0, *, maximize=False, **_)[source]
Return the expected-improvement acquisition at points with surrogate
meanandstd.For minimization the improvement over the incumbent
bestisbest - mean - xi; for maximization it ismean - best - xi.xi >= 0trades exploration for exploitation. Points with zero predictivestdget zero EI. Higher is better (maximized over candidates).
- knowledge_gradient(mean, cov, noise=1.0e-6)[source]
Knowledge-gradient acquisition value of one observation at each candidate (Frazier et al. 2009).
Given the Gaussian-process posterior
meanand jointcovover a candidate set, returns, for each candidatex, the expected increase in the best posterior mean after fantasizing one (noisy) observation there:KG(x) = E_y[max_x' mu_{n+1}(x')] - max_x' mu_n(x'). Maximizing KG is the one-step Bayes-optimal, look-ahead choice (it values information, not just immediate improvement), so it explores where an observation would most change the believed optimum. Assumes a maximization objective; negatemeanfor minimization. Computed exactly via the piecewise-linear epigraph of the fantasized posterior means, and>= 0by construction.
- propose_knowledge_gradient(x, y, bounds, *, maximize=False, n_candidates=512, seed=None, gp=None, fit_kwargs=None, noise=1.0e-6)[source]
Propose the next evaluation point by maximizing the knowledge gradient over a candidate set.
Fits the GP surrogate to
(x, y), drawsn_candidatesLatin-hypercube points, evaluates the joint posterior, and returns the candidate with the largestknowledge_gradient()– the look-ahead Bayesian-optimization proposal.maximizeselects the objective sense (the mean is negated for minimization).
- log_expected_improvement(mean, std, best, xi=0.0, *, maximize=False, **_)[source]
Return the log expected-improvement acquisition – a numerically stable EI (Ament et al. 2023).
Mathematically
log(EI), but computed so it stays finite and informative deep in the no-improvement tail whereEIitself underflows to 0 (andlog EIto-inf), keeping the optimizer’s ordering and gradients usable. Same argmax asexpected_improvement(); points with zero predictivestdget-inf. Higher is better. Thez >= 0branch is the direct well-conditioned form; thez < 0tail uses the scaled complementary error functionerfcx(Phi(z)/phi(z) = sqrt(pi/2) erfcx(-z/sqrt2)), which is bounded there and so never under/overflows.
- probability_of_improvement(mean, std, best, *, maximize=False, xi=0.0, **_)[source]
Return the probability-of-improvement acquisition.
The probability that a candidate improves on the incumbent
bestby at leastxi:P(f < best - xi)for minimization,P(f > best + xi)for maximization. Where the predictivestdis zero the improvement is deterministic (1.0 if it improves, else 0.0). Higher is better.
- upper_confidence_bound(mean, std, best=0.0, *, maximize=False, kappa=1.96, **_)[source]
Return the confidence-bound acquisition (UCB for maximization, LCB for minimization).
Returns a merit that is maximized over candidates: the optimistic bound
mean + kappa * stdwhen maximizing, andkappa * std - meanwhen minimizing (so picking the largest merit selects the most promising low-objective point).kappa >= 0trades exploration for exploitation;bestis ignored. Higher is better.
- thompson_sampling(mean, std, best=0.0, *, maximize=False, rng=None, **_)[source]
Thompson-sampling acquisition: one marginal posterior draw
N(mean, std)per candidate.Returns a merit (maximized over candidates) equal to the drawn value when maximizing and its negation when minimizing, so the selected point is the optimum of the sampled objective. A randomized, exploration-aware acquisition – repeated proposals explore competing optima in proportion to posterior probability, with no exploration knob to tune. This is the cheap marginal variant (independent per-candidate draws, ignoring the GP’s cross-candidate correlation); pass an
rng(viaacq_kwargs) for reproducible proposals.bestis ignored.
- register_acquisition(name, fn, aliases=())[source]
Register an acquisition
fnundername(and anyaliases).fnis called asfn(mean, std, best, *, maximize, **params)and must return a merit array that the proposal loop maximizes over candidates. This is the extension point for new acquisitions – registering is all that is needed, no edits topropose_next/minimize.
- available_acquisitions()[source]
Return the sorted names (and aliases) of all registered acquisitions.
- minimize(objective, bounds, n_init=5, n_iter=15, seed=None, *, maximize=False, xi=0.0, acq='ei', acq_kwargs=None, n_candidates=512, fit_kwargs=None)[source]
Run sequential GP Bayesian optimization of a scalar
objectiveoverbounds.Seeds with an
n_init-point Latin-hypercube design, then runsn_iteracquisition-driven steps usingacq("ei"by default; also"pi"/"ucb"or any registered acquisition). Minimizes by default; setmaximize=Trueto maximize.objectivetakes a(d,)point and returns a float.- Parameters:
- Return type:
BayesOptResult
- propose_next(x, y, bounds, n_candidates=512, seed=None, *, maximize=False, xi=0.0, acq='ei', acq_kwargs=None, gp=None, fit_kwargs=None, return_acquisition=False)[source]
Propose the next point to evaluate by maximizing an acquisition function.
Fits a GP to
(x, y), scoresn_candidatesLatin-hypercube points by theacqacquisition ("ei"/"pi"/"ucb"or any registered name / callable), and returns the best candidate (a(d,)array), optionally with its merit.xiis forwarded to acquisitions that use it (EI, PI); per-acquisition parameters such askappago inacq_kwargs.- Parameters:
- Return type:
- propose_batch(x, y, bounds, q, n_candidates=512, seed=None, *, maximize=False, xi=0.0, acq='ei', acq_kwargs=None, fit_kwargs=None)[source]
Propose a batch of
qpoints to evaluate together, via the kriging-believer heuristic.Each pick maximizes the acquisition; the GP posterior mean at the chosen point is then appended as a fantasized observation and the surrogate refit, so the next pick is steered away from it. Returns a
(q, d)array. This needs no true objective evaluations between picks, so it suits parallel/asynchronous experiment campaigns.
- optimal_design(bounds, n, *, candidates=None, model=None, criterion='D', n_candidates=256, n_restarts=5, max_iter=100, ref=None, seed=None)[source]
Return an
n-point optimal design selected from a candidate pool by Fedorov exchange.The pool is either generated as a Sobol design of
n_candidatespoints over per-dimensionbounds, or supplied directly as an(P, d)candidatesarray (in which caseboundsmay beNone).modelis a model-matrix function (defaultpolynomial_features()degree 1, i.e. linear with intercept);criterionselects the optimality merit ("D"/"A"/"I"or any registered name / callable). The best design overn_restartsrandom starts is returned as an(n, d)array. For"I"optimality, prediction variance is averaged overref(a model matrix) when given, else over the candidate pool.Raises if
nis below the number of model parameters (the information matrix would be singular).
- polynomial_features(degree=1, *, bias=True)[source]
Return a model-matrix function building polynomial features up to
degree(with interactions).The returned
f(X)maps an(n, d)point array to an(n, p)model matrix: an optional intercept column, then every monomialprod(x_j)over index multisets of size1..degree(sodegree=1is linear,degree=2is a full quadratic response surface including the cross termsx_i x_j).
- d_criterion(info, *, ref=None)[source]
D-optimality merit:
log det M(-infifMis singular). Higher is better.
- a_criterion(info, *, ref=None)[source]
A-optimality merit:
-trace(M^{-1})(-infif singular). Higher is better.
- i_criterion(info, *, ref=None)[source]
I-optimality merit:
-meanprediction variance overref(-infif singular).The prediction variance at a reference row
gisg M^{-1} g; this returns the negative mean over the reference model matrixrefso larger is better. Falls back to A-optimality when no reference set is supplied.
- g_criterion(info, *, ref=None)[source]
G-optimality merit:
-maxprediction variance overref(-infif singular).Where I-optimality minimizes the average prediction variance, G-optimality minimizes its worst case over the reference region, so the fitted surface has a bounded error everywhere. Returns the negative maximum of
g M^{-1} gover the reference rows (falls back to the largest coefficient variancemax diag(M^{-1})when no reference set is given).
- e_criterion(info, *, ref=None)[source]
E-optimality merit: the smallest eigenvalue of
M(higher is better).Maximizing the minimum eigenvalue of the information matrix shrinks the variance along the worst-determined parameter contrast, so no direction in coefficient space is left poorly estimated.
0for a singular (rank-deficient) design.
- c_criterion(c)[source]
Return a c-optimality criterion targeting the linear combination
c'.betaof coefficients.c-optimality minimizes the variance of a specific quantity of interest
c'.beta(e.g. a contrast or a prediction at one point). The returned criterion has merit-c' M^{-1} c(-infif singular), so it plugs straight intooptimal_design()orregister_criterion().- Parameters:
c (ndarray)
- Return type:
Criterion
- register_criterion(name, fn, aliases=())[source]
Register an optimality criterion
fnundername(and anyaliases).fnis called asfn(info, *, ref)with the information matrixM = F.T @ Fand must return a merit thatoptimal_design()maximizes. This is the extension point for new criteria – registering is all that is needed, no edits to the exchange loop.
- available_criteria()[source]
Return the sorted names (and aliases) of all registered optimality criteria.
- class ConstrainedBayesOptResult(x, y, best_x, best_y, c, feasible)[source]
Bases:
BayesOptResultOutcome of a constrained Bayesian-optimization run.
cholds the(N, K)observed constraint values (feasible rows have all entries<= 0) andfeasibleis the corresponding boolean mask.best_x/best_yare the best feasible point; if no feasible point was found they fall back to the least-infeasible observation.- c: ndarray
- feasible: ndarray
- probability_of_feasibility(mean, std)[source]
Return the per-point probability that all constraints are satisfied (
c_k <= 0).meanandstdare(n, K)posterior predictive moments of theKconstraint surrogates. Returns an(n,)array, the product over constraints ofPhi(-mean_k / std_k). Where a constraint’sstdis zero the feasibility is deterministic (1.0 ifmean <= 0).
- propose_next_constrained(x, y, c, bounds, n_candidates=512, seed=None, *, maximize=False, xi=0.0, acq='ei', acq_kwargs=None, fit_kwargs=None, return_acquisition=False)[source]
Propose the next point under inequality constraints
c_k(x) <= 0.Fits a GP to the objective
(x, y)and one GP per constraint column ofc(an(N, K)array), then maximizes the feasibility-weighted acquisition overn_candidatesLatin-hypercube points. Until a feasible observation exists the acquisition factor is held at 1 so the search targets feasibility; afterwards the incumbent is the best feasible objective. Returns the chosen(d,)point, optionally with its merit.- Parameters:
- Return type:
- constrained_minimize(objective, constraints, bounds, n_init=5, n_iter=15, seed=None, *, maximize=False, xi=0.0, acq='ei', acq_kwargs=None, n_candidates=512, fit_kwargs=None)[source]
Constrained GP Bayesian optimization of
objectivesubject toconstraintsoverbounds.Each callable in
constraintsmaps a(d,)point to a scalar that is feasible when<= 0. Seeds with ann_init-point Latin-hypercube design, then runsn_iterfeasibility-weighted acquisition steps. Minimizes the objective by default; returns the best feasible point (or the least-infeasible one if none feasible) along with the full evaluation history.
- class MultiObjectiveResult(x, y, pareto_mask, pareto_x, pareto_y)[source]
Bases:
OptimizationResultOutcome of a multi-objective Bayesian-optimization run.
yis the(N, M)matrix of observed objective vectors (all minimized);pareto_maskflags the non-dominated rows, andpareto_x/pareto_yare those points and their objective vectors.- pareto_mask: ndarray
- pareto_x: ndarray
- pareto_y: ndarray
- pareto_mask(y)[source]
Return a boolean mask of the non-dominated rows of
y(an(N, M)minimization objective).Row
iis dominated when some other row is<=it on every objective and strictly<on at least one; the mask isTruefor the rows that survive (the Pareto-optimal set).
- multi_minimize(objectives, bounds, n_init=10, n_iter=20, seed=None, *, rho=0.05, n_candidates=512, fit_kwargs=None)[source]
Multi-objective GP Bayesian optimization of
objectivesoverbounds(ParEGO).Each callable in
objectivesmaps a(d,)point to a scalar; all are minimized. Seeds with ann_init-point Latin-hypercube design, then runsn_itersteps, each drawing a random Tchebycheff weighting, scalarizing the observed objectives, and taking one GP-EI step on that scalar. Returns the full evaluation history and the Pareto-optimal subset.
- class BayesianOptimizer(bounds, *, acq='ei', acq_kwargs=None, maximize=False, n_init=None, xi=0.0, n_candidates=512, fit_kwargs=None, seed=None)[source]
Bases:
objectStateful ask-tell wrapper around the GP Bayesian-optimization loop.
askproposes the next point (or a batch),tellrecords evaluated observations, andbestreturns the incumbent. Minimizes by default; setmaximize=Trueto maximize. The acquisition is selected byacq("ei"/"pi"/"ucb"or any registered name / callable) with per-acquisition parameters inacq_kwargs.- Parameters:
- property x: ndarray
Return the observed points as an
(N, d)array.
- property y: ndarray
Return the observed objective values as an
(N,)array.
- property n_observations: int
Return the number of recorded observations.
- property best: BayesOptResult
Return the incumbent (best observed point) as a
BayesOptResult.
- ask(q=1)[source]
Return the next point to evaluate as a
(d,)array, or a(q, d)batch whenq > 1.The first
n_initpoints come from a space-filling design; subsequent points are GP acquisition proposals (a kriging-believer batch whenq > 1).
- monte_carlo_qei(mean, cov, best, *, maximize=False, samples=512, seed=0)[source]
Monte-Carlo multi-point Expected Improvement of a batch with joint posterior
N(mean, cov).Draws
samplesjoint posterior realizations of theqbatch points and averages the batch improvement over the incumbentbest–max(best - min_i f_i, 0)for minimization, ormax(max_i f_i - best, 0)for maximization. Forq = 1this reduces to ordinary EI.
- propose_qei_batch(x, y, bounds, q, *, n_candidates=256, mc_samples=256, maximize=False, seed=None, gp=None, fit_kwargs=None)[source]
Propose a
q-point batch by greedy Monte-Carlo q-EI under the joint GP posterior.Fits the GP to
(x, y), then builds the batch one point at a time: each new point is the Latin-hypercube candidate maximizing the q-EI of{batch so far} + candidate(evaluated with common random numbers so the greedy comparison is fair). Because the joint posterior is used, an already-chosen point lowers the marginal value of nearby candidates, so the batch self-diversifies without any fantasized observations. Returns a(q, d)array.
- propose_local_penalization(x, y, bounds, q, *, n_candidates=512, maximize=False, seed=None, gp=None, fit_kwargs=None)[source]
Propose a
q-point batch by local penalization (Gonzalez et al. 2016).Picks points sequentially from a single GP fit (no refitting): each pick maximizes the expected improvement multiplied by a soft exclusion factor around every pending pick. The exclusion radius is set from a Lipschitz estimate
Lof the objective (the largest posterior-mean gradient over the candidates) and the gap to the incumbent, so the penalty is principled rather than a fixed distance. Cheaper than q-EI for largeq(one GP fit, closed-form penalties). Returns a(q, d)array.
- max_value_entropy_search(mean, std, max_samples, *, maximize=True)[source]
Max-value Entropy Search acquisition at candidates with posterior
mean/std.Given samples
max_samplesof the global optimum valuey*, returns the per-candidate mutual informationI(y; y*) = (1/M) sum_m [ gamma_m phi(gamma_m)/(2 Phi(gamma_m)) - log Phi(gamma_m) ]withgamma_m = (y*_m - mu)/sd(maximization; for minimization the sense is flipped by the caller). Higher is better – it favors uncertain candidates near the believed optimum.
- sample_max_values(mean, std, n_samples=64, *, seed=0)[source]
Sample plausible global-max values
y*via the Gumbel approximation (Wang & Jegelka 2017).The CDF of the maximum over the candidate cloud is
P(max <= y) = prod_i Phi((y - mu_i)/sd_i); a Gumbel is fit to its 25/50/75 percentiles (found by bisection) and sampled. Returns an(n_samples,)array ofy*draws (never below the best posterior mean).
- propose_mes(x, y, bounds, *, n_candidates=512, max_samples=64, maximize=False, seed=None, gp=None, fit_kwargs=None)[source]
Propose the next point by Max-value Entropy Search.
Fits the GP to
(x, y), samplesmax_samplesoptimum values viasample_max_values(), scores Latin-hypercube candidates bymax_value_entropy_search(), and returns the maximizer as a(d,)array.maximizeselects the optimization sense (default minimize, matching the rest of the BO layer).
- 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. Returns{'x', 'y', 'X', 'Y', 'n_restarts'}with the best point/value and the full history.
- class TrustRegion(dim, length=0.8, length_min=0.0078125, length_max=1.6, success_tol=3, failure_tol=0, _success=0, _failure=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).- Parameters:
- dim: int
- length: float = 0.8
- length_min: float = 0.0078125
- length_max: float = 1.6
- success_tol: int = 3
- failure_tol: int = 0
- property collapsed: bool
- alm_scores(gp, x, y, candidates)[source]
Active Learning MacKay scores: the GP posterior predictive variance at each candidate.
- alc_scores(gp, x, y, candidates, reference)[source]
Active Learning Cohn / IMSE scores: integrated posterior-variance reduction per candidate.
Adding candidate
creduces the posterior variance at a reference pointrbycov_post(r, c)^2 / var_post(c); this returns the sum over the reference set (the negative change in integrated MSE), so the maximizer is the most globally informative next point.
- propose_active_learning(x, y, bounds, *, method='alc', n_candidates=512, n_reference=256, seed=None, gp=None, fit_kwargs=None)[source]
Propose the next active-learning point (
method='alc'IMSE, or'alm'max variance).
- active_learning_design(objective, bounds, *, n_init=None, max_evals=40, method='alc', seed=None, fit_kwargs=None)[source]
Sequentially place points to maximize surrogate accuracy, returning the design and its responses.
Starts from a Latin-hypercube design, then repeatedly fits the GP and adds the most informative point (by
method) untilmax_evalsevaluations. Returns{'X', 'Y'}– a design tailored to learnobjectivewell everywhere, not just near an optimum.
- expected_information_gain_linear(model_matrix, *, noise=1.0, prior_cov=None)[source]
Exact expected information gain of a linear-Gaussian design
y = F.theta + eps(= Bayesian D-opt).For a Gaussian prior
theta ~ N(0, Sigma0)and observation noiseeps ~ N(0, noise^2 I), the mutual information between the data andthetais0.5 * log det(I + noise^-2 Sigma0 F^T F).model_matrixis the(n, p)design matrixF(e.g. frommixle.doe.optimal.polynomial_features()). Higher EIG = a more informative design.
- expected_information_gain_nmc(prior_sampler, log_likelihood, simulate, *, n_outer=256, n_inner=256, seed=None)[source]
Nested-Monte-Carlo expected information gain for a general (nonlinear) design.
Estimates
EIG = E_{theta, y}[ log p(y|theta) - log E_{theta'}[p(y|theta')] ](Ryan 2003): draw outertheta_i ~ priorandy_i ~ p(y|theta_i)viasimulate; the inner expectation is a mean overn_innerprior draws ofexp(log_likelihood(theta', y_i)).prior_sampler(rng, n)returns(n, k)parameter draws;log_likelihood(thetas, y)returns a log-density per row ofthetasat the single observationy;simulate(theta, rng)draws oneygiventheta.
- multi_fidelity_minimize(objective, bounds, *, fidelities=(0.5, 1.0), costs=None, target=None, n_init=None, max_cost=40.0, n_candidates=256, maximize=False, seed=None, fit_kwargs=None)[source]
Cost-aware multi-fidelity Bayesian optimization of
objective(x, s).objective(x, s)returns the response at inputxand fidelitys(one offidelities); the largest fidelity (ortarget) is the true objective.costsis the per-fidelity evaluation cost (default: the fidelity value itself). The loop fits a GP over[x, s], proposesxby Expected Improvement at the target fidelity, then evaluates at the fidelity maximizing target-variance reduction per unit cost, until the cumulative cost reachesmax_cost. Returns{'x', 'y', 'X', 'Y', 'cost'}– the best target-fidelity point and the full augmented history.
- sobol_indices(func, bounds, n=4096, *, seed=0, names=None)[source]
First- and total-order Sobol sensitivity indices (Saltelli sampling, Jansen estimators).
- Parameters:
func (Callable[[ndarray], ndarray]) – a vectorized model
f(X) -> ymapping an(m, d)array of inputs to an(m,)array of scalar outputs.bounds (Sequence[tuple[float, float]]) –
[(lo, hi), ...]per input – the input is taken uniform on the box.n (int) – base sample size; the total number of model evaluations is
n * (d + 2).seed (int) – RNG seed for the (Sobol) base samples.
names (Sequence[str] | None) – optional input names for the returned dict.
- Returns:
{'S1': (d,), 'ST': (d,), 'names': [...], 'var': float}– first-orderS1[i]is the fraction of output variance from inputialone; total-orderST[i]includes all interactions involvingi(soST[i] - S1[i]measuresi’s interaction strength, andST[i] ~ 0means inputican be fixed).- Return type:
- morris_screening(func, bounds, *, trajectories=20, levels=4, seed=0, names=None)[source]
Morris elementary-effects screening – a cheap first factor ranking.
Walks
trajectoriesone-factor-at-a-time paths on alevels-grid; the mean absolute elementary effectmu_star[i]ranks influence and the spreadsigma[i]flags nonlinearity/interactions. Cost:trajectories * (d + 1)evaluations – far fewer than Sobol, for an initial screen.
- fast_indices(func, bounds, n=600, *, harmonics=6, seed=0, names=None)[source]
First-order sensitivity indices via Random Balance Designs FAST (RBD-FAST).
A Fourier alternative to
sobol_indices()for the first-order indices: every input is driven along the same triangle-wave search curve but under an independent random permutation, the model is evaluated once over thenpoints, and for each input the output – reordered along that input’s curve – has its variance concentrated at the base frequency’s firstharmonicsharmonics. The ratio of that power to the total is the first-order index (with the Tarantola bias correction). Cost is a single batch ofnevaluations, independent of dimension.Returns
{'S1': (d,), 'names': [...], 'var': float}.
- dgsm(func, bounds, n=1024, *, seed=0, rel_step=1.0e-4, names=None)[source]
Derivative-based global sensitivity measures (DGSM): mean squared partial derivatives.
nu[i] = E[(df/dx_i)^2]over the input box, estimated by central finite differences atnlow-discrepancy points. Unlike the first-order Sobol index, a DGSM is nonzero whenever an input matters anywhere – including purely through interactions – so it is a cheap, robust screen that upper-bounds the total Sobol index (Sobol & Kucherenko, via the Poincare inequality:ST[i] <= (L_i / pi)^2 * nu[i] / Var(y)for a uniform input of widthL_i). The reportedimportanceisL_i^2 * nu[i]normalized to sum to one – a dimensionless influence ranking.Returns
{'nu': (d,), 'importance': (d,), 'names': [...]}.
- propagate(func, mean, cov=None, *, n=10000, method='montecarlo', quantiles=(0.05, 0.5, 0.95), seed=0)[source]
Propagate a Gaussian input
N(mean, cov)throughfuncto output statistics.- Parameters:
func (Callable[[ndarray], ndarray]) – a vectorized model
f(X) -> ymapping(m, d)inputs to(m,)(or(m, k)) outputs.mean (ndarray) – length-
dinput mean.cov:(d, d)input covariance (defaults to identity).n (int) – Monte Carlo sample size (ignored by the unscented method).
method (str) –
'montecarlo'(sample + summarize, gives quantiles) or'unscented'(sigma-point moment propagation, mean + std only). Looked up through the propagator registry.quantiles (tuple[float, ...]) – output quantiles to report (Monte Carlo only).
cov (ndarray | None)
seed (int)
- Returns:
{'mean', 'std', 'quantiles' (mc only), 'samples' (mc only)}.- Return type:
- register_propagator(name)[source]
Decorator registering a propagation method under
nameforpropagate().The decorated callable receives
(func, mean, cov, *, n, quantiles, seed)(mean/covalready coerced to float arrays) and returns the output-statistics dict.
- unscented_transform(func, mean, cov, *, alpha=1e-3, beta=2.0, kappa=0.0)[source]
Propagate
(mean, cov)throughfuncwith the unscented (sigma-point) transform.Returns the output
(mean, covariance). Exact for an affinefunc; for a nonlinear one it captures the mean and covariance to second order with only2d+1evaluations.
- calibrate(simulator, x, y, theta0, *, discrepancy=True, discrepancy_lengthscale=None, seed=0, max_iter=300)[source]
Calibrate
simulator(x, theta)to field data(x, y)with a GP discrepancy term.Maximizes the marginal likelihood of the residual
r(theta) = y - eta(x, theta)under a GP + noise model, overthetaand the discrepancy amplitude + noise.discrepancy=Falsedrops the GP (plain nonlinear least squares) – useful to show the bias the discrepancy removes.The discrepancy correlation length is fixed (
discrepancy_lengthscale, default 10% of the input domain) rather than fitted: this is the standard resolution of the Kennedy-O’Hagantheta/deltaidentifiability problem – a short discrepancy length forces the GP to model only local model-form error, leaving the smooth global trend to the parametric simulator sothetastays identifiable. Set it to the scale of model error you expect.- Parameters:
simulator (Callable[[ndarray, ndarray], ndarray]) –
eta(x, theta) -> predictions(vectorized over the rows ofx).x (ndarray) – field inputs and observations.
y (ndarray) – field inputs and observations.
theta0 (Sequence[float]) – initial calibration parameters (its length sets the parameter count).
discrepancy (bool) – include the GP discrepancy term (the Kennedy-O’Hagan model).
discrepancy_lengthscale (float | None) – fixed GP correlation length (default: 10% of the input domain).
seed (int)
max_iter (int)
- Return type:
KOCalibration
- class KOCalibration(theta, ls, amp, noise, simulator, x, y)[source]
Bases:
objectResult of
calibrate(): the fitted parameters, discrepancy GP, and a calibrated predictor.- predict(x_new, *, with_discrepancy=True)[source]
Calibrated prediction at
x_new: simulator at the fittedtheta, plus the GP discrepancy (the bias-corrected estimate of reality) unlesswith_discrepancy=False(the pure simulator).
Submodules¶
- mixle.doe.active module
- mixle.doe.analysis module
- mixle.doe.batch module
- mixle.doe.bayesopt module
- mixle.doe.calibrate module
- mixle.doe.constrained module
- mixle.doe.designs module
- mixle.doe.entropy module
- mixle.doe.factorial module
- mixle.doe.mixture module
- mixle.doe.multifidelity module
- mixle.doe.multiobjective module
- mixle.doe.optimal module
- mixle.doe.optimizer module
- mixle.doe.propagate module
- mixle.doe.sensitivity module
- mixle.doe.trust_region module