Computer experiments

Computer experiments define the input domain and output structure of an objective, constraint, or multi-output simulator. They are plain Python objects that evaluate user callables and return numerical backend-compatible arrays.

ComputerExperiment

class ComputerExperiment(input_dim, input_box, *, single_function=None, function_list=None, single_objective=None, objective_list=None, single_constraint=None, constraint_list=None, constraint_bounds=None)

Define a deterministic computer experiment.

input_dim is the input dimension d. input_box can have shape (2, d) with lower and upper rows or shape (d, 2) with one (lower, upper) row per coordinate. Bounds must be finite and upper bounds must be larger than lower bounds. The object stores the box with shape (2, d).

A function specification can be a callable or a dictionary. Dictionary keys include:

  • "function": callable accepting x with shape (n, d).

  • "output_dim": number of outputs from that callable.

  • "type": "objective", "constraint", or a list of such labels.

  • "bounds": feasibility bounds for constraint outputs.

Use either combined functions through single_function or function_list, or separated objectives and constraints through single_objective, objective_list, single_constraint, and constraint_list.

eval(x, *, normalize_input=None)

Evaluate all outputs. x has shape (n, d) or (d,). Returns a NumPy array with shape (n, output_dim). When normalize_input is true, x is interpreted in [0, 1]^d and mapped to the physical input box before evaluation.

eval_objectives(x, *, normalize_input=None)

Evaluate objective outputs only. Returns shape (n, n_objectives). Returns an empty second dimension when no objective is registered.

eval_constraints(x, *, normalize_input=None)

Evaluate constraint outputs only. Returns shape (n, n_constraints). Returns an empty second dimension when no constraint is registered.

The object caches the last deterministic evaluation. It raises ValueError for invalid input boxes, mutually exclusive construction paths, incompatible output dimensions, missing constraint bounds, or input arrays with the wrong shape.

StochasticComputerExperiment

class StochasticComputerExperiment(input_dim, input_box, *, single_function=None, function_list=None, single_objective=None, objective_list=None, single_constraint=None, constraint_list=None, simulated_noise_variance=None)

Extend ComputerExperiment with additive Gaussian output noise.

simulated_noise_variance can be a scalar or a list with one variance per output. Per-function dictionaries may also contain "simulated_noise_variance".

eval(x, *, simulate_noise=True, batch_size=1, rng=None)

Evaluate all outputs. With batch_size=1, returns a NumPy array with shape (n, output_dim). With batch_size > 1, returns shape (n, output_dim, batch_size). rng can be a numpy.random.Generator for reproducible noise draws.

Stochastic evaluations do not use the deterministic cache. The eval_objectives and eval_constraints shortcuts are not supported for stochastic experiments because repeated calls would draw different noise.

Multi-output deterministic or stochastic computer experiments.

Author: Emmanuel Vazquez <emmanuel.vazquez@centralesupelec.fr> Copyright (c) 2022-2026, CentraleSupelec License: GPLv3 (see LICENSE)

class gpmpcontrib.computerexperiment.ComputerExperiment(input_dim, input_box, *, single_function=None, function_list=None, single_objective=None, objective_list=None, single_constraint=None, constraint_list=None, constraint_bounds=None)[source]

Bases: object

Represent a multi-output computer experiment evaluating objectives and constraints.

You can supply either:
  • a combined function (or list of functions) via single_function / function_list, whose outputs are tagged with types, or

  • separate objectives and constraints via single_objective/objective_list and single_constraint/constraint_list.

Input domain (input_box) is accepted as either shape (2, d) [lower, upper] or (d, 2) [(l1, u1), …, (ld, ud)]. Internally it is stored as (2, d).

Parameters:
  • input_dim (int) – Dimension of the input space.

  • input_box (array-like) – Either (2, d) or (d, 2). Bounds must be finite with upper > lower per dimension.

  • single_function (FuncSpec or list[FuncSpec], optional) –

    Combined function(s). Dict entries may include:
    • ”function”: callable(X) -> (n, p_i) or (n,)

    • ”output_dim”: int (default 1)

    • ”type”: list[str] of length output_dim with values in {“objective”,”constraint”}

    • ”bounds”: list[Bounds] or Bounds for constraints per output. Use None for objectives.

  • function_list (FuncSpec or list[FuncSpec], optional) –

    Combined function(s). Dict entries may include:
    • ”function”: callable(X) -> (n, p_i) or (n,)

    • ”output_dim”: int (default 1)

    • ”type”: list[str] of length output_dim with values in {“objective”,”constraint”}

    • ”bounds”: list[Bounds] or Bounds for constraints per output. Use None for objectives.

  • single_objective (FuncSpec or list[FuncSpec], optional) – Objective function(s). Dict like above. “type” defaults to “objective”.

  • objective_list (FuncSpec or list[FuncSpec], optional) – Objective function(s). Dict like above. “type” defaults to “objective”.

  • single_constraint (FuncSpec or list[FuncSpec], optional) – Constraint function(s). Dict like above. Provide bounds if not set via constraint_bounds.

  • constraint_list (FuncSpec or list[FuncSpec], optional) – Constraint function(s). Dict like above. Provide bounds if not set via constraint_bounds.

  • constraint_bounds (list[Bounds], optional) – Global bounds to attach to constraint functions provided without “bounds”. Length must match total number of constraint outputs.

Raises:

ValueError – If incompatible inputs are provided or shapes are inconsistent.

Notes

  • normalize_input: if True, eval assumes x ∈ [0,1]^d and scales to the physical box. You can also override per-call via eval(…, normalize_input=True/False).

eval(x, *, normalize_input=None)[source]

Evaluate all outputs at x.

Parameters:
  • x (array-like) – Shape (n, d) or (d,). If 1D, it is reshaped to (1, d).

  • normalize_input (Optional[bool]) – Per-call override. None = use object-level setting.

Returns:

Shape (n, output_dim).

Return type:

ndarray

eval_constraints(x, *, normalize_input=None)[source]
Parameters:
  • x (ndarray | Sequence[float])

  • normalize_input (bool | None)

Return type:

ndarray

eval_objectives(x, *, normalize_input=None)[source]
Parameters:
  • x (ndarray | Sequence[float])

  • normalize_input (bool | None)

Return type:

ndarray

get_constraint_bounds()[source]

Array of bounds (or None) for outputs whose type == ‘constraint’.

Return type:

ndarray

get_output_bounds()[source]

List of (lb, ub) or None per output, aligned with columns of eval result.

Return type:

List[Tuple[float, float] | None]

get_output_types()[source]

List of output types aligned with columns of eval result.

Return type:

List[str]

property normalize_input: bool

Whether inputs are normalized to [0,1]^d before evaluation.

class gpmpcontrib.computerexperiment.StochasticComputerExperiment(input_dim, input_box, *, single_function=None, function_list=None, single_objective=None, objective_list=None, single_constraint=None, constraint_list=None, simulated_noise_variance=None)[source]

Bases: ComputerExperiment

Extension of ComputerExperiment that simulates additive Gaussian noise on outputs.

Noise configuration:
  • Provide a global simulated_noise_variance (scalar or list with length = total outputs), or

  • Provide per-function dictionaries with “simulated_noise_variance” (list length = that function’s output_dim), or

  • Omit / set zeros for noise-free outputs.

Methods differ from base by adding stochastic evaluation with optional batching.

Notes

  • eval_objectives / eval_constraints are not supported here because repeated calls would mix stochastic draws and caching is disabled for stochastic evals.

Parameters:
  • input_dim (int)

  • input_box (ArrayLike)

  • single_function (Optional[FuncSpec])

  • function_list (Optional[List[FuncSpec]])

  • single_objective (Optional[FuncSpec])

  • objective_list (Optional[List[FuncSpec]])

  • single_constraint (Optional[FuncSpec])

  • constraint_list (Optional[List[FuncSpec]])

  • simulated_noise_variance (Optional[Union[float, List[float]]])

eval(x, *, simulate_noise=True, batch_size=1, rng=None)[source]

Evaluate all outputs at x with optional simulated Gaussian noise.

Parameters:
  • x (array-like) – Shape (n, d) or (d,). If 1D, it is reshaped to (1, d).

  • simulate_noise (bool, default True) – Whether to add Gaussian noise using configured variances.

  • batch_size (int, default 1) – If >1, returns shape (n, p, batch_size). If 1, returns (n, p).

  • rng (numpy.random.Generator, optional) – Random generator for reproducibility. If None, a default RNG is used.

Returns:

(n, p) if batch_size == 1. Otherwise (n, p, batch_size).

Return type:

ndarray

eval_constraints(x, **kwargs)[source]
Parameters:

x (ndarray | Sequence[float])

Return type:

ndarray

eval_objectives(x, **kwargs)[source]
Parameters:

x (ndarray | Sequence[float])

Return type:

ndarray

get_simulated_noise_variances()[source]
Return type:

ndarray

property simulated_noise_variance: ndarray