blackboxopt package

Submodules

blackboxopt.acquisition module

Acquisition functions for surrogate optimization.

class blackboxopt.acquisition.AcquisitionFunction

Bases: object

Base class for acquisition functions.

acquire(surrogateModel, bounds, n: int = 1, **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelSurrogate model

Surrogate model.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired, or maximum requested number. The default is 1.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

class blackboxopt.acquisition.CoordinatePerturbation(maxeval: int, sampler=None, weightpattern=(0.2, 0.4, 0.6, 0.9, 0.95, 1), reltol: float = 0.01)

Bases: AcquisitionFunction

Coordinate perturbation acquisition function.

Attributes

nevalint

Number of evaluations done so far.

maxevalint

Maximum number of evaluations.

samplerNormalSampler

Sampler to generate candidate points.

weightpatternlist-like, optional

Weights \(w\) in (0,1) to be used in the score function \(w f_s(x) + (1-w) (1-d_s(x))\), where

  • \(f_s(x)\) is the estimated value for the objective function on x, scaled to [0,1].

  • \(d_s(x)\) is the minimum distance between x and the previously selected evaluation points, scaled to [-1,0].

The default is [0.2, 0.4, 0.6, 0.9, 0.95, 1].

reltolfloat, optional

Candidate points are chosen s.t.

||x - xbest|| >= reltol * sqrt(dim) * sigma,

where sigma is the standard deviation of the normal distribution.

acquire(surrogateModel, bounds, n: int = 1, *, xbest=None, coord=(), **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelSurrogate model

Surrogate model.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired. The default is 1.

xbestarray-like, optional

Best point so far.

coordtuple, optional

Coordinates of the input space that will vary. The default is (), which means that all coordinates will vary.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

tol(bounds) float
class blackboxopt.acquisition.CoordinatePerturbationOverNondominated(acquisitionFunc: CoordinatePerturbation)

Bases: AcquisitionFunction

Coordinate perturbation acquisition function over the nondominated set.

Attributes

acquisitionFuncCoordinatePerturbation

Coordinate perturbation acquisition function.

acquire(surrogateModels, bounds, n: int = 1, *, nondominated=(), paretoFront=(), **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelslist

List of surrogate models.

bounds

Bounds of the search space.

nint

Maximum number of points to be acquired. The default is 1.

nondominatedarray-like, optional

Nondominated set in the objective space. The default is an empty tuple.

paretoFrontarray-like, optional

Pareto front in the objective space. The default is an empty tuple.

class blackboxopt.acquisition.EndPointsParetoFront(optimizer=None, nGens: int = 100, tol=0.001)

Bases: AcquisitionFunction

Obtain endpoints of the Pareto front.

Attributes

optimizer

Single-objective optimizer. Default is MixedVariableGA from pymoo.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points.

acquire(surrogateModels, bounds, n: int = 1, **kwargs) ndarray

Acquire n points at most.

Parameters

surrogateModelslist

List of surrogate models.

bounds

Bounds of the search space.

nint, optional

Maximum number of points to be acquired. The default is 1.

Returns

numpy.ndarray

k-by-dim matrix with the selected points.

class blackboxopt.acquisition.GosacSample(fun, optimizer=None, nGens: int = 100, tol: float = 0.001)

Bases: AcquisitionFunction

GOSAC acquisition function as described in [1].

Attributes

funcallable

Objective function.

optimizerpymoo.optimizer

Optimizer for the acquisition function.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points.

References

acquire(surrogateModels, bounds, n: int = 1, **kwargs) ndarray

Acquire n points (Currently only n=1 is supported).

Parameters

surrogateModelslist

List of surrogate models for the constraints.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired. The default is 1.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

class blackboxopt.acquisition.MinimizeMOSurrogate(mooptimizer=None, nGens=100, tol=0.001)

Bases: AcquisitionFunction

Obtain pareto-optimal samplesfor the multi-objective surrogate model.

Attributes

mooptimizer

Multi-objective optimizer. Default is MixedVariableGA from pymoo with RankAndCrowding survival strategy.

nGensint

Number of generations for the multi-objective optimizer. Default is 100.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points. Default is 1e-3.

acquire(surrogateModels, bounds, n: int = 1, **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelslist

List of surrogate models.

bounds

Bounds of the search space.

nint, optional

Maximum number of points to be acquired. The default is 1.

Returns

numpy.ndarray

k-by-dim matrix with the selected points.

class blackboxopt.acquisition.MinimizeSurrogate(nCand: int, tol=0.001)

Bases: AcquisitionFunction

Obtain samples that are local minima of the surrogate model.

Attributes

samplerSampler

Sampler to generate candidate points.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points.

acquire(surrogateModel, bounds, n: int = 1, **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelSurrogate model

Surrogate model.

bounds

Bounds of the search space.

nint, optional

Max number of points to be acquired. The default is 1.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

class blackboxopt.acquisition.ParetoFront(mooptimizer=None, nGens: int = 100, oldTV=())

Bases: AcquisitionFunction

Obtain samples that fill gaps in the Pareto front.

Attributes

mooptimizer

Multi-objective optimizer. Default is MixedVariableGA from pymoo with RankAndCrowding survival strategy.

nGensint

Number of generations for the multi-objective optimizer. Default is 100.

oldTVnumpy.ndarray

Old target values to be avoided in the acquisition. Default is an empty array.

acquire(surrogateModels, bounds, n: int = 1, *, paretoFront=(), **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelslist

List of surrogate models.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired. The default is 1.

paretoFrontarray-like, optional

Pareto front in the objective space. The default is an empty tuple.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

pareto_front_target(paretoFront: ndarray) ndarray

Find a target value that should fill a gap in the Pareto front.

Parameters

paretoFrontnumpy.ndarray

Pareto front in the objective space.

Returns

numpy.ndarray

Target value.

class blackboxopt.acquisition.TargetValueAcquisition(tol=0.001, popsize=10, ngen=10)

Bases: AcquisitionFunction

Target value acquisition function.

Attributes

cycleLengthint

Length of the cycle.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points. Default is 1e-3.

acquire(surrogateModel, bounds, n: int = 1, *, sampleStage: int = -1, fbounds=(), **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelSurrogate model

Surrogate model.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired. The default is 1.

sampleStageint, optional

Stage of the sampling process. The default is -1, which means that the stage is not specified.

fbounds, optional

Bounds of the objective function so far. Optional if sampleStage is 0.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

class blackboxopt.acquisition.UniformAcquisition(nCand: int, weight: float = 0.95, tol: float = 0.001)

Bases: AcquisitionFunction

Uniform acquisition function.

Attributes

samplerSampler

Sampler to generate candidate points.

weightfloat, optional

Weight \(w\) in (0,1) to be used in the score function \(w f_s(x) + (1-w) (1-d_s(x))\), where

  • \(f_s(x)\) is the estimated value for the objective function on x, scaled to [0,1].

  • \(d_s(x)\) is the minimum distance between x and the previously selected evaluation points, scaled to [-1,0].

The default is 0.95.

tolfloat, optional

Tolerance value for excluding candidate points that are too close to already sampled points. The default is 1e-3.

acquire(surrogateModel, bounds, n: int = 1, **kwargs) ndarray

Acquire n points.

Parameters

surrogateModelSurrogate model

Surrogate model.

bounds

Bounds of the search space.

nint, optional

Number of points to be acquired. The default is 1.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

blackboxopt.acquisition.find_best(x: ndarray, distx: ndarray, fx: ndarray, n: int, tol: float = 0.001, weightpattern=(0.3, 0.5, 0.8, 0.95)) tuple[ndarray, ndarray]

Select n points based on their values and distances to candidates.

The points are chosen from x such that they minimize the expression \(w f_s(x) + (1-w) (1-d_s(x))\), where

  • \(w\) is a weight.

  • \(f_s(x)\) is the estimated value for the objective function on x, scaled to [0,1].

  • \(d_s(x)\) is the minimum distance between x and the previously selected evaluation points, scaled to [-1,0].

If there are more than one new sample point to be selected, the distances of the candidate points to the previously selected candidate point have to be taken into account.

Parameters

xnumpy.ndarray

Matrix with candidate points.

distx: numpy.ndarray

Matrix with the distances between the candidate points and the sampled points. The number of rows of distx must be equal to the number of rows of x.

fxnumpy.ndarray

Vector with the estimated values for the objective function on the candidate points.

nint

Number of points to be selected for the next costly evaluation.

tolfloat

Tolerance value for excluding candidate points that are too close to already sampled points.

weightpattern: list-like, optional

Weight(s) w to be used in the score given in a circular list.

Returns

numpy.ndarray

n-by-dim matrix with the selected points.

numpy.ndarray

n-by-(n+m) matrix with the distances between the n selected points and the (n+m) sampled points (m is the number of points that have been sampled so far)

blackboxopt.acquisition.find_pareto_front(x, fx, iStart=0) list

Find the Pareto front given a set of points and their values.

Parameters

xnumpy.ndarray

n-by-d matrix with n samples in a d-dimensional space.

fxnumpy.ndarray

n-by-m matrix with the values of the objective function on the samples.

iStartint, optional

Points from 0 to iStart - 1 are considered to be already in the Pareto front. The default is 0.

Returns

list

Indices of the points that are in the Pareto front.

blackboxopt.optimize module

Optimization algorithms for blackboxopt.

class blackboxopt.optimize.OptimizeResult(x: ndarray, fx: float | ndarray, nit: int, nfev: int, samples: ndarray, fsamples: ndarray)

Bases: object

Represents the optimization result.

Attributes

xnumpy.ndarray

The solution of the optimization.

fxfloat | numpy.ndarray

The value of the objective function at the solution.

nitint

Number of iterations performed.

nfevint

Number of function evaluations done.

samplesnumpy.ndarray

All sampled points.

fsamplesnumpy.ndarray

All objective function values on sampled points.

fsamples: ndarray
fx: float | ndarray
nfev: int
nit: int
samples: ndarray
x: ndarray
blackboxopt.optimize.cptv(fun, bounds, maxeval: int, *, surrogateModel=None, acquisitionFunc: CoordinatePerturbation | None = None, expectedRelativeImprovement: float = 0.001, failtolerance: int = 5, consecutiveQuickFailuresTol: int = 0, useLocalSearch: bool = False, disp: bool = False, callback: Callable[[OptimizeResult], None] | None = None) OptimizeResult

Minimize a scalar function of one or more variables using the coordinate perturbation and target value strategy.

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

surrogateModelsurrogate model, optional

Surrogate model. The default is RbfModel().

acquisitionFuncCoordinatePerturbation, optional

Acquisition function to be used in the CP step. The default is CoordinatePerturbation(0).

expectedRelativeImprovementfloat, optional

Expected relative improvement with respect to the current best value. An improvement is considered significant if it is greater than expectedRelativeImprovement times the absolute value of the current best value. The default is 1e-3.

failtoleranceint, optional

Number of consecutive insignificant improvements before the algorithm switches between the CP and TV steps. The default is 5.

consecutiveQuickFailuresTolint, optional

Number of times that the CP step or the TV step fails quickly before the algorithm stops. The default is 0, which means the algorithm will stop after maxeval function evaluations. A quick failure is when the acquisition function in the CP or TV step does not find any significant improvement.

useLocalSearchbool, optional

If True, the algorithm will perform a local search when a significant improvement is not found in a sequence of (CP,TV,CP) steps. The default is False.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None. The callback function will be called internally at stochastic_response_surface() and target_value_optimization(), as well as in the local search if it is performed.

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.cptvl(fun, bounds, maxeval: int, *, surrogateModel=None, acquisitionFunc: CoordinatePerturbation | None = None, expectedRelativeImprovement: float = 0.001, failtolerance: int = 5, consecutiveQuickFailuresTol: int = 0, disp: bool = False, callback: Callable[[OptimizeResult], None] | None = None) OptimizeResult

Wrapper to cptv. See cptv.

blackboxopt.optimize.gosac(fun, gfun, bounds, maxeval: int, *, surrogateModels=(<blackboxopt.rbf.RbfModel object>,), samples: ~numpy.ndarray | None = None, disp: bool = False, callback: ~typing.Callable[[~blackboxopt.optimize.OptimizeResult], None] | None = None)

Minimize a scalar function of one or more variables subject to constraints.

The surrogate models are used to approximate the constraints. The objective function is assumed to be cheap to evaluate, while the constraints are assumed to be expensive to evaluate.

Parameters

funcallable

The objective function to be minimized.

gfuncallable

The constraint function to be minimized. The constraints must be formulated as g(x) <= 0.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

surrogateModelstuple, optional

Surrogate models to be used. The default is (RbfModel(),).

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None.

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.initialize_moo_surrogate(fun, bounds, mineval: int, maxeval: int, *, surrogateModels=(<blackboxopt.rbf.RbfModel object>, ), samples: ~numpy.ndarray | None = None) OptimizeResult

Initialize the surrogate model and the output of the optimization.

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

minevalint

Minimum number of function evaluations to build the surrogate model.

maxevalint

Maximum number of function evaluations.

surrogateModelslist, optional

Surrogate models to be used. The default is (RbfModel(),).

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.initialize_surrogate(fun, bounds, mineval: int, maxeval: int, x0y0=(), *, surrogateModel=None, samples: ndarray | None = None) OptimizeResult

Initialize the surrogate model and the output of the optimization.

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

minevalint

Minimum number of function evaluations to build the surrogate model.

maxevalint

Maximum number of function evaluations.

x0y0tuple-like, optional

Initial guess for the solution and the value of the objective function at the initial guess.

surrogateModelsurrogate model, optional

Surrogate model to be used. The default is RbfModel().

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.initialize_surrogate_constraints(fun, gfun, bounds, mineval: int, maxeval: int, *, surrogateModels=(<blackboxopt.rbf.RbfModel object>, ), samples: ~numpy.ndarray | None = None) OptimizeResult

Initialize the surrogate models for the constraints.

Parameters

funcallable

The objective function to be minimized.

gfuncallable

The constraint functions. Each constraint function must return a scalar value. If the constraint function returns a value greater than zero, it is considered a violation of the constraint.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

minevalint

Minimum number of function evaluations to build the surrogate model.

maxevalint

Maximum number of function evaluations.

surrogateModelslist, optional

Surrogate models to be used. The default is (RbfModel(),).

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.multistart_stochastic_response_surface(fun, bounds, maxeval: int, *, surrogateModel=None, acquisitionFunc: CoordinatePerturbation | None = None, newSamplesPerIteration: int = 1, performContinuousSearch: bool = True, disp: bool = False, callback: Callable[[OptimizeResult], None] | None = None) OptimizeResult

Minimize a scalar function of one or more variables using a surrogate model.

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

surrogateModelsurrogate model, optional

Surrogate model to be used. The default is RbfModel().

acquisitionFuncCoordinatePerturbation, optional

Acquisition function to be used.

newSamplesPerIterationint, optional

Number of new samples to be generated per iteration. The default is 1.

performContinuousSearchbool, optional

If True, the algorithm will perform a continuous search when a significant improvement is found among the integer coordinates. The default is True.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None. The callback function will be called internally at stochastic_response_surface().

Returns

OptimizeResult

The optimization result.

blackboxopt.optimize.socemo(fun, bounds, maxeval: int, *, surrogateModels=(<blackboxopt.rbf.RbfModel object>,), acquisitionFunc: ~blackboxopt.acquisition.CoordinatePerturbation | None = None, acquisitionFuncGlobal: ~blackboxopt.acquisition.UniformAcquisition | None = None, samples: ~numpy.ndarray | None = None, disp: bool = False, callback: ~typing.Callable[[~blackboxopt.optimize.OptimizeResult], None] | None = None)

Minimize a multiobjective function using the surrogate model approach from [2].

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

surrogateModelstuple, optional

Surrogate models to be used. The default is (RbfModel(),).

acquisitionFuncCoordinatePerturbation, optional

Acquisition function to be used in the CP step. The default is CoordinatePerturbation(0).

acquisitionFuncGlobalUniformAcquisition, optional

Acquisition function to be used in the global step. The default is UniformAcquisition(0).

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None.

Returns

OptimizeResult

The optimization result.

References

blackboxopt.optimize.stochastic_response_surface(fun, bounds, maxeval: int, x0y0=(), *, surrogateModel=None, acquisitionFunc: CoordinatePerturbation | None = None, samples: ndarray | None = None, newSamplesPerIteration: int = 1, expectedRelativeImprovement: float = 0.001, failtolerance: int = 5, performContinuousSearch: bool = True, disp: bool = False, callback: Callable[[OptimizeResult], None] | None = None) OptimizeResult

Minimize a scalar function of one or more variables using a response surface model approach based on a surrogate model.

This method is based on [3].

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

x0y0tuple-like, optional

Initial guess for the solution and the value of the objective function at the initial guess.

surrogateModelsurrogate model, optional

Surrogate model to be used. The default is RbfModel(). On exit, if provided, the surrogate model is updated to represent the one used in the last iteration.

acquisitionFuncCoordinatePerturbation, optional

Acquisition function to be used.

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

newSamplesPerIterationint, optional

Number of new samples to be generated per iteration. The default is 1.

expectedRelativeImprovementfloat, optional

Expected relative improvement with respect to the current best value. An improvement is considered significant if it is greater than expectedRelativeImprovement times the absolute value of the current best value. The default is 1e-3.

failtoleranceint, optional

Number of consecutive insignificant improvements before the algorithm modifies the sampler. The default is 5.

performContinuousSearchbool, optional

If True, the algorithm will perform a continuous search when a significant improvement is found. The default is True.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None.

Returns

OptimizeResult

The optimization result.

References

blackboxopt.optimize.target_value_optimization(fun, bounds, maxeval: int, x0y0=(), *, surrogateModel=None, acquisitionFunc: AcquisitionFunction | None = None, samples: ndarray | None = None, newSamplesPerIteration: int = 1, expectedRelativeImprovement: float = 0.001, failtolerance: int = -1, disp: bool = False, callback: Callable[[OptimizeResult], None] | None = None) OptimizeResult

Minimize a scalar function of one or more variables using the target value strategy from [4].

Parameters

funcallable

The objective function to be minimized.

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

maxevalint

Maximum number of function evaluations.

x0y0tuple-like, optional

Initial guess for the solution and the value of the objective function at the initial guess.

surrogateModelsurrogate model, optional

Surrogate model to be used. The default is RbfModel(). On exit, if provided, the surrogate model is updated to represent the one used in the last iteration.

acquisitionFuncAcquisitionFunction, optional

Acquisition function to be used. The default is TargetValueAcquisition().

samplesnp.ndarray, optional

Initial samples to be added to the surrogate model. The default is an empty array.

newSamplesPerIterationint, optional

Number of new samples to be generated per iteration. The default is 1.

expectedRelativeImprovementfloat, optional

Expected relative improvement with respect to the current best value. An improvement is considered significant if it is greater than expectedRelativeImprovement times the absolute value of the current best value. The default is 1e-3.

failtoleranceint, optional

Number of consecutive insignificant improvements before the algorithm modifies the sampler. The default is -1, which means this parameter is not used.

dispbool, optional

If True, print information about the optimization process. The default is False.

callbackcallable, optional

If provided, the callback function will be called after each iteration with the current optimization result. The default is None.

Returns

OptimizeResult

The optimization result.

References

blackboxopt.problem module

Problem definitions for interfacing with pymoo.

class blackboxopt.problem.BBOptDuplicateElimination(**kwargs)

Bases: DefaultDuplicateElimination

calc_dist(pop, other=None)
class blackboxopt.problem.MultiobjSurrogateProblem(surrogateModels, bounds)

Bases: Problem

Mixed-integer multi-objective problem whose objective functions is the evaluation function of the surrogate models.

Attributes

surrogateModelslist

List of surrogate models.

class blackboxopt.problem.MultiobjTVProblem(surrogateModels, tau, bounds)

Bases: Problem

Mixed-integer multi-objective problem whose objective functions is the entry-wise absolute difference between the surrogate models and the target values.

Attributes

surrogateModelslist

List of surrogate models.

taulist

List of target values.

class blackboxopt.problem.ProblemNoConstraint(objfunc, bounds, iindex)

Bases: Problem

Mixed-integer problem with no constraints for pymoo.

Attributes

objfunccallable

Objective function.

class blackboxopt.problem.ProblemWithConstraint(objfunc, gfunc, bounds, iindex, n_ieq_constr: int = 1)

Bases: Problem

Mixed-integer problem with constraints for pymoo.

Attributes

objfunccallable

Objective function.

gfunccallable

Constraint function.

blackboxopt.rbf module

Radial Basis Function model.

class blackboxopt.rbf.MedianLpfFilter

Bases: RbfFilter

class blackboxopt.rbf.RbfFilter

Bases: object

class blackboxopt.rbf.RbfModel(rbf_type: RbfType = RbfType.CUBIC, iindex: tuple[int, ...] = (), filter: RbfFilter | None = None)

Bases: object

Radial Basis Function model.

\[f(x) = \sum_{i=1}^{m} \beta_i \phi(\|x - x_i\|) + \sum_{i=1}^{n} \beta_{m+i} p_i(x),\]

where:

  • \(m\) is the number of sampled points.

  • \(x_i\) are the sampled points.

  • \(\beta_i\) are the coefficients of the RBF model.

  • \(\phi\) is the function that defines the RBF model.

  • \(p_i\) are the basis functions of the polynomial tail.

  • \(n\) is the dimension of the polynomial tail.

Attributes

typeRbfType, optional

Defines the function phi used in the RBF model. The options are:

  • RbfType.LINEAR: phi(r) = r.

  • RbfType.CUBIC: phi(r) = r^3.

  • RbfType.THINPLATE: phi(r) = r^2 * log(r).

iindextuple, optional

Indices of the input space that are integer. The default is ().

filterRbfFilter, optional

Filter used with the function values. The default is RbfFilter() which is the identity function.

bumpiness_measure(x: ndarray, target, LDLt=()) float

Compute the bumpiness of the surrogate model for a potential sample point x as defined in [5].

Parameters

xnp.ndarray

Possible point to be added to the surrogate model.

targeta number

Target value.

LDLt(lu,d,perm), optional

LDLt factorization of the matrix A as returned by the function scipy.linalg.ldl. If not provided, the factorization is computed.

Returns

float

Bumpiness measure of x.

References

create_initial_design(dim: int, bounds, minm: int = 0, maxm: int = 0) None

Creates an initial set of samples for the RBF model.

The points are generated using a symmetric Latin hypercube design.

Parameters

dimint

Dimension of the domain space.

bounds

Tuple of lower and upper bounds for each dimension of the domain space.

minmint, optional

Minimum number of points to generate. If not provided, the initial design will have min(2 * pdim(),maxm) points.

maxmint, optional

Maximum number of points to generate. If not provided, the initial design will have max(2 * pdim(),minm) points.

ddpbasis(x: ndarray, p: ndarray) ndarray

Computes the second derivative of the polynomial tail matrix for a given x and direction p.

Parameters

xnumpy.ndarray

Point in a d-dimensional space.

pnumpy.ndarray

Direction in which the second derivative is evaluated.

Returns

out: numpy.ndarray

Second derivative of the polynomial tail matrix for the input point and direction.

ddphi(r)

Second derivative of the function phi at the distance(s) r.

Parameters

rarray_like

Distance(s) between points.

Returns

out: array_like

Second derivative of the phi-value of the distances provided on input.

dim() int

Get the dimension of the domain space.

Returns

out: int

Dimension of the domain space.

dpbasis(x: ndarray) ndarray

Computes the derivative of the polynomial tail matrix for a given x.

Parameters

xnumpy.ndarray

Point in a d-dimensional space.

Returns

out: numpy.ndarray

Derivative of the polynomial tail matrix for the input point.

dphi(r)

Derivative of the function phi at the distance(s) r.

Parameters

rarray_like

Distance(s) between points.

Returns

out: array_like

Derivative of the phi-value of the distances provided on input.

dphiOverR(r)

Derivative of the function phi divided by r at the distance(s) r.

Parameters

rarray_like

Distance(s) between points.

Returns

out: array_like

Derivative of the phi-value of the distances provided on input divided by the distance.

eval(x: ndarray) tuple[ndarray, ndarray]

Evaluates the model at one or multiple points.

Parameters

xnp.ndarray

m-by-d matrix with m point coordinates in a d-dimensional space.

Returns

numpy.ndarray

Value for the RBF model on each of the input points.

numpy.ndarray

Matrix D where D[i, j] is the distance between the i-th input point and the j-th sampled point.

get_RBFmatrix() ndarray

Get the matrix used to compute the RBF weights.

Returns

out: np.ndarray

(m+pdim)-by-(m+pdim) matrix used to compute the RBF weights.

get_fsamples() ndarray

Get f(x) for the sampled points.

Returns

out: np.ndarray

m vector with the function values.

get_matrixP() ndarray

Get the matrix P.

Returns

out: np.ndarray

m-by-pdim matrix with the polynomial tail.

hessp(x: ndarray, p: ndarray) ndarray

Evaluates the Hessian of the model at x in the direction of p.

\[H(f)(x) v = \sum_{i=1}^{m} \beta_i \left( \phi''(\|x - x_i\|)\frac{(x^Tv)x}{\|x - x_i\|^2} + \frac{\phi'(\|x - x_i\|)}{\|x - x_i\|} \left(v - \frac{(x^Tv)x}{\|x - x_i\|^2}\right) \right) + \sum_{i=1}^{n} \beta_{m+i} H(p_i)(x) v.\]

Parameters

xnp.ndarray

Point in a d-dimensional space.

pnp.ndarray

Direction in which the Hessian is evaluated.

Returns

numpy.ndarray

Value for the Hessian of the RBF model at x in the direction of p.

jac(x: ndarray) ndarray

Evaluates the derivative of the model at one point.

\[\nabla f(x) = \sum_{i=1}^{m} \beta_i \frac{\phi'(\|x - x_i\|)}{\|x - x_i\|} x + \sum_{i=1}^{n} \beta_{m+i} \nabla p_i(x).\]

Parameters

xnp.ndarray

Point in a d-dimensional space.

Returns

numpy.ndarray

Value for the derivative of the RBF model on the input point.

mu_measure(x: ndarray, xdist=None, LDLt=()) float

Compute the value of abs(mu) in the inf step of the target value sampling strategy. See [6] for more details.

Parameters

xnp.ndarray

Possible point to be added to the surrogate model.

xdistarray-like, optional

Distances between x and the sampled points. If not provided, the distances are computed.

LDLt(lu,d,perm), optional

LDLt factorization of the matrix A as returned by the function scipy.linalg.ldl. If not provided, the factorization is computed.

Returns

float

Value of abs(mu) when adding the new x.

References

nsamples() int

Get the number of sampled points.

Returns

out: int

Number of sampled points.

pbasis(x: ndarray) ndarray

Computes the polynomial tail matrix for a given set of points.

Parameters

xnumpy.ndarray

m-by-d matrix with m point coordinates in a d-dimensional space.

Returns

out: numpy.ndarray

Site matrix, needed for determining parameters of the polynomial tail.

pdim() int

Get the dimension of the polynomial tail.

Returns

out: int

Dimension of the polynomial tail.

phi(r)

Applies the function phi to the distance(s) r.

Parameters

rarray_like

Distance(s) between points.

Returns

out: array_like

Phi-value of the distances provided on input.

reserve(maxeval: int, dim: int) None

Reserve space for the RBF model.

If the input maxeval is smaller than the current number of samples, nothing is done.

Parameters

maxevalint

Maximum number of function evaluations allowed.

dimint

Dimension of the domain space.

reset() None

Resets the RBF model.

sample(i: int) ndarray

Get the i-th sampled point.

Parameters

iint

Index of the sampled point.

Returns

out: np.ndarray

i-th sampled point.

samples() ndarray

Get the sampled points.

Returns

out: np.ndarray

m-by-d matrix with m point coordinates in a d-dimensional space.

update_coefficients(fx, filter: RbfFilter | None = None) None

Updates the coefficients of the RBF model.

Parameters

fxarray-like

Function values on the sampled points.

filterRbfFilter | None, optional

Filter used with the function values. The default is None, which means the filter used in the initialization of the RBF model is used.

update_samples(xNew: ndarray, distNew=None) None

Updates the RBF model with new points.

Parameters

xNewnp.ndarray

m-by-d matrix with m point coordinates in a d-dimensional space.

distNewarray-like, optional

m-by-(self.nsamples() + m) matrix with distances between points in xNew and points in (self.samples(), xNew). If not provided, the distances are computed.

class blackboxopt.rbf.RbfType(value)

Bases: Enum

An enumeration.

CUBIC = 2
LINEAR = 1
THINPLATE = 3

blackboxopt.sampling module

Sampling strategies for the optimization algorithms.

class blackboxopt.sampling.NormalSampler(n: int, sigma: float, *, sigma_min: float = 0, sigma_max: float = inf, strategy: SamplingStrategy = SamplingStrategy.NORMAL)

Bases: Sampler

Sampler that generates samples from a normal distribution.

Attributes

sigmafloat

Standard deviation of the normal distribution, relative to the bounds [0, 1].

sigma_minfloat

Minimum standard deviation of the normal distribution, relative to the bounds [0, 1].

sigma_maxfloat

Maximum standard deviation of the normal distribution, relative to the bounds [0, 1].

get_dds_sample(bounds, probability: float, *, iindex: tuple[int, ...] = (), mu=None, coord=()) ndarray

Generate a DDS sample.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

probabilityfloat

Perturbation probability.

iindextuple, optional

Indices of the input space that are integer. The default is ().

muarray-like, optional

Point around which the sample will be generated. The default is the origin.

coordtuple, optional

Coordinates of the input space that will vary. The default is (), which means that all coordinates will vary.

Returns

numpy.ndarray

Matrix with the generated samples.

get_normal_sample(bounds, *, iindex: tuple[int, ...] = (), mu=None, coord=()) ndarray

Generate a sample from a normal distribution around a given point mu.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

iindextuple, optional

Indices of the input space that are integer. The default is ().

muarray-like, optional

Point around which the sample will be generated. The default is the origin.

coordtuple, optional

Coordinates of the input space that will vary. The default is (), which means that all coordinates will vary.

Returns

numpy.ndarray

Matrix with the generated samples.

get_sample(bounds, *, iindex: tuple[int, ...] = (), mu=None, probability: float = 1, coord=()) ndarray

Generate a sample.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

iindextuple, optional

Indices of the input space that are integer. The default is ().

muarray-like, optional

Point around which the sample will be generated. The default is the origin.

probabilityfloat, optional

Perturbation probability. The default is 1.

coordtuple, optional

Coordinates of the input space that will vary. The default is (), which means that all coordinates will vary.

Returns

numpy.ndarray

Matrix with the generated samples.

class blackboxopt.sampling.Sampler(n: int, strategy: SamplingStrategy = SamplingStrategy.UNIFORM)

Bases: object

Base class for samplers.

Attributes

strategySamplingStrategy

Sampling strategy.

nint

Number of samples to be generated.

get_sample(bounds, *, iindex: tuple[int, ...] = ()) ndarray

Generate a sample.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

iindextuple, optional

Indices of the input space that are integer. The default is ().

get_slhd_sample(bounds, *, iindex: tuple[int, ...] = ()) ndarray

Creates a Symmetric Latin Hypercube Design.

Note that, for integer variables, it may not be possible to generate a SLHD. In this case, the algorithm will do its best to try not to repeat values in the integer variables.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

iindextuple, optional

Indices of the input space that are integer. The default is ().

Returns

numpy.ndarray

Matrix with the generated samples.

get_uniform_sample(bounds, *, iindex: tuple[int, ...] = ()) ndarray

Generate a sample from a uniform distribution inside the bounds.

Parameters

bounds

Bounds for variables. Each element of the tuple must be a tuple with two elements, corresponding to the lower and upper bound for the variable.

iindextuple, optional

Indices of the input space that are integer. The default is ().

Returns

numpy.ndarray

Matrix with the generated samples.

class blackboxopt.sampling.SamplingStrategy(value)

Bases: Enum

An enumeration.

DDS = 2
DDS_UNIFORM = 4
NORMAL = 1
SLHD = 5
UNIFORM = 3

Module contents

Black-Box Optimization Library