optiml.opti.utils module
- optiml.opti.utils.solve_lagrangian_equality_constrained_quadratic(Q, q, A, b, method='gmres')[source]
Solve a quadratic function subject to equality constraint:
\[\tfrac{1}{2} x^\top Q x + q^\top x \quad : \quad A x = b\]by solving the KKT system:
\[\begin{split}\begin{bmatrix} Q & A^\top \\ A & 0 \end{bmatrix} \begin{bmatrix} x \\ \lambda \end{bmatrix} = \begin{bmatrix} -q \\ b \end{bmatrix}\end{split}\]See more @ https://www.math.uh.edu/~rohop/fall_06/Chapter3.pdf
- optiml.opti.utils.generate_box_constrained_quadratic(ndim=2, actv=0.5, rank=1.1, ecc=0.99, ub_min=8, ub_max=12, seed=123456)[source]
Generate a box-constrained quadratic function defined as:
\[\tfrac{1}{2} x^\top Q x + q^\top x \quad : \quad 0 \le x \le ub\]- Parameters:
ndim – (integer, scalar): the size of the problem
actv – (real, scalar, default 0.5): how many box constraints (as a fraction of the number of variables n of the problems) the unconstrained optimum will violate, and therefore we expect to be active in the constrained optimum; note that there is no guarantee that exactly acvt constraints will be active, they may be less or (more likely) more, except when actv = 0 because then the unconstrained optimum is surely feasible and therefore it will be the constrained optimum as well
rank – (real, scalar, default 1.1): Q will be obtained as \(Q = G^\top G\), with G a \(m \times n\) random matrix with \(m = \text{rank} \cdot n\). If rank > 1 then Q can be expected to be full-rank, if rank < 1 it will not
ecc – (real, scalar, default 0.99): the eccentricity of Q, i.e., the ratio \((\lambda_1 - \lambda_n) / (\lambda_1 + \lambda_n)\), with \(\lambda_1\) the largest eigenvalue and \(\lambda_n\) the smallest one. Note that this makes sense only if \(\lambda_n > 0\), for otherwise the eccentricity is always 1; hence, this setting is ignored if \(\lambda_n = 0\), i.e., Q is not full-rank (see above). An eccentricity of 0 means that all eigenvalues are equal, as eccentricity \(\to 1\) the largest eigenvalue gets larger and larger w.r.t. the smallest one
seed – (integer, default 0): the seed for the random number generator
ub_min – (real, scalar, default 8): the minimum value of each \(ub_i\)
ub_max – (real, scalar, default 12): the maximum value of each \(ub_i\)
- optiml.opti.utils.plot_surface_contour(f, x_min, x_max, y_min, y_max, ub=None, primal=True)[source]