csle_agents.agents.mcs.mcs_utils package
Submodules
csle_agents.agents.mcs.mcs_utils.gls_utils module
- class csle_agents.agents.mcs.mcs_utils.gls_utils.GLSUtils[source]
Bases:
object
Class with util functions for MCS
- lsconvex(alist: List[Union[float, int]], flist: List[Union[float, int]], nmin: int, s: int) int [source]
Performing the lsconvex :param alist: list of known steps :param flist: function values of known steps :param nmin: :param s: :return: convex
- lsrange(xl, xu, x, p, prt, bend)[source]
Defining line search range
- Parameters
xl – lower bound
xu – upper bound
x – starting point
p – Search direction
prt – print command - unused in this implementation sofar
bend –
- lssat(small: Union[float, int], alist: List[Union[float, int]], flist: List[Union[float, int]], alp: float, amin: float, amax: float, s: int, saturated: int) Tuple[float, int] [source]
Performing the lssat :param small: :param alist: :param flist: :param alp: :param amin: :param amin: :param amax: :param s: :param saturated: :return: alp, saturated
csle_agents.agents.mcs.mcs_utils.ls_utils module
- class csle_agents.agents.mcs.mcs_utils.ls_utils.LSUtils[source]
Bases:
csle_agents.agents.mcs.mcs_utils.ls_utils.UtilHelpers
Class with utility functions for MCS
- lsguard(alp: float, alist: List[Union[float, int]], amax: float, amin: float, small: Union[float, int]) float [source]
Local search guard function
- Parameters
alp –
alist – list of known steps
amax – maximum step
amin – minimum step
small –
- Returns
- lssplit(i: int, alist: List[Union[float, int]], flist: List[Union[float, int]], short: float) Tuple[float, float] [source]
Local search split function
- Parameters
i – label index
alist – list of known steps
flist – function values of known steps
short –
- Returns
- minq(gam: float, c: numpy.ndarray[Any, numpy.dtype[numpy.float64]], G: numpy.ndarray[Any, numpy.dtype[numpy.float64]], xu: numpy.ndarray[Any, numpy.dtype[numpy.float64]], xo: numpy.ndarray[Any, numpy.dtype[numpy.float64]], prt: int, eps: float, ier: int = 0, convex: int = 0) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], float, int] [source]
Minq Function Minimizes an affine quadratic form subject to simple bounds. Using coordinate searches and reduced subspace minimizations, using LDL^T factorization updates fct = gam + c^T x + 0.5 x^T G x s.t. x in [xu,xo] (xu <= xo is assumed), where G is a symmetric n x n matrix, not necessarily definite (if G is indefinite, only a local minimum is found) if G is sparse, it is assumed that the ordering is such that a sparse modified Cholesky factorization is feasible
- Parameters
prt – print command
xx – initial guess (optional)
x – minimizer (but unbounded direction if ier = 1)
fct – optimal function value
ier – 0 (local minimizer found)
- class csle_agents.agents.mcs.mcs_utils.ls_utils.Minq[source]
Bases:
object
The minQ class helper for MCS
- ldlrk1(L: numpy.ndarray[Any, numpy.dtype[numpy.float64]], d: numpy.ndarray[Any, numpy.dtype[numpy.float64]], alp: float, u: numpy.ndarray[Any, numpy.dtype[numpy.float64]], eps: float = 2.2204e-16) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]] [source]
lslrk1 function
- Parameters
L – Indication of the end point (or total number of partition of the value x in the i’th dimenstion)
d – the value of the interpolating polynomial
alp –
u –
eps – parameter value for the golden ratio
- Returns
- class csle_agents.agents.mcs.mcs_utils.ls_utils.UtilHelpers[source]
Bases:
object
A class with util functions for MCS
- getalp(alpu: float, alpo: float, gTp: float, pTGp: float) Tuple[float, bool, bool, int] [source]
Gives minimizer alp in [alpu,alpo] for a univariate quadratic q(alp)=alp*gTp+0.5*alp^2*pTGp
- Parameters
alpu –
alpo –
gTp –
- Parm pTGp
- Returns
- ldldown(L: numpy.ndarray[Any, numpy.dtype[numpy.float64]], d: numpy.ndarray[Any, numpy.dtype[numpy.float64]], j: int) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]] [source]
ldldown function
- Parameters
L – indication of the end point (or total number of partition of the value x in the i’th dimenstion)
d – the value of the interpolating polynomial
j – label
- Returns
the updated end point and the updated value
- ldlup(L: numpy.ndarray[Any, numpy.dtype[numpy.float64]], d: numpy.ndarray[Any, numpy.dtype[numpy.float64]], j: int, g: numpy.ndarray[Any, numpy.dtype[numpy.float64]], eps: float) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]] [source]
ldlup function :param L: Indication of the end point (or total number of partition of the value x in the i’th dimenstion) :param d: the value of the interpolating polynomial :param j: label :param g: :param eps: parameter value for the golden ratio :return:
- minqsub(nsub: int, free: numpy.ndarray[Any, numpy.dtype[numpy.bool_]], L: numpy.ndarray[Any, numpy.dtype[numpy.float64]], dd: numpy.ndarray[Any, numpy.dtype[numpy.float64]], K: numpy.ndarray[Any, numpy.dtype[numpy.bool_]], G: numpy.ndarray[Any, numpy.dtype[numpy.float64]], n: int, g: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x: numpy.ndarray[Any, numpy.dtype[numpy.float64]], xo: numpy.ndarray[Any, numpy.dtype[numpy.float64]], xu: numpy.ndarray[Any, numpy.dtype[numpy.float64]], convex: int, xx: numpy.ndarray[Any, numpy.dtype[numpy.float64]], fct: float, nfree: int, unfix: int, alp: float, alpu: float, alpo: float, lba: bool, uba: bool, ier: int, subdone: int, eps: float)[source]
Minqsub function
- Parameters
nsub –
free –
L – Indication of the end point (or total number of partition of the value x in the i’th dimenstion)
dd –
n –
g –
x –
xo –
xu –
convex –
xx –
fct –
nfree –
unfix –
alp –
alpu –
alpo –
lba –
uba –
ier –
subdone –
eps – parameter value for the golden ratio
- Returns
csle_agents.agents.mcs.mcs_utils.mcs_fun module
- class csle_agents.agents.mcs.mcs_utils.mcs_fun.MCSUtils[source]
Bases:
csle_agents.agents.mcs.mcs_utils.mcs_fun.UtilHelpers
Class with utiltiy functions for MCS
- addloc(nloc: int, xloc: List[float], x: float) Tuple[int, List[float]] [source]
Adding a location
- Parameters
nloc –
xloc –
x –
- Returns
locations including the added one
- check_box_bound(u: List[int], v: List[int])[source]
Function that checks the bounds of the box :param u: lower bound :param v: upper bound :return: boolean indicating the bound
- chkloc(nloc: int, xloc: List[float], x: float) int [source]
Checking the location
- Parameters
nloc –
xloc –
x –
- Returns
the location
- chrelerr(fbest: float, stop: List[Union[float, int]]) int [source]
Performing the chrelerr
- Parameters
fbest –
stop –
- Returns
flags
- chvtr(f: float, vtr: float) int [source]
Performing te chvtr function
- Parameters
f –
vtr –
- Returns
flag
- exgain(n: int, n0: numpy.ndarray[Any, numpy.dtype[numpy.float64]], l: numpy.ndarray[Any, numpy.dtype[numpy.int32]], L: numpy.ndarray[Any, numpy.dtype[numpy.int32]], x: numpy.ndarray[Any, numpy.dtype[numpy.float64]], y: numpy.ndarray[Any, numpy.dtype[numpy.float32]], x1: numpy.ndarray[Any, numpy.dtype[numpy.float32]], x2: numpy.ndarray[Any, numpy.dtype[numpy.float32]], fx: float, f0: numpy.ndarray[Any, numpy.dtype[numpy.float32]], f1: numpy.ndarray[Any, numpy.dtype[numpy.float32]], f2: numpy.ndarray[Any, numpy.dtype[numpy.float32]]) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], int, float] [source]
Determines the splitting index, the splitting value and the expected gain vector e for (potentially) splitting a box by expected gain
- Parameters
n – dimension of the problem
n0 – the ith coordinate has been split n0(i) times in the history of the box
l – Pointer to the initial point of the initialization list
L – lengths of the initialization list
x – base vertex of the box
y – opposite vertex of the box
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
f1 – corresponding function value
f2 – corresponding function value
fx – function value at the base vertex
f0 – function values appertaining to the init. list
- Return e
maximal expected gain in function value by changing coordinate i
- Return isplit
splitting index
- Return splval
Inf if n0(isplit) = 0, splitting value otherwise
- fbestloc(fmi: List[float], fbest: float, xmin: List[float], xbest: float, nbasket0: int, stop: List[Union[float, int]]) Tuple[float, float] [source]
The fbestloc function of MCS
- Parameters
fmi –
fbest –
xmin –
xbest –
nbasket0 –
stop –
- Returns
- genbox(par: int, level0: int, nchild: int, f0: float) Tuple[int, int, int, float] [source]
Function that generates a box
- Parameters
par –
level0 –
nchild –
f0 – inital function value
- Returns
Metrics and parameters from generating the box
- get_theta0(iinit: int, u: List[Union[float, int]], v: List[Union[float, int]], n: int) numpy.ndarray[Any, numpy.dtype[numpy.float32]] [source]
Function for obtaining initial position
- Parameters
iinit –
u –
v –
n –
- Returns
the initial position theta0
- hessian(i: int, k: int, x: List[Union[float, int]], x0: List[Union[float, int]], f: float, f0: float, g: numpy.ndarray[Any, numpy.dtype[numpy.float64]], G: numpy.ndarray[Any, numpy.dtype[numpy.float64]]) Any [source]
Computes the element G(i,k) of the Hessian of the local quadratic model
- Parameters
i –
k –
x – position
x0 – initial position
f – function values
f0 – inital function value
g –
G –
- initbox(theta0: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f0: numpy.ndarray[Any, numpy.dtype[numpy.float32]], l: numpy.ndarray[Any, numpy.dtype[numpy.int32]], L: numpy.ndarray[Any, numpy.dtype[numpy.int32]], istar: numpy.ndarray[Any, numpy.dtype[Union[numpy.float32, numpy.float64]]], u: List[Union[float, int]], v: List[Union[float, int]], isplit: numpy.ndarray[Any, numpy.dtype[numpy.int32]], level: numpy.ndarray[Any, numpy.dtype[numpy.int32]], ipar: numpy.ndarray[Any, numpy.dtype[numpy.int32]], ichild: numpy.ndarray[Any, numpy.dtype[numpy.int32]], f: numpy.ndarray[Any, numpy.dtype[numpy.float32]], nboxes: int, prt: int)[source]
Generates the boxes in the initializaiton procedure
- Parameters
theta0 –
f0 – inital function value
l – Indication of the mid point
L – Indication of the end point (or total number of partition of the value x in the i’th dimenstion)
istar –
u –
v –
isplit –
level –
ipar –
ichild –
ichild –
f – function value of the splitinhg float value
nboxes – counter for boxes not in the ‘shopping bas
prt – print - unsued in this implementation so far
- neighbor(x: numpy.ndarray[Any, numpy.dtype[numpy.float32]], delta: List[float], u: List[Union[float, int]], v: List[Union[float, int]]) Tuple[List[Any], List[Any]] [source]
Computes ‘neighbors’ x1 and x2 of x needed for making triple search and building a local quadratic model such that x(i), x1(i), x2(i) are pairwise distinct for i = 1,…,n
- Parameters
x – current position
delta – radius of neighboring region
u –
v –
- polint1(x: List[float], f: List[float]) Tuple[float, float] [source]
Quadratic polynomial interpolation
- Parameters
x – positions
f – function values
- Returns
g, G
- splrnk(n: int, n0: numpy.ndarray[Any, numpy.dtype[numpy.float64]], p: numpy.ndarray[Any, numpy.dtype[numpy.int32]], x: numpy.ndarray[Any, numpy.dtype[numpy.float64]], y: numpy.ndarray[Any, numpy.dtype[numpy.float32]]) Tuple[int, float] [source]
Determines the splitting index and splitting value for splitting a box by rank
- Parameters
n – dimension of the problem
p – ranking of estimated variability of the function in the different coordinates
x – base vertex of the box
y – opposite vertex of the box
:return : splitting index and value at splitting point
- strtsw(smax: int, level: List[int], f: List[float], nboxes: int, record: numpy.ndarray[Any, numpy.dtype[Any]]) Tuple[int, numpy.ndarray[Any, numpy.dtype[numpy.int32]]] [source]
Function that does the strtsw
- Parameters
smax –
level –
f –
nboxes – counter for boxes not in the ‘shopping bas
record –
- updtrec(j: int, s: int, f: List[float], record: List[int]) List[int] [source]
Updates the pointer record(s) to the best non-split box at level s :param j: label of a box :param s: its level :param f: vector containing the base vertex function values of the already defined boxes. :param record: record list
- vertex(j: int, n: int, u: List[Union[float, int]], v: List[Union[float, int]], v1: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x0: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f0: numpy.ndarray[Any, numpy.dtype[numpy.float64]], ipar: numpy.ndarray[Any, numpy.dtype[numpy.int32]], isplit: numpy.ndarray[Any, numpy.dtype[numpy.int32]], ichild: numpy.ndarray[Any, numpy.dtype[numpy.int32]], z: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f: numpy.ndarray[Any, numpy.dtype[numpy.float64]], l: numpy.ndarray[Any, numpy.dtype[numpy.int32]], L: numpy.ndarray[Any, numpy.dtype[numpy.int32]])[source]
Vertex function
- Parameters
j – label
n –
u – the initial lower bound (“lower corner” in 3D)
v – the initial upper bound (“upper corner” in 3D)
v1 –
x0 – initial position
f0 – inital function value
ipar –
isplit –
ichild –
z –
f –
l – Indication of the mid point
L – Indication of the end point (or total number of partition of the value x in the i’th dimenstion)
- class csle_agents.agents.mcs.mcs_utils.mcs_fun.UtilHelpers[source]
Bases:
object
Class with utility functions for MCS
- polint(x: Union[List[float], numpy.ndarray[Any, numpy.dtype[numpy.float64]]], f: Union[List[float], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float32]]]) numpy.ndarray[Any, numpy.dtype[numpy.float64]] [source]
Quadratic polynomial interpolation
- Parameters
x – pairwise distinct support points
f – corresponding function values
- Return d
the value of the interpolating polynomial
- quadmin(a: float, b: float, d: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x0: Union[List[float], numpy.ndarray[Any, numpy.dtype[numpy.float64]]]) float [source]
The quadmin method
- Parameters
a –
b –
d –
x0 –
- Returns
- quadpol(x: float, d: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x0: Union[List[float], numpy.ndarray[Any, numpy.dtype[numpy.float64]]])[source]
Evaluates the quadratic polynomial
- Parameters
x – starting point
d – the value of the interpolating polynomial
x0 – initial position
- split1(x1: float, x2: float, f1: float, f2: float) float [source]
The split1 method
- Parameters
x1 –
x2 –
f1 –
f2 –
- Returns
- split2(x: float, y: float) float [source]
The split2 method. Determines a value x1 for splitting the interval [min(x,y),max(x,y)] is modeled on the function subint with safeguards for infinite y
- Parameters
x –
y –
- Returns
- subint(x1: float, x2: float) Tuple[float, float] [source]
Computes [min(x,y),max(x,y)] that are neither too close nor too far away from x
- Parameters
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
- updtf(n: int, i: int, x1: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x2: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f1: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f2: numpy.ndarray[Any, numpy.dtype[numpy.float64]], fold: Union[float, numpy.ndarray[Any, numpy.dtype[numpy.float64]]], f: numpy.ndarray[Any, numpy.dtype[numpy.float64]]) Tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]] [source]
updtf function
- Parameters
n –
i –
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
f1 – corresponding function value
f2 – corresponding function value
fold – former function value
f – function values
- Returns
- vert1(j: int, z: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x1: float, x2: float, f1: float, f2: float) Tuple[float, float, float, float, float] [source]
The vert1 method
- Parameters
j – label
z –
f – function value
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
f1 – corresponding function value
f2 – corresponding function value
- Returns
- vert2(j: int, x: float, z: numpy.ndarray[Any, numpy.dtype[numpy.float64]], f: numpy.ndarray[Any, numpy.dtype[numpy.float64]], x1: float, x2: float, f1: float, f2: float) Tuple[float, float, float, float] [source]
The vert2 function
- Parameters
j – label
x –
z –
f – function values
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
f1 – corresponding function value
f2 – corresponding function value
- vert3(j: int, x0, f0, L: int, x1: float, x2: float, f1: float, f2: float) Tuple[float, float, float, float] [source]
Vert3 function
- Parameters
j – label
x0 – initial position
f0 – inital function value
L –
x1 – corresponding parameter/coordinate value
x2 – corresponding parameter/coordinate value
f1 – corresponding function value
f2 – corresponding function value