adelie.adelie_core.constraint.ConstraintLinear64#

class adelie.adelie_core.constraint.ConstraintLinear64#

Core constraint class for linear constraint.

Methods

__init__(self, A, lower, n]], upper, n]], ...)

buffer_size(self)

Returns the buffer size in unit of 8 bytes.

clear(self)

Clears internal data.

dual(self, arg0, arg1)

Returns the current dual variable in sparse format.

duals(self)

Returns the number of dual variables.

duals_nnz(self)

Returns the number of non-zero dual values.

gradient(self, x, out)

Computes the gradient of the Lagrangian.

gradient_static(self, x, mu, out)

Computes the gradient of the Lagrangian.

primals(self)

Returns the number of primal variables.

project(self, x)

Computes a projection onto the feasible set.

solve(self, x, quad, linear, l1, l2, Q, buffer)

Computes the block-coordinate update.

solve_zero(self, arg0, arg1)

Solves the zero primal KKT condition problem.

Attributes

dual_size

Number of duals.

primal_size

Number of primals.

__init__(self: adelie.adelie_core.constraint.ConstraintLinear64, A: adelie_core::matrix::MatrixConstraintBase<double, long>, lower: numpy.ndarray[numpy.float64[1, n]], upper: numpy.ndarray[numpy.float64[1, n]], A_vars: numpy.ndarray[numpy.float64[1, n]], max_iters: int, tol: float, nnls_max_iters: int, nnls_tol: float, pinball_max_iters: int, pinball_tol: float, slack: float, n_threads: int) None#
buffer_size(self: adelie.adelie_core.constraint.ConstraintBase64) int#

Returns the buffer size in unit of 8 bytes.

Returns:
sizeint

Buffer size in unit of 8 bytes.

clear(self: adelie.adelie_core.constraint.ConstraintBase64) None#

Clears internal data.

The state of the constraint object must return back to that of the initial construction.

Warning

This function is not thread-safe!

dual(self: adelie.adelie_core.constraint.ConstraintBase64, arg0: numpy.ndarray[numpy.int64[1, n], flags.writeable], arg1: numpy.ndarray[numpy.float64[1, n], flags.writeable]) None#

Returns the current dual variable in sparse format.

Parameters:
indices(nnz,) ndarray

The indices with non-zero dual values. The size must be at least the value returned by duals_nnz().

values(nnz,) ndarray

The non-zero dual values corresponding to indices. The size must be at least the value returned by duals_nnz().

duals(self: adelie.adelie_core.constraint.ConstraintBase64) int#

Returns the number of dual variables.

Returns:
sizeint

Number of dual variables.

duals_nnz(self: adelie.adelie_core.constraint.ConstraintBase64) int#

Returns the number of non-zero dual values.

Returns:
nnzint

Number of non-zero dual values.

gradient(self: adelie.adelie_core.constraint.ConstraintBase64, x: numpy.ndarray[numpy.float64[1, n]], out: numpy.ndarray[numpy.float64[1, n], flags.writeable]) None#

Computes the gradient of the Lagrangian.

The gradient of the Lagrangian (with respect to the primal) is given by

\[\begin{align*} \mu^\top \phi'(x) \end{align*}\]

where \(\phi'(x)\) is the Jacobian of \(\phi\) at \(x\) and \(\mu\) is the dual solution from the last call to solve().

Parameters:
x(d,) ndarray

The primal \(x\) at which to evaluate the gradient.

out(d,) ndarray

The output vector to store the gradient.

gradient_static(self: adelie.adelie_core.constraint.ConstraintBase64, x: numpy.ndarray[numpy.float64[1, n]], mu: numpy.ndarray[numpy.float64[1, n]], out: numpy.ndarray[numpy.float64[1, n], flags.writeable]) None#

Computes the gradient of the Lagrangian.

The gradient of the Lagrangian (with respect to the primal) is given by

\[\begin{align*} \mu^\top \phi'(x) \end{align*}\]

where \(\phi'(x)\) is the Jacobian of \(\phi\) at \(x\) and \(\mu\) is the dual given by mu.

Parameters:
x(d,) ndarray

The primal \(x\) at which to evaluate the gradient.

mu(m,) ndarray

The dual \(\mu\) at which to evaluate the gradient.

out(d,) ndarray

The output vector to store the gradient.

primals(self: adelie.adelie_core.constraint.ConstraintBase64) int#

Returns the number of primal variables.

Returns:
sizeint

Number of primal variables.

project(self: adelie.adelie_core.constraint.ConstraintBase64, x: numpy.ndarray[numpy.float64[1, n], flags.writeable]) None#

Computes a projection onto the feasible set.

The feasible set is defined by \(\{x : \phi(x) \leq 0 \}\). A projection can be user-defined, that is, the user may define any norm \(\|\cdot\|\) such that the function returns a solution to

\[\begin{split}\begin{align*} \mathrm{minimize}_z \quad& \|x - z\| \\ \text{subject to} \quad& \phi(z) \leq 0 \end{align*}\end{split}\]

This function is only used by the solver after convergence to attempt to bring the coordinates into the feasible set. If not overriden, it will perform a no-op, assuming \(x\) is already feasible.

Parameters:
x(d,) ndarray

The primal \(x\) to project onto the feasible set. The output is stored back in this argument.

solve(self: adelie.adelie_core.constraint.ConstraintBase64, x: numpy.ndarray[numpy.float64[1, n], flags.writeable], quad: numpy.ndarray[numpy.float64[1, n]], linear: numpy.ndarray[numpy.float64[1, n]], l1: float, l2: float, Q: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], buffer: numpy.ndarray[numpy.uint64[1, n], flags.writeable]) None#

Computes the block-coordinate update.

The block-coordinate update is given by solving

\[\begin{split}\begin{align*} \mathrm{minimize}_x \quad& \frac{1}{2} x^\top \Sigma x - v^\top x + \lambda_1 \|x\|_2 + \frac{\lambda_2}{2} \|x\|_2^2 \\ \text{subject to} \quad& \phi(Q x) \leq 0 \end{align*}\end{split}\]

where \(\phi\) defines the current constraint.

Warning

This function is not thread-safe!

Parameters:
x(d,) ndarray

The primal \(x\). The passed-in values may be used as a warm-start for the internal solver. The output is stored back in this argument.

quad(d,) ndarray

The quadratic component \(\Sigma\).

linear(d,) ndarray

The linear component \(v\).

l1float

The first regularization \(\lambda_1\).

l2float

The second regularization \(\lambda_2\).

Q(d, d) ndarray

Orthogonal matrix \(Q\).

buffer(b,) ndarray

Buffer of type uint64_t aligned at 8 bytes. The size must be at least as large as buffer_size().

solve_zero(self: adelie.adelie_core.constraint.ConstraintBase64, arg0: numpy.ndarray[numpy.float64[1, n]], arg1: numpy.ndarray[numpy.uint64[1, n], flags.writeable]) float#

Solves the zero primal KKT condition problem.

The zero primal KKT condition problem is given by

\[\begin{align*} \mathrm{minimize}_{\mu \geq 0} \|v - \phi'(0)^\top \mu\|_2 \end{align*}\]

where \(\phi\) is the current constraint function and \(\mu\) is the dual variable. It is advised, but not necessary, that the object stores the solution internally so that a subsequent call to dual() will return the solution.

Warning

This function is not thread-safe!

Parameters:
v(d,) ndarray

The vector \(v\).

buffer(b,) ndarray

Buffer of type uint64_t aligned at 8 bytes. The size must be at least as large as buffer_size().

Returns:
normfloat

The optimal objective for the zero primal KKT condition problem.

dual_size#

Number of duals.

primal_size#

Number of primals.