Details Optimization
Details Phase II
- class randomStarter.RandomStarter(s_opts: SACoptions)
Decide which start point
xStartto take for the next sequential optimizer step: Eithercobra.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==Falseis the normal case: Usenp.random.default_rngas RNG.Case
ISA.RS_rep==Trueis only for comparing with SACOBRA R: We useself.my_rng2as RNG which produces with a given seed the same random numbers asmy_rng2in 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 nextxStart. In the latter case we setp2.rs_done == True.If
ISA.RS==Falsethe probability for random start is 0.If
ISA.RS==Truethe 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, namelyCOBYLA: nlopt.LN_COBYLAISRESN: nlopt.GN_ISRES
- Parameters:
xStart – where (in input space) the optimizer starts
cobra – parameter
cobra.sac_opts.SEQ.optimizerspecifies the optimization algorithmp2 – dict
p2.opt_rescontains the optimization results
- class surrogator1.Surrogator1.AdFitter(cobra: CobraInitializer, p2: Phase2Vars, Fres)
Adjust fitness values of
Fres, depending on p-effect (ifonlinePLOG != O_LOGIC.NONE) or depending onFRange,ISA.TFRange(ifonlinePLOG == O_LOGIC.NONE)- __call__()
- Returns:
self.surrogateInput, a potentially plog-transformedFres- Return type:
np.ndarray
- __init__(cobra: CobraInitializer, p2: Phase2Vars, Fres)
The values provided in
Fresare conditionally plog-transformed and the results are available fromself.surrogateInput.- Parameters:
cobra – AdFitter needs
sac_optsandsac_resp2 – AdFitter needs
p2.pEffectand changesp2.PLOG,p2.pshiftFres – the
Fresinput, 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.pEffectwith method described in Details for onlinePLOG, case O_LOGIC.XNEW.Let
opl = s_opts.ISA.onlinePLOG.In case
opl != NONE, classAdFitterwill apply plog toFresifp2.pEffect> 0, elseFresis used directly.In case
opl == NONE,p2.pEffectis irrelevant.- Parameters:
p2 – needs
p2.fitnessSurrogate1andp2.fitnessSurrogate2on input and changesp2.err1,p2.err2,p2.errRatioandp2.pEffecton outputxNew – the new infill point
xNewEval –
fn(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:
- 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.pEffectwith method described in Details for onlinePLOG, case O_LOGIC.MIDPTS.Let
opl = s_opts.ISA.onlinePLOG.In case
opl != NONE, classAdFitterwill apply plog toFresifp2.pEffect> 0, elseFresis used directly.In case
opl == NONE,p2.pEffectis irrelevant.- Parameters:
p2 – needs
p2.fitnessSurrogate1andp2.fitnessSurrogate2on input and changesp2.err1,p2.err2,p2.errRatioandp2.pEffecton outputmidp – the midpoints
midpEval –
fn(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:
- 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.modelis either SciPy’s RBFInterpolator or it is an object of classRBFsacob, which is SACOBRA’s own implementation of RBF models (allows withdegree=1.5the option equivalent tosquares=Tin 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
RBFsacobis factor 20-50 slower in__init__and factor 5-8 slower in__call__than SciPy’s RBFInterpolator (seetest/results_time_RBF.txtfor details). But it has the useful extra optiondegree=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 ofxflat. If m>1, then it is either vector of shape m or matrix of shape (n,m), depending on size n ofxflat.
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 inRBFoptionsrbf_opts. Shape m ofyobscontrols 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
RBFoptionsfor 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.5which means linear polynomial tail plus pure square termsx1**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 ofxflat. If m>1, then it is either vector of shape m or matrix of shape (n,m), depending on size n ofxflat.
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 ofyobscontrols 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
RBFoptionsfor details. The names should match to SciPy’s RBFInterpolatordegree – 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
RBFoptionsfor detailstest_pmat – only for testing the RBFsacob implementation (degree=1, 1.5)
Parameter
degreecontrols 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=Tin 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 pointxNew(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
selfare changed: (a) numbersnewNumViol,newMaxViol,newNumPred,trueNumViol,trueMaxViol; (b) vectorsfeas,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) dictrefi; (c) numbersnv_conB,nv_conA,nv_trueB,nv_trueA; (d) stringstate
- 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
selfare changed: (a) numbersnewNumViol,newMaxViol,newNumPred,trueNumViol,trueMaxViol; (b) vectorsfeas,feasPred
- update(xNew: ndarray, cobra: CobraInitializer, p2: Phase2Vars, currentMu, fitnessSurrogate=None, f_value=None)
Evaluate
xNewon the real functions + do refine step (ifcobra.sac_opts.EQU.activeandself.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, setfitnessSurrogate = p2.fitnessSurrogate. Used to calculates_f(xNew)wheres_fis the fitness surrogate model.s_f(xNew)becomes the new last value of vectorself.predYf_value – if
None, setf_value=p2.opt_res['minf']. Used forself.predVal(probably obsolete)
- Returns:
nothing, but many elements of
selfare updated:xNew,xNewEval,x0,x1, …