Details Optimization

Details Phase II

class randomStarter.RandomStarter(s_opts: SACoptions)

Decide which start point xStart to take for the next sequential optimizer step: Either cobra.sac_res['xbest'] or a random point in search space.

__init__(s_opts: SACoptions)

Initialize RandomStarter RNGs with seed s_opts.cobraSeed.

Case ISA.RS_rep==False is the normal case: Use np.random.default_rng as RNG.

Case ISA.RS_rep==True is only for comparing with SACOBRA R: We use self.my_rng2 as RNG which produces with a given seed the same random numbers as my_rng2 in R.

random_start(cobra: CobraInitializer, p2: Phase2Vars) ndarray

This method decides whether cobra.sac_res['xbest'] or a random start point is used for the next xStart. In the latter case we set p2.rs_done == True.

If ISA.RS==False the probability for random start is 0.

If ISA.RS==True the probability depends on the feasibility rate, ISA.RStype, ISA.RSauto, ISA.RSmin, ISA.RSmax.

Parameters:
  • cobra – we need elements sac_opts, sac_res['xbest', 'dimension', 'numViol']

  • p2 – we write on p2.rs_done

Returns:

xStart

Return type:

np.ndarray

class seqOptimizer.SeqOptimizer(xStart: ndarray, cobra: CobraInitializer, p2: Phase2Vars)

Sequential optimizer for phase II that optimizes on the surrogates in each sequential step.

Several optimizer algorithms from nlopt, the nonlinear optimization package NLopt, are available and can be selected via parameter cobra.sac_opts.SEQ.optimizer, namely

Parameters:
  • xStart – where (in input space) the optimizer starts

  • cobra – parameter cobra.sac_opts.SEQ.optimizer specifies the optimization algorithm

  • p2 – dict p2.opt_res contains the optimization results

class surrogator1.Surrogator1.AdFitter(cobra: CobraInitializer, p2: Phase2Vars, Fres)

Adjust fitness values of Fres, depending on p-effect (if onlinePLOG != O_LOGIC.NONE) or depending on FRange, ISA.TFRange (if onlinePLOG == O_LOGIC.NONE)

__call__()
Returns:

self.surrogateInput, a potentially plog-transformed Fres

Return type:

np.ndarray

__init__(cobra: CobraInitializer, p2: Phase2Vars, Fres)

The values provided in Fres are conditionally plog-transformed and the results are available from self.surrogateInput.

Parameters:
  • cobra – AdFitter needs sac_opts and sac_res

  • p2 – AdFitter needs p2.pEffect and changes p2.PLOG, p2.pshift

  • Fres – the Fres input, may be either cobra.sac_res[‘Fres’] or cobra.for_rbf[‘Fres’]

class surrogator1.Surrogator1

This class calculates the surrogate models in case ISA.onlinePLOG = O_LOGIC.NONE or O_LOGIC.XNEW.

static calcPEffect(p2: Phase2Vars, xNew: ndarray, xNewEval: ndarray, verbose=False)

Calculates the p-effect in variable p2.pEffect with method described in Details for onlinePLOG, case O_LOGIC.XNEW.

Let opl = s_opts.ISA.onlinePLOG.

In case opl != NONE, class AdFitter will apply plog to Fres if p2.pEffect > 0, else Fres is used directly.

In case opl == NONE, p2.pEffect is irrelevant.

Parameters:
  • p2 – needs p2.fitnessSurrogate1 and p2.fitnessSurrogate2 on input and changes p2.err1, p2.err2, p2.errRatio and p2.pEffect on output

  • xNew – the new infill point

  • xNewEvalfn(xNew)[0]

  • verbose – if True, print a warning message if any clipping occurs

Returns:

None

static trainSurrogates(cobra: CobraInitializer, p2: Phase2Vars) Phase2Vars

Train surrogate models p2.fitnessSurrogate, p2.constraintSurrogates, p2.fitnessSurrogate1, p2.fitnessSurrogate2.

Parameters:
  • cobra

  • p2

Returns:

p2

Return type:

Phase2Vars

class surrogator2.Surrogator2

This class calculates the surrogate models in case ISA.onlinePLOG = O_LOGIC.MIDPTS.

static calcPEffect(p2: Phase2Vars, midp: ndarray, midpEval: ndarray, verbose=False)

Calculates the p-effect in variable p2.pEffect with method described in Details for onlinePLOG, case O_LOGIC.MIDPTS.

Let opl = s_opts.ISA.onlinePLOG.

In case opl != NONE, class AdFitter will apply plog to Fres if p2.pEffect > 0, else Fres is used directly.

In case opl == NONE, p2.pEffect is irrelevant.

Parameters:
  • p2 – needs p2.fitnessSurrogate1 and p2.fitnessSurrogate2 on input and changes p2.err1, p2.err2, p2.errRatio and p2.pEffect on output

  • midp – the midpoints

  • midpEvalfn(midp)[0]

  • verbose – if True, print a warning message if any clipping occurs

Returns:

None

static trainSurrogates(cobra: CobraInitializer, p2: Phase2Vars) Phase2Vars

Train surrogate models p2.fitnessSurrogate, p2.constraintSurrogates, p2.fitnessSurrogate1, p2.fitnessSurrogate2.

Parameters:
  • cobra

  • p2

Returns:

p2

Return type:

Phase2Vars

class rbfModel.RBFmodel(xobs: ~numpy.ndarray, yobs: ~numpy.ndarray, rbf_opts=<opt.rbfOptions.RBFoptions object>)

Wrapper for the RBF model which is contained in self.model. self.model is either SciPy’s RBFInterpolator or it is an object of class RBFsacob, which is SACOBRA’s own implementation of RBF models (allows with degree=1.5 the option equivalent to squares=T in R’s SACOBRA, which means only pure squares in the polynomial tail).

The wrapper’s purpose is to provide a syntax similar to SACOBRA’s RbfInter.R.

Usage:

mdl = RBFmodel(xobs,yobs) # equivalent to trainCubicRBF
yflat = mdl(xflat)        # apply the model to new observations xflat, with xflat.shape = [n,d]

It turns out that RBFsacob is factor 20-50 slower in __init__ and factor 5-8 slower in __call__ than SciPy’s RBFInterpolator (see test/results_time_RBF.txt for details). But it has the useful extra option degree=1.5.

__call__(xflat: ndarray)

Apply RBF model(s) to data xflat.

Parameters:

xflat – vector of length d - or - matrix of shape (n,d)

Returns:

response of model(s): See __init__() for definition of parameter m. If m=1, then the return value is either a number or a vector of length n, depending on size n of xflat. If m>1, then it is either vector of shape m or matrix of shape (n,m), depending on size n of xflat.

Hint

The shape m refers to the size m of yobs in constructor __init__().

__init__(xobs: ~numpy.ndarray, yobs: ~numpy.ndarray, rbf_opts=<opt.rbfOptions.RBFoptions object>)

Create RBF model(s) from observations (xobs,yobs) according to the RBF specification in RBFoptions rbf_opts. Shape m of yobs controls whether one RBF model (m=1) or several RBF models (m>1) are formed.

Parameters:
  • xobs – (n x d)-matrix of n d-dimensional vectors \(\vec{x}_i,\, i=0,...,n-1\)

  • yobs – vector of shape (n,) with observations \(f(\vec{x}_i)\) - or - matrix of shape (n,m) with observations \(f_j(\vec{x}_i)\) for \(m\) functions \(f_j,\, j=0,...,m-1\)

  • rbf_opts – see RBFoptions for details

class rbfSacobra.RBFsacob(xobs, yobs, kernel='cubic', degree=1.5, rho=0, width=-1, test_pmat=False)

RBF model implemented in SACOBRA. In contrast to SciPy’s RBFInterpolator implementation, it allows degree=1.5 which means linear polynomial tail plus pure square terms x1**2, x2**2, ...

__call__(xflat)

Apply RBF kernel(s) to data xflat.

Parameters:

xflat – vector of length d - or - matrix of shape (n,d)

Returns:

response of kernel(s): See __init__() for definition of parameter m. If m=1, then the return value is either a number or a vector of length n, depending on size n of xflat. If m>1, then it is either vector of shape m or matrix of shape (n,m), depending on size n of xflat.

Hint

The shape m refers to the size m of yobs in constructor __init__().

__init__(xobs, yobs, kernel='cubic', degree=1.5, rho=0, width=-1, test_pmat=False)

Create RBF model(s) from observations (xobs,yobs). Shape m of yobs controls whether one RBF model (m=1) or several RBF models (m>1) are formed.

Parameters:
  • xobs – (n x d)-matrix of n d-dimensional vectors \(\vec{x}_i,\, i=0,...,n-1\)

  • yobs – vector of shape (n,) with observations \(f(\vec{x}_i)\) - or - matrix of shape (n,m) with observations \(f_j(\vec{x}_i)\) for \(m\) functions \(f_j,\, j=0,...,m-1\)

  • kernel – RBF kernel type, see RBFoptions for details. The names should match to SciPy’s RBFInterpolator

  • degree – degree of polynomial tail, see below

  • rho – smoothing parameter. If = 0, we have interpolating RBFs, if > 0, we have approximating RBFs (the larger rho, the more approximating)

  • width – optional width parameter for Gaussian or MQ RBFs, see RBFoptions for details

  • test_pmat – only for testing the RBFsacob implementation (degree=1, 1.5)

Parameter degree controls whether RBF models are augmented with a polynomial tail. Allowed values:

  • 0 or -1: no polynomial tail

  • 1: linear polynomial tail

  • 1.5: linear plus pure squares tail (e.g. x1*x1, x2*x2) (option squares=T in R’s SACOBRA)

  • 2: linear plus quadratic polynomial tail (all monomials of degree 1 and 2)

class evaluatorReal.EvaluatorReal(cobra: CobraInitializer, p2: Phase2Vars)

Method EvaluatorReal.update() evaluates the new infill point xNew (found via sequential optimization with surrogate models) on the real functions.

equ_num_max_viol(cobra: CobraInitializer, currentMu, newPredC, p2: Phase2Vars)

Calculate self.newNumViol, .newMaxViol, … for the equality case (sac_opts.EQU.active=True)

Parameters:
  • cobra – object of class CobraInitializer

  • currentMu – current artificial equality margin \(\mu\)

  • newPredC – prediction for xNew on constraint surrogates

Returns:

nothing, but these elements of self are changed: (a) numbers newNumViol, newMaxViol, newNumPred, trueNumViol, trueMaxViol; (b) vectors feas, feasPred

equ_refine(cobra: CobraInitializer, p2: Phase2Vars, currentMu)

Do refine step for equality constraints on the new point stored in self.xNew.

Parameters:
  • cobra

  • p2

  • currentMu – current artificial margin \(\mu\) for equality constraints

Returns:

nothing, but these elements of self are changed: (a) vectors xNew, x_0 (the infill point before refine), x_1 (the infill point after refine) (b) dict refi; (c) numbers nv_conB, nv_conA, nv_trueB, nv_trueA; (d) string state

ine_num_max_viol(cobra: CobraInitializer, newPredC)

Calculate self.newNumViol, .newMaxViol, … for the inequality case (sac_opts.EQU.active=False)

Parameters:
  • cobra – object of class CobraInitializer

  • newPredC – prediction for xNew on constraint surrogates

Returns:

nothing, but these elements of self are changed: (a) numbers newNumViol, newMaxViol, newNumPred, trueNumViol, trueMaxViol; (b) vectors feas, feasPred

update(xNew: ndarray, cobra: CobraInitializer, p2: Phase2Vars, currentMu, fitnessSurrogate=None, f_value=None)

Evaluate xNew on the real functions + do refine step (if cobra.sac_opts.EQU.active and self.state == "optimized") + calculate various feasibility indicators (numViol, maxViol, …)

Parameters:
  • xNew – the new infill point (vector) resulting from sequential optimization on surrogates or from repair step

  • cobra

  • p2

  • currentMu – current artificial margin \(\mu\) for equality constraints

  • fitnessSurrogate – if None, set fitnessSurrogate = p2.fitnessSurrogate. Used to calculate s_f(xNew) where s_f is the fitness surrogate model. s_f(xNew) becomes the new last value of vector self.predY

  • f_value – if None, set f_value=p2.opt_res['minf']. Used for self.predVal (probably obsolete)

Returns:

nothing, but many elements of self are updated: xNew, xNewEval, x0, x1, …