adelie.adelie_core.constraint.ConstraintBase64#

class adelie.adelie_core.constraint.ConstraintBase64#

Base constraint class.

The purpose of a constraint class is to define methods that update certain quantities that are required for solving the constrained group lasso problem.

Every constraint-like class must inherit from this class and override the methods before passing into the solver.

Methods

__init__(self)

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.ConstraintBase64) 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.

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.

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.

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.