Lightweight utilities for working with structured flat vectors and block matrices in NumPy.
Consider a Newton algorithm for solving the KKT conditions, as described here:
where the grey components are only required when inequality constraints are present.
from vector_structure import VectorStructure
structure = [("x", n)]
if ineq_constraints:
structure.append(("lambda", m))
structure.append(("mu", p))
vs = VectorStructure(structure)
M = np.zeros((vs.size, vs.size))
M[vs["x"], vs["x"]] = nabla2(f)(x)
if ineq_constraints:
M[vs["x"], vs["lambda"]] = Df(x).T
M[vs["x"], vs["mu"]] = A
...
x_lambda_mu = np.linalg.solve(M, r)
x = x_lambda_mu[vs["x"]]
if ineq_constraints:
lambda = x_lambda_mu[vs["lambda"]]For the full documentation, see here