Title: | Disciplined Convex Optimization |
---|---|
Description: | An object-oriented modeling language for disciplined convex programming (DCP) as described in Fu, Narasimhan, and Boyd (2020, <doi:10.18637/jss.v094.i14>). It allows the user to formulate convex optimization problems in a natural way following mathematical convention and DCP rules. The system analyzes the problem, verifies its convexity, converts it into a canonical form, and hands it off to an appropriate solver to obtain the solution. Interfaces to solvers on CRAN and elsewhere are provided, both commercial and open source. |
Authors: | Anqi Fu [aut, cre], Balasubramanian Narasimhan [aut], David W Kang [aut], Steven Diamond [aut], John Miller [aut], Stephen Boyd [ctb], Paul Kunsberg Rosenfield [ctb] |
Maintainer: | Anqi Fu <[email protected]> |
License: | Apache License 2.0 | file LICENSE |
Version: | 1.0-15 |
Built: | 2024-11-07 20:44:54 UTC |
Source: | https://github.com/cvxgrp/cvxr |
This class represents the negation of an affine expression.
## S4 method for signature 'Expression,missing' e1 - e2 ## S4 method for signature 'Expression,Expression' e1 - e2 ## S4 method for signature 'Expression,ConstVal' e1 - e2 ## S4 method for signature 'ConstVal,Expression' e1 - e2 ## S4 method for signature 'NegExpression' dim_from_args(object) ## S4 method for signature 'NegExpression' sign_from_args(object) ## S4 method for signature 'NegExpression' is_incr(object, idx) ## S4 method for signature 'NegExpression' is_decr(object, idx) ## S4 method for signature 'NegExpression' is_symmetric(object) ## S4 method for signature 'NegExpression' is_hermitian(object) ## S4 method for signature 'NegExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Expression,missing' e1 - e2 ## S4 method for signature 'Expression,Expression' e1 - e2 ## S4 method for signature 'Expression,ConstVal' e1 - e2 ## S4 method for signature 'ConstVal,Expression' e1 - e2 ## S4 method for signature 'NegExpression' dim_from_args(object) ## S4 method for signature 'NegExpression' sign_from_args(object) ## S4 method for signature 'NegExpression' is_incr(object, idx) ## S4 method for signature 'NegExpression' is_decr(object, idx) ## S4 method for signature 'NegExpression' is_symmetric(object) ## S4 method for signature 'NegExpression' is_hermitian(object) ## S4 method for signature 'NegExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
e1 , e2
|
The Expression objects or numeric constants to subtract. |
object |
A NegExpression object. |
idx |
An index into the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
dim_from_args(NegExpression)
: The (row, col) dimensions of the expression.
sign_from_args(NegExpression)
: The (is positive, is negative) sign of the expression.
is_incr(NegExpression)
: The expression is not weakly increasing in any argument.
is_decr(NegExpression)
: The expression is weakly decreasing in every argument.
is_symmetric(NegExpression)
: Is the expression symmetric?
is_hermitian(NegExpression)
: Is the expression Hermitian?
graph_implementation(NegExpression)
: The graph implementation of the expression.
sparse
flag field for the LinOp objectGet the sparse
flag field for the LinOp object
.build_matrix_0(xp, v)
.build_matrix_0(xp, v)
xp |
the LinOpVector Object XPtr |
v |
the |
a XPtr to ProblemData Object
sparse
flag field for the LinOp objectGet the sparse
flag field for the LinOp object
.build_matrix_1(xp, v1, v2)
.build_matrix_1(xp, v1, v2)
xp |
the LinOpVector Object XPtr |
v1 |
the |
v2 |
the |
a XPtr to ProblemData Object
Compute sgn, scale, M such that .
.decomp_quad(P, cond = NA, rcond = NA)
.decomp_quad(P, cond = NA, rcond = NA)
P |
A real symmetric positive or negative (semi)definite input matrix |
cond |
Cutoff for small eigenvalues. Singular values smaller than rcond * largest_eigenvalue are considered negligible. |
rcond |
Cutoff for small eigenvalues. Singular values smaller than rcond * largest_eigenvalue are considered negligible. |
A list consisting of induced matrix 2-norm of P and a rectangular matrix such that P = scale * (dot(M1, t(M1)) - dot(M2, t(M2)))
args
field of LinOpPerform a push back operation on the args
field of LinOp
.LinOp__args_push_back(xp, yp)
.LinOp__args_push_back(xp, yp)
xp |
the LinOp Object XPtr |
yp |
the LinOp Object XPtr to push |
dense_data
for the LinOp objectGet the field dense_data
for the LinOp object
.LinOp__get_dense_data(xp)
.LinOp__get_dense_data(xp)
xp |
the LinOp Object XPtr |
a MatrixXd object
Get the id field of the LinOp Object
.LinOp__get_id(xp)
.LinOp__get_id(xp)
xp |
the LinOp Object XPtr |
the value of the id field of the LinOp Object
size
for the LinOp objectGet the field size
for the LinOp object
.LinOp__get_size(xp)
.LinOp__get_size(xp)
xp |
the LinOp Object XPtr |
an integer vector
Get the slice field of the LinOp Object
.LinOp__get_slice(xp)
.LinOp__get_slice(xp)
xp |
the LinOp Object XPtr |
the value of the slice field of the LinOp Object
sparse
flag field for the LinOp objectGet the sparse
flag field for the LinOp object
.LinOp__get_sparse(xp)
.LinOp__get_sparse(xp)
xp |
the LinOp Object XPtr |
TRUE or FALSE
sparse_data
from the LinOp objectGet the field named sparse_data
from the LinOp object
.LinOp__get_sparse_data(xp)
.LinOp__get_sparse_data(xp)
xp |
the LinOp Object XPtr |
a dgCMatrix-class object
type
for the LinOp objectGet the field named type
for the LinOp object
.LinOp__get_type(xp)
.LinOp__get_type(xp)
xp |
the LinOp Object XPtr |
an integer value for type
Create a new LinOp object.
.LinOp__new()
.LinOp__new()
an external ptr (Rcpp::XPtr) to a LinOp object instance.
dense_data
of the LinOp objectSet the field dense_data
of the LinOp object
.LinOp__set_dense_data(xp, denseMat)
.LinOp__set_dense_data(xp, denseMat)
xp |
the LinOp Object XPtr |
denseMat |
a standard matrix object in R |
size
of the LinOp objectSet the field size
of the LinOp object
.LinOp__set_size(xp, value)
.LinOp__set_size(xp, value)
xp |
the LinOp Object XPtr |
value |
an integer vector object in R |
Set the slice field of the LinOp Object
.LinOp__set_slice(xp, value)
.LinOp__set_slice(xp, value)
xp |
the LinOp Object XPtr |
value |
a list of integer vectors, e.g. |
the value of the slice field of the LinOp Object
sparse
of the LinOp objectSet the flag sparse
of the LinOp object
.LinOp__set_sparse(xp, sparseSEXP)
.LinOp__set_sparse(xp, sparseSEXP)
xp |
the LinOp Object XPtr |
sparseSEXP |
an R boolean |
sparse_data
of the LinOp objectSet the field named sparse_data
of the LinOp object
.LinOp__set_sparse_data(xp, sparseMat)
.LinOp__set_sparse_data(xp, sparseMat)
xp |
the LinOp Object XPtr |
sparseMat |
a dgCMatrix-class object |
type
for the LinOp objectSet the field named type
for the LinOp object
.LinOp__set_type(xp, typeValue)
.LinOp__set_type(xp, typeValue)
xp |
the LinOp Object XPtr |
typeValue |
an integer value |
size
field of LinOpPerform a push back operation on the size
field of LinOp
.LinOp__size_push_back(xp, intVal)
.LinOp__size_push_back(xp, intVal)
xp |
the LinOp Object XPtr |
intVal |
the integer value to push back |
slice
field of LinOpPerform a push back operation on the slice
field of LinOp
.LinOp__slice_push_back(xp, intVec)
.LinOp__slice_push_back(xp, intVec)
xp |
the LinOp Object XPtr |
intVec |
an integer vector to push back |
Return the LinOp element at index i (0-based)
.LinOp_at_index(lvec, i)
.LinOp_at_index(lvec, i)
lvec |
the LinOpVector Object XPtr |
i |
the index |
Create a new LinOpVector object.
.LinOpVector__new()
.LinOpVector__new()
an external ptr (Rcpp::XPtr) to a LinOp object instance.
args
field of LinOpPerform a push back operation on the args
field of LinOp
.LinOpVector__push_back(xp, yp)
.LinOpVector__push_back(xp, yp)
xp |
the LinOpVector Object XPtr |
yp |
the LinOp Object XPtr to push |
Internal method for calculating the p-norm
.p_norm(x, p)
.p_norm(x, p)
x |
A matrix |
p |
A number grater than or equal to 1, or equal to positive infinity |
Returns the specified norm of matrix x
Get the const_to_row field of the ProblemData Object
.ProblemData__get_const_to_row(xp)
.ProblemData__get_const_to_row(xp)
xp |
the ProblemData Object XPtr |
the const_to_row field as a named integer vector where the names are integers converted to characters
Get the const_vec field from the ProblemData Object
.ProblemData__get_const_vec(xp)
.ProblemData__get_const_vec(xp)
xp |
the ProblemData Object XPtr |
a numeric vector of the field const_vec from the ProblemData Object
Get the I field of the ProblemData Object
.ProblemData__get_I(xp)
.ProblemData__get_I(xp)
xp |
the ProblemData Object XPtr |
an integer vector of the field I from the ProblemData Object
Get the id_to_col field of the ProblemData Object
.ProblemData__get_id_to_col(xp)
.ProblemData__get_id_to_col(xp)
xp |
the ProblemData Object XPtr |
the id_to_col field as a named integer vector where the names are integers converted to characters
Get the J field of the ProblemData Object
.ProblemData__get_J(xp)
.ProblemData__get_J(xp)
xp |
the ProblemData Object XPtr |
an integer vector of the field J from the ProblemData Object
Get the V field of the ProblemData Object
.ProblemData__get_V(xp)
.ProblemData__get_V(xp)
xp |
the ProblemData Object XPtr |
a numeric vector of doubles (the field V) from the ProblemData Object
Create a new ProblemData object.
.ProblemData__new()
.ProblemData__new()
an external ptr (Rcpp::XPtr) to a ProblemData object instance.
Set the const_to_row map of the ProblemData Object
.ProblemData__set_const_to_row(xp, iv)
.ProblemData__set_const_to_row(xp, iv)
xp |
the ProblemData Object XPtr |
iv |
a named integer vector with names being integers converted to characters |
Set the const_vec field in the ProblemData Object
.ProblemData__set_const_vec(xp, cvp)
.ProblemData__set_const_vec(xp, cvp)
xp |
the ProblemData Object XPtr |
cvp |
a numeric vector of values for const_vec field of the ProblemData object |
Set the I field in the ProblemData Object
.ProblemData__set_I(xp, ip)
.ProblemData__set_I(xp, ip)
xp |
the ProblemData Object XPtr |
ip |
an integer vector of values for field I of the ProblemData object |
Set the id_to_col field of the ProblemData Object
.ProblemData__set_id_to_col(xp, iv)
.ProblemData__set_id_to_col(xp, iv)
xp |
the ProblemData Object XPtr |
iv |
a named integer vector with names being integers converted to characters |
Set the J field in the ProblemData Object
.ProblemData__set_J(xp, jp)
.ProblemData__set_J(xp, jp)
xp |
the ProblemData Object XPtr |
jp |
an integer vector of the values for field J of the ProblemData object |
Set the V field in the ProblemData Object
.ProblemData__set_V(xp, vp)
.ProblemData__set_V(xp, vp)
xp |
the ProblemData Object XPtr |
vp |
a numeric vector of values for field V |
This class represents indexing using logical indexing or a list of indices into a matrix.
## S4 method for signature 'Expression,index,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,missing,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,index,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,index,matrix,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,matrix,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,missing,ANY' x[i, j, ..., drop = TRUE] SpecialIndex(expr, key) ## S4 method for signature 'SpecialIndex' name(x) ## S4 method for signature 'SpecialIndex' is_atom_log_log_convex(object) ## S4 method for signature 'SpecialIndex' is_atom_log_log_concave(object) ## S4 method for signature 'SpecialIndex' get_data(object) ## S4 method for signature 'SpecialIndex' .grad(object)
## S4 method for signature 'Expression,index,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,missing,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,index,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,index,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,index,matrix,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,matrix,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,matrix,missing,ANY' x[i, j, ..., drop = TRUE] SpecialIndex(expr, key) ## S4 method for signature 'SpecialIndex' name(x) ## S4 method for signature 'SpecialIndex' is_atom_log_log_convex(object) ## S4 method for signature 'SpecialIndex' is_atom_log_log_concave(object) ## S4 method for signature 'SpecialIndex' get_data(object) ## S4 method for signature 'SpecialIndex' .grad(object)
x , object
|
An Index object. |
i , j
|
The row and column indices of the slice. |
... |
(Unimplemented) Optional arguments. |
drop |
(Unimplemented) A logical value indicating whether the result should be coerced to the lowest possible dimension. |
expr |
An Expression representing a vector or matrix. |
key |
A list containing the start index, end index, and step size of the slice. |
name(SpecialIndex)
: Returns the index in string form.
is_atom_log_log_convex(SpecialIndex)
: Is the atom log-log convex?
is_atom_log_log_concave(SpecialIndex)
: Is the atom log-log concave?
get_data(SpecialIndex)
: A list containing key
.
.grad(SpecialIndex)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
expr
An Expression representing a vector or matrix.
key
A list containing the start index, end index, and step size of the slice.
This class represents indexing or slicing into a matrix.
## S4 method for signature 'Expression,missing,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,numeric,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,missing,numeric,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,numeric,numeric,ANY' x[i, j, ..., drop = TRUE] Index(expr, key) ## S4 method for signature 'Index' to_numeric(object, values) ## S4 method for signature 'Index' dim_from_args(object) ## S4 method for signature 'Index' is_atom_log_log_convex(object) ## S4 method for signature 'Index' is_atom_log_log_concave(object) ## S4 method for signature 'Index' get_data(object) ## S4 method for signature 'Index' graph_implementation(object, arg_objs, dim, data = NA_real_) ## S4 method for signature 'SpecialIndex' to_numeric(object, values) ## S4 method for signature 'SpecialIndex' dim_from_args(object)
## S4 method for signature 'Expression,missing,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,numeric,missing,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,missing,numeric,ANY' x[i, j, ..., drop = TRUE] ## S4 method for signature 'Expression,numeric,numeric,ANY' x[i, j, ..., drop = TRUE] Index(expr, key) ## S4 method for signature 'Index' to_numeric(object, values) ## S4 method for signature 'Index' dim_from_args(object) ## S4 method for signature 'Index' is_atom_log_log_convex(object) ## S4 method for signature 'Index' is_atom_log_log_concave(object) ## S4 method for signature 'Index' get_data(object) ## S4 method for signature 'Index' graph_implementation(object, arg_objs, dim, data = NA_real_) ## S4 method for signature 'SpecialIndex' to_numeric(object, values) ## S4 method for signature 'SpecialIndex' dim_from_args(object)
x |
A Expression object. |
i , j
|
The row and column indices of the slice. |
... |
(Unimplemented) Optional arguments. |
drop |
(Unimplemented) A logical value indicating whether the result should be coerced to the lowest possible dimension. |
expr |
An Expression representing a vector or matrix. |
key |
A list containing the start index, end index, and step size of the slice. |
object |
An Index object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Index)
: The index/slice into the given value.
dim_from_args(Index)
: The dimensions of the atom.
is_atom_log_log_convex(Index)
: Is the atom log-log convex?
is_atom_log_log_concave(Index)
: Is the atom log-log concave?
get_data(Index)
: A list containing key
.
graph_implementation(Index)
: The graph implementation of the atom.
to_numeric(SpecialIndex)
: The index/slice into the given value.
dim_from_args(SpecialIndex)
: The dimensions of the atom.
expr
An Expression representing a vector or matrix.
key
A list containing the start index, end index, and step size of the slice.
Elementwise multiplication operator
## S4 method for signature 'Expression,Expression' e1 * e2 ## S4 method for signature 'Expression,ConstVal' e1 * e2 ## S4 method for signature 'ConstVal,Expression' e1 * e2
## S4 method for signature 'Expression,Expression' e1 * e2 ## S4 method for signature 'Expression,ConstVal' e1 * e2 ## S4 method for signature 'ConstVal,Expression' e1 * e2
e1 , e2
|
The Expression objects or numeric constants to multiply elementwise. |
This class represents one expression divided by another expression.
## S4 method for signature 'Expression,Expression' e1 / e2 ## S4 method for signature 'Expression,ConstVal' e1 / e2 ## S4 method for signature 'ConstVal,Expression' e1 / e2 ## S4 method for signature 'DivExpression' to_numeric(object, values) ## S4 method for signature 'DivExpression' is_quadratic(object) ## S4 method for signature 'DivExpression' is_qpwa(object) ## S4 method for signature 'DivExpression' dim_from_args(object) ## S4 method for signature 'DivExpression' is_atom_convex(object) ## S4 method for signature 'DivExpression' is_atom_concave(object) ## S4 method for signature 'DivExpression' is_atom_log_log_convex(object) ## S4 method for signature 'DivExpression' is_atom_log_log_concave(object) ## S4 method for signature 'DivExpression' is_incr(object, idx) ## S4 method for signature 'DivExpression' is_decr(object, idx) ## S4 method for signature 'DivExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Expression,Expression' e1 / e2 ## S4 method for signature 'Expression,ConstVal' e1 / e2 ## S4 method for signature 'ConstVal,Expression' e1 / e2 ## S4 method for signature 'DivExpression' to_numeric(object, values) ## S4 method for signature 'DivExpression' is_quadratic(object) ## S4 method for signature 'DivExpression' is_qpwa(object) ## S4 method for signature 'DivExpression' dim_from_args(object) ## S4 method for signature 'DivExpression' is_atom_convex(object) ## S4 method for signature 'DivExpression' is_atom_concave(object) ## S4 method for signature 'DivExpression' is_atom_log_log_convex(object) ## S4 method for signature 'DivExpression' is_atom_log_log_concave(object) ## S4 method for signature 'DivExpression' is_incr(object, idx) ## S4 method for signature 'DivExpression' is_decr(object, idx) ## S4 method for signature 'DivExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
e1 , e2
|
The Expression objects or numeric constants to divide. The denominator, |
object |
A DivExpression object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(DivExpression)
: Matrix division by a scalar.
is_quadratic(DivExpression)
: Is the left-hand expression quadratic and the right-hand expression constant?
is_qpwa(DivExpression)
: Is the expression quadratic of piecewise affine?
dim_from_args(DivExpression)
: The (row, col) dimensions of the left-hand expression.
is_atom_convex(DivExpression)
: Division is convex (affine) in its arguments only if the denominator is constant.
is_atom_concave(DivExpression)
: Division is concave (affine) in its arguments only if the denominator is constant.
is_atom_log_log_convex(DivExpression)
: Is the atom log-log convex?
is_atom_log_log_concave(DivExpression)
: Is the atom log-log concave?
is_incr(DivExpression)
: Is the right-hand expression positive?
is_decr(DivExpression)
: Is the right-hand expression negative?
graph_implementation(DivExpression)
: The graph implementation of the expression.
This class represents the matrix product of two linear expressions. See Multiply for the elementwise product.
## S4 method for signature 'Expression,Expression' x %*% y ## S4 method for signature 'Expression,ConstVal' x %*% y ## S4 method for signature 'ConstVal,Expression' x %*% y ## S4 method for signature 'MulExpression' to_numeric(object, values) ## S4 method for signature 'MulExpression' dim_from_args(object) ## S4 method for signature 'MulExpression' is_atom_convex(object) ## S4 method for signature 'MulExpression' is_atom_concave(object) ## S4 method for signature 'MulExpression' is_atom_log_log_convex(object) ## S4 method for signature 'MulExpression' is_atom_log_log_concave(object) ## S4 method for signature 'MulExpression' is_incr(object, idx) ## S4 method for signature 'MulExpression' is_decr(object, idx) ## S4 method for signature 'MulExpression' .grad(object, values) ## S4 method for signature 'MulExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Expression,Expression' x %*% y ## S4 method for signature 'Expression,ConstVal' x %*% y ## S4 method for signature 'ConstVal,Expression' x %*% y ## S4 method for signature 'MulExpression' to_numeric(object, values) ## S4 method for signature 'MulExpression' dim_from_args(object) ## S4 method for signature 'MulExpression' is_atom_convex(object) ## S4 method for signature 'MulExpression' is_atom_concave(object) ## S4 method for signature 'MulExpression' is_atom_log_log_convex(object) ## S4 method for signature 'MulExpression' is_atom_log_log_concave(object) ## S4 method for signature 'MulExpression' is_incr(object, idx) ## S4 method for signature 'MulExpression' is_decr(object, idx) ## S4 method for signature 'MulExpression' .grad(object, values) ## S4 method for signature 'MulExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
x , y
|
The Expression objects or numeric constants to multiply. |
object |
A MulExpression object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(MulExpression)
: Matrix multiplication.
dim_from_args(MulExpression)
: The (row, col) dimensions of the expression.
is_atom_convex(MulExpression)
: Multiplication is convex (affine) in its arguments only if one of the arguments is constant.
is_atom_concave(MulExpression)
: If the multiplication atom is convex, then it is affine.
is_atom_log_log_convex(MulExpression)
: Is the atom log-log convex?
is_atom_log_log_concave(MulExpression)
: Is the atom log-log concave?
is_incr(MulExpression)
: Is the left-hand expression positive?
is_decr(MulExpression)
: Is the left-hand expression negative?
.grad(MulExpression)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
graph_implementation(MulExpression)
: The graph implementation of the expression.
This class represents the positive semidefinite constraint, , i.e.
for all
.
e1 %>>% e2 e1 %<<% e2 ## S4 method for signature 'Expression,Expression' e1 %>>% e2 ## S4 method for signature 'Expression,ConstVal' e1 %>>% e2 ## S4 method for signature 'ConstVal,Expression' e1 %>>% e2 ## S4 method for signature 'Expression,Expression' e1 %<<% e2 ## S4 method for signature 'Expression,ConstVal' e1 %<<% e2 ## S4 method for signature 'ConstVal,Expression' e1 %<<% e2 PSDConstraint(expr, id = NA_integer_) ## S4 method for signature 'PSDConstraint' name(x) ## S4 method for signature 'PSDConstraint' is_dcp(object) ## S4 method for signature 'PSDConstraint' is_dgp(object) ## S4 method for signature 'PSDConstraint' residual(object) ## S4 method for signature 'PSDConstraint' canonicalize(object)
e1 %>>% e2 e1 %<<% e2 ## S4 method for signature 'Expression,Expression' e1 %>>% e2 ## S4 method for signature 'Expression,ConstVal' e1 %>>% e2 ## S4 method for signature 'ConstVal,Expression' e1 %>>% e2 ## S4 method for signature 'Expression,Expression' e1 %<<% e2 ## S4 method for signature 'Expression,ConstVal' e1 %<<% e2 ## S4 method for signature 'ConstVal,Expression' e1 %<<% e2 PSDConstraint(expr, id = NA_integer_) ## S4 method for signature 'PSDConstraint' name(x) ## S4 method for signature 'PSDConstraint' is_dcp(object) ## S4 method for signature 'PSDConstraint' is_dgp(object) ## S4 method for signature 'PSDConstraint' residual(object) ## S4 method for signature 'PSDConstraint' canonicalize(object)
e1 , e2
|
The Expression objects or numeric constants to compare. |
expr |
An Expression, numeric element, vector, or matrix representing |
id |
(Optional) A numeric value representing the constraint ID. |
x , object
|
A PSDConstraint object. |
name(PSDConstraint)
: The string representation of the constraint.
is_dcp(PSDConstraint)
: The constraint is DCP if the left-hand and right-hand expressions are affine.
is_dgp(PSDConstraint)
: Is the constraint DGP?
residual(PSDConstraint)
: A Expression representing the residual of the constraint.
canonicalize(PSDConstraint)
: The graph implementation of the object. Marks the top level constraint as the dual_holder
so the dual value will be saved to the PSDConstraint.
expr
An Expression, numeric element, vector, or matrix representing .
Raises each element of the input to the power .
If
expr
is a CVXR expression, then expr^p
is equivalent to power(expr,p)
.
## S4 method for signature 'Expression,numeric' e1 ^ e2 power(x, p, max_denom = 1024)
## S4 method for signature 'Expression,numeric' e1 ^ e2 power(x, p, max_denom = 1024)
e1 |
An Expression object to exponentiate. |
e2 |
The power of the exponential. Must be a numeric scalar. |
x |
An Expression, vector, or matrix. |
p |
A scalar value indicating the exponential power. |
max_denom |
The maximum denominator considered in forming a rational approximation of |
For and
, this function is constant and positive.
For
and
, this function is affine, increasing, and the same sign as
.
For
and
, this function is convex, positive, with signed monotonicity.
For
and
for
, this function is convex, decreasing, and positive.
For and
for
, this function is concave, increasing, and positivea.
For and
for
, this function is convex, increasing, and positive.
## Not run: x <- Variable() prob <- Problem(Minimize(power(x,1.7) + power(x,-2.3) - power(x,0.45))) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
## Not run: x <- Variable() prob <- Problem(Minimize(power(x,1.7) + power(x,-2.3) - power(x,0.45))) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
This class represents the sum of any number of expressions.
## S4 method for signature 'Expression,missing' e1 + e2 ## S4 method for signature 'Expression,Expression' e1 + e2 ## S4 method for signature 'Expression,ConstVal' e1 + e2 ## S4 method for signature 'ConstVal,Expression' e1 + e2 ## S4 method for signature 'AddExpression' dim_from_args(object) ## S4 method for signature 'AddExpression' name(x) ## S4 method for signature 'AddExpression' to_numeric(object, values) ## S4 method for signature 'AddExpression' is_atom_log_log_convex(object) ## S4 method for signature 'AddExpression' is_atom_log_log_concave(object) ## S4 method for signature 'AddExpression' is_symmetric(object) ## S4 method for signature 'AddExpression' is_hermitian(object) ## S4 method for signature 'AddExpression' copy(object, args = NULL, id_objects = list()) ## S4 method for signature 'AddExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Expression,missing' e1 + e2 ## S4 method for signature 'Expression,Expression' e1 + e2 ## S4 method for signature 'Expression,ConstVal' e1 + e2 ## S4 method for signature 'ConstVal,Expression' e1 + e2 ## S4 method for signature 'AddExpression' dim_from_args(object) ## S4 method for signature 'AddExpression' name(x) ## S4 method for signature 'AddExpression' to_numeric(object, values) ## S4 method for signature 'AddExpression' is_atom_log_log_convex(object) ## S4 method for signature 'AddExpression' is_atom_log_log_concave(object) ## S4 method for signature 'AddExpression' is_symmetric(object) ## S4 method for signature 'AddExpression' is_hermitian(object) ## S4 method for signature 'AddExpression' copy(object, args = NULL, id_objects = list()) ## S4 method for signature 'AddExpression' graph_implementation(object, arg_objs, dim, data = NA_real_)
e1 , e2
|
The Expression objects or numeric constants to add. |
x , object
|
An AddExpression object. |
values |
A list of arguments to the atom. |
args |
An optional list of arguments to reconstruct the atom. Default is to use current args of the atom. |
id_objects |
Currently unused. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
dim_from_args(AddExpression)
: The dimensions of the expression.
name(AddExpression)
: The string form of the expression.
to_numeric(AddExpression)
: Sum all the values.
is_atom_log_log_convex(AddExpression)
: Is the atom log-log convex?
is_atom_log_log_concave(AddExpression)
: Is the atom log-log convex?
is_symmetric(AddExpression)
: Is the atom symmetric?
is_hermitian(AddExpression)
: Is the atom hermitian?
copy(AddExpression)
: Returns a shallow copy of the AddExpression atom
graph_implementation(AddExpression)
: The graph implementation of the expression.
arg_groups
A list
of Expressions and numeric data.frame, matrix, or vector objects.
The IneqConstraint class
## S4 method for signature 'Expression,Expression' e1 <= e2 ## S4 method for signature 'Expression,ConstVal' e1 <= e2 ## S4 method for signature 'ConstVal,Expression' e1 <= e2 ## S4 method for signature 'Expression,Expression' e1 < e2 ## S4 method for signature 'Expression,ConstVal' e1 < e2 ## S4 method for signature 'ConstVal,Expression' e1 < e2 ## S4 method for signature 'Expression,Expression' e1 >= e2 ## S4 method for signature 'Expression,ConstVal' e1 >= e2 ## S4 method for signature 'ConstVal,Expression' e1 >= e2 ## S4 method for signature 'Expression,Expression' e1 > e2 ## S4 method for signature 'Expression,ConstVal' e1 > e2 ## S4 method for signature 'ConstVal,Expression' e1 > e2 ## S4 method for signature 'IneqConstraint' name(x) ## S4 method for signature 'IneqConstraint' dim(x) ## S4 method for signature 'IneqConstraint' size(object) ## S4 method for signature 'IneqConstraint' expr(object) ## S4 method for signature 'IneqConstraint' is_dcp(object) ## S4 method for signature 'IneqConstraint' is_dgp(object) ## S4 method for signature 'IneqConstraint' residual(object)
## S4 method for signature 'Expression,Expression' e1 <= e2 ## S4 method for signature 'Expression,ConstVal' e1 <= e2 ## S4 method for signature 'ConstVal,Expression' e1 <= e2 ## S4 method for signature 'Expression,Expression' e1 < e2 ## S4 method for signature 'Expression,ConstVal' e1 < e2 ## S4 method for signature 'ConstVal,Expression' e1 < e2 ## S4 method for signature 'Expression,Expression' e1 >= e2 ## S4 method for signature 'Expression,ConstVal' e1 >= e2 ## S4 method for signature 'ConstVal,Expression' e1 >= e2 ## S4 method for signature 'Expression,Expression' e1 > e2 ## S4 method for signature 'Expression,ConstVal' e1 > e2 ## S4 method for signature 'ConstVal,Expression' e1 > e2 ## S4 method for signature 'IneqConstraint' name(x) ## S4 method for signature 'IneqConstraint' dim(x) ## S4 method for signature 'IneqConstraint' size(object) ## S4 method for signature 'IneqConstraint' expr(object) ## S4 method for signature 'IneqConstraint' is_dcp(object) ## S4 method for signature 'IneqConstraint' is_dgp(object) ## S4 method for signature 'IneqConstraint' residual(object)
e1 , e2
|
The Expression objects or numeric constants to compare. |
x , object
|
A IneqConstraint object. |
name(IneqConstraint)
: The string representation of the constraint.
dim(IneqConstraint)
: The dimensions of the constrained expression.
size(IneqConstraint)
: The size of the constrained expression.
expr(IneqConstraint)
: The expression to constrain.
is_dcp(IneqConstraint)
: A non-positive constraint is DCP if its argument is convex.
is_dgp(IneqConstraint)
: Is the constraint DGP?
residual(IneqConstraint)
: The residual of the constraint.
The EqConstraint class
## S4 method for signature 'Expression,Expression' e1 == e2 ## S4 method for signature 'Expression,ConstVal' e1 == e2 ## S4 method for signature 'ConstVal,Expression' e1 == e2 ## S4 method for signature 'EqConstraint' name(x) ## S4 method for signature 'EqConstraint' dim(x) ## S4 method for signature 'EqConstraint' size(object) ## S4 method for signature 'EqConstraint' expr(object) ## S4 method for signature 'EqConstraint' is_dcp(object) ## S4 method for signature 'EqConstraint' is_dgp(object) ## S4 method for signature 'EqConstraint' residual(object)
## S4 method for signature 'Expression,Expression' e1 == e2 ## S4 method for signature 'Expression,ConstVal' e1 == e2 ## S4 method for signature 'ConstVal,Expression' e1 == e2 ## S4 method for signature 'EqConstraint' name(x) ## S4 method for signature 'EqConstraint' dim(x) ## S4 method for signature 'EqConstraint' size(object) ## S4 method for signature 'EqConstraint' expr(object) ## S4 method for signature 'EqConstraint' is_dcp(object) ## S4 method for signature 'EqConstraint' is_dgp(object) ## S4 method for signature 'EqConstraint' residual(object)
e1 , e2
|
The Expression objects or numeric constants to compare. |
x , object
|
A EqConstraint object. |
name(EqConstraint)
: The string representation of the constraint.
dim(EqConstraint)
: The dimensions of the constrained expression.
size(EqConstraint)
: The size of the constrained expression.
expr(EqConstraint)
: The expression to constrain.
is_dcp(EqConstraint)
: Is the constraint DCP?
is_dgp(EqConstraint)
: Is the constraint DGP?
residual(EqConstraint)
: The residual of the constraint..
This class represents the elementwise absolute value.
Abs(x) ## S4 method for signature 'Abs' to_numeric(object, values) ## S4 method for signature 'Abs' allow_complex(object) ## S4 method for signature 'Abs' sign_from_args(object) ## S4 method for signature 'Abs' is_atom_convex(object) ## S4 method for signature 'Abs' is_atom_concave(object) ## S4 method for signature 'Abs' is_incr(object, idx) ## S4 method for signature 'Abs' is_decr(object, idx) ## S4 method for signature 'Abs' is_pwl(object)
Abs(x) ## S4 method for signature 'Abs' to_numeric(object, values) ## S4 method for signature 'Abs' allow_complex(object) ## S4 method for signature 'Abs' sign_from_args(object) ## S4 method for signature 'Abs' is_atom_convex(object) ## S4 method for signature 'Abs' is_atom_concave(object) ## S4 method for signature 'Abs' is_incr(object, idx) ## S4 method for signature 'Abs' is_decr(object, idx) ## S4 method for signature 'Abs' is_pwl(object)
x |
An Expression object. |
object |
An Abs object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
to_numeric(Abs)
: The elementwise absolute value of the input.
allow_complex(Abs)
: Does the atom handle complex numbers?
sign_from_args(Abs)
: The atom is positive.
is_atom_convex(Abs)
: The atom is convex.
is_atom_concave(Abs)
: The atom is not concave.
is_incr(Abs)
: A logical value indicating whether the atom is weakly increasing.
is_decr(Abs)
: A logical value indicating whether the atom is weakly decreasing.
is_pwl(Abs)
: Is x
piecewise linear?
x
An Expression object.
The elementwise absolute value.
## S4 method for signature 'Expression' abs(x)
## S4 method for signature 'Expression' abs(x)
x |
An Expression. |
An Expression representing the absolute value of the input.
A <- Variable(2,2) prob <- Problem(Minimize(sum(abs(A))), list(A <= -2)) result <- solve(prob) result$value result$getValue(A)
A <- Variable(2,2) prob <- Problem(Minimize(sum(abs(A))), list(A <= -2)) result <- solve(prob) result$value result$getValue(A)
Determine whether the reduction accepts a problem.
accepts(object, problem)
accepts(object, problem)
object |
A Reduction object. |
problem |
A Problem to check. |
A logical value indicating whether the reduction can be applied.
This virtual class represents an affine atomic expression.
## S4 method for signature 'AffAtom' allow_complex(object) ## S4 method for signature 'AffAtom' sign_from_args(object) ## S4 method for signature 'AffAtom' is_imag(object) ## S4 method for signature 'AffAtom' is_complex(object) ## S4 method for signature 'AffAtom' is_atom_convex(object) ## S4 method for signature 'AffAtom' is_atom_concave(object) ## S4 method for signature 'AffAtom' is_incr(object, idx) ## S4 method for signature 'AffAtom' is_decr(object, idx) ## S4 method for signature 'AffAtom' is_quadratic(object) ## S4 method for signature 'AffAtom' is_qpwa(object) ## S4 method for signature 'AffAtom' is_pwl(object) ## S4 method for signature 'AffAtom' is_psd(object) ## S4 method for signature 'AffAtom' is_nsd(object) ## S4 method for signature 'AffAtom' .grad(object, values)
## S4 method for signature 'AffAtom' allow_complex(object) ## S4 method for signature 'AffAtom' sign_from_args(object) ## S4 method for signature 'AffAtom' is_imag(object) ## S4 method for signature 'AffAtom' is_complex(object) ## S4 method for signature 'AffAtom' is_atom_convex(object) ## S4 method for signature 'AffAtom' is_atom_concave(object) ## S4 method for signature 'AffAtom' is_incr(object, idx) ## S4 method for signature 'AffAtom' is_decr(object, idx) ## S4 method for signature 'AffAtom' is_quadratic(object) ## S4 method for signature 'AffAtom' is_qpwa(object) ## S4 method for signature 'AffAtom' is_pwl(object) ## S4 method for signature 'AffAtom' is_psd(object) ## S4 method for signature 'AffAtom' is_nsd(object) ## S4 method for signature 'AffAtom' .grad(object, values)
object |
An AffAtom object. |
idx |
An index into the atom. |
values |
A list of numeric values for the arguments |
allow_complex(AffAtom)
: Does the atom handle complex numbers?
sign_from_args(AffAtom)
: The sign of the atom.
is_imag(AffAtom)
: Is the atom imaginary?
is_complex(AffAtom)
: Is the atom complex valued?
is_atom_convex(AffAtom)
: The atom is convex.
is_atom_concave(AffAtom)
: The atom is concave.
is_incr(AffAtom)
: The atom is weakly increasing in every argument.
is_decr(AffAtom)
: The atom is not weakly decreasing in any argument.
is_quadratic(AffAtom)
: Is every argument quadratic?
is_qpwa(AffAtom)
: Is every argument quadratic of piecewise affine?
is_pwl(AffAtom)
: Is every argument piecewise linear?
is_psd(AffAtom)
: Is the atom a positive semidefinite matrix?
is_nsd(AffAtom)
: Is the atom a negative semidefinite matrix?
.grad(AffAtom)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
Are the arguments affine?
are_args_affine(constraints)
are_args_affine(constraints)
constraints |
A Constraint object. |
All the affine arguments in given constraints.
This virtual class represents atomic expressions in CVXR.
## S4 method for signature 'Atom' name(x) ## S4 method for signature 'Atom' validate_args(object) ## S4 method for signature 'Atom' dim(x) ## S4 method for signature 'Atom' nrow(x) ## S4 method for signature 'Atom' ncol(x) ## S4 method for signature 'Atom' allow_complex(object) ## S4 method for signature 'Atom' is_nonneg(object) ## S4 method for signature 'Atom' is_nonpos(object) ## S4 method for signature 'Atom' is_imag(object) ## S4 method for signature 'Atom' is_complex(object) ## S4 method for signature 'Atom' is_convex(object) ## S4 method for signature 'Atom' is_concave(object) ## S4 method for signature 'Atom' is_log_log_convex(object) ## S4 method for signature 'Atom' is_log_log_concave(object) ## S4 method for signature 'Atom' canonicalize(object) ## S4 method for signature 'Atom' graph_implementation(object, arg_objs, dim, data = NA_real_) ## S4 method for signature 'Atom' value_impl(object) ## S4 method for signature 'Atom' value(object) ## S4 method for signature 'Atom' grad(object) ## S4 method for signature 'Atom' domain(object) ## S4 method for signature 'Atom' atoms(object)
## S4 method for signature 'Atom' name(x) ## S4 method for signature 'Atom' validate_args(object) ## S4 method for signature 'Atom' dim(x) ## S4 method for signature 'Atom' nrow(x) ## S4 method for signature 'Atom' ncol(x) ## S4 method for signature 'Atom' allow_complex(object) ## S4 method for signature 'Atom' is_nonneg(object) ## S4 method for signature 'Atom' is_nonpos(object) ## S4 method for signature 'Atom' is_imag(object) ## S4 method for signature 'Atom' is_complex(object) ## S4 method for signature 'Atom' is_convex(object) ## S4 method for signature 'Atom' is_concave(object) ## S4 method for signature 'Atom' is_log_log_convex(object) ## S4 method for signature 'Atom' is_log_log_concave(object) ## S4 method for signature 'Atom' canonicalize(object) ## S4 method for signature 'Atom' graph_implementation(object, arg_objs, dim, data = NA_real_) ## S4 method for signature 'Atom' value_impl(object) ## S4 method for signature 'Atom' value(object) ## S4 method for signature 'Atom' grad(object) ## S4 method for signature 'Atom' domain(object) ## S4 method for signature 'Atom' atoms(object)
x , object
|
An Atom object. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector with two elements representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
name(Atom)
: Returns the string representtation of the function call
validate_args(Atom)
: Raises an error if the arguments are invalid.
dim(Atom)
: The c(row, col)
dimensions of the atom.
nrow(Atom)
: The number of rows in the atom.
ncol(Atom)
: The number of columns in the atom.
allow_complex(Atom)
: Does the atom handle complex numbers?
is_nonneg(Atom)
: A logical value indicating whether the atom is nonnegative.
is_nonpos(Atom)
: A logical value indicating whether the atom is nonpositive.
is_imag(Atom)
: A logical value indicating whether the atom is imaginary.
is_complex(Atom)
: A logical value indicating whether the atom is complex valued.
is_convex(Atom)
: A logical value indicating whether the atom is convex.
is_concave(Atom)
: A logical value indicating whether the atom is concave.
is_log_log_convex(Atom)
: A logical value indicating whether the atom is log-log convex.
is_log_log_concave(Atom)
: A logical value indicating whether the atom is log-log concave.
canonicalize(Atom)
: Represent the atom as an affine objective and conic constraints.
graph_implementation(Atom)
: The graph implementation of the atom.
value_impl(Atom)
: Returns the value of each of the componets in an Atom. Returns an empty matrix if it's an empty atom
value(Atom)
: Returns the value of the atom.
grad(Atom)
: The (sub/super)-gradient of the atom with respect to each variable.
domain(Atom)
: A list of constraints describing the closure of the region where the expression is finite.
atoms(Atom)
: Returns a list of the atom types present amongst this atom's arguments
This virtual class represents atomic expressions that can be applied along an axis in CVXR.
## S4 method for signature 'AxisAtom' dim_from_args(object) ## S4 method for signature 'AxisAtom' get_data(object) ## S4 method for signature 'AxisAtom' validate_args(object) ## S4 method for signature 'AxisAtom' .axis_grad(object, values) ## S4 method for signature 'AxisAtom' .column_grad(object, value)
## S4 method for signature 'AxisAtom' dim_from_args(object) ## S4 method for signature 'AxisAtom' get_data(object) ## S4 method for signature 'AxisAtom' validate_args(object) ## S4 method for signature 'AxisAtom' .axis_grad(object, values) ## S4 method for signature 'AxisAtom' .column_grad(object, value)
object |
An Atom object. |
values |
A list of numeric values for the arguments |
value |
A numeric value |
dim_from_args(AxisAtom)
: The dimensions of the atom determined from its arguments.
get_data(AxisAtom)
: A list containing axis
and keepdims
.
validate_args(AxisAtom)
: Check that the new dimensions have the same number of entries as the old.
.axis_grad(AxisAtom)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(AxisAtom)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
expr
A numeric element, data.frame, matrix, vector, or Expression.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
This base class represents expressions involving binary operators.
## S4 method for signature 'BinaryOperator' name(x) ## S4 method for signature 'BinaryOperator' to_numeric(object, values) ## S4 method for signature 'BinaryOperator' sign_from_args(object) ## S4 method for signature 'BinaryOperator' is_imag(object) ## S4 method for signature 'BinaryOperator' is_complex(object)
## S4 method for signature 'BinaryOperator' name(x) ## S4 method for signature 'BinaryOperator' to_numeric(object, values) ## S4 method for signature 'BinaryOperator' sign_from_args(object) ## S4 method for signature 'BinaryOperator' is_imag(object) ## S4 method for signature 'BinaryOperator' is_complex(object)
x , object
|
A BinaryOperator object. |
values |
A list of arguments to the atom. |
name(BinaryOperator)
: Returns the name of the BinaryOperator object.
to_numeric(BinaryOperator)
: Apply the binary operator to the values.
sign_from_args(BinaryOperator)
: Default to rule for multiplication.
is_imag(BinaryOperator)
: Is the expression imaginary?
is_complex(BinaryOperator)
: Is the expression complex valued?
lh_exp
The Expression on the left-hand side of the operator.
rh_exp
The Expression on the right-hand side of the operator.
op_name
A character
string indicating the binary operation.
Constructs a block matrix from a list of lists. Each internal list is stacked horizontally, and the internal lists are stacked vertically.
bmat(block_lists)
bmat(block_lists)
block_lists |
A list of lists containing Expression objects, matrices, or vectors, which represent the blocks of the block matrix. |
An Expression representing the block matrix.
x <- Variable() expr <- bmat(list(list(matrix(1, nrow = 3, ncol = 1), matrix(2, nrow = 3, ncol = 2)), list(matrix(3, nrow = 1, ncol = 2), x) )) prob <- Problem(Minimize(sum_entries(expr)), list(x >= 0)) result <- solve(prob) result$value
x <- Variable() expr <- bmat(list(list(matrix(1, nrow = 3, ncol = 1), matrix(2, nrow = 3, ncol = 2)), list(matrix(3, nrow = 1, ncol = 2), x) )) prob <- Problem(Minimize(sum_entries(expr)), list(x >= 0)) result <- solve(prob) result$value
This class represents a parameter whose value is obtained by evaluating a function.
CallbackParam(callback, dim = NULL, ...) ## S4 method for signature 'CallbackParam' value(object)
CallbackParam(callback, dim = NULL, ...) ## S4 method for signature 'CallbackParam' value(object)
callback |
A callback function that generates the parameter value. |
dim |
The dimensions of the parameter. |
... |
Additional attribute arguments. See Leaf for details. |
object |
A CallbackParam object. |
callback
A callback function that generates the parameter value.
dim
The dimensions of the parameter.
x <- Variable(2) fun <- function() { value(x) } y <- CallbackParam(fun, dim(x), nonneg = TRUE) get_data(y)
x <- Variable(2) fun <- function() { value(x) } y <- CallbackParam(fun, dim(x), nonneg = TRUE) get_data(y)
This virtual class represents a canonical expression.
## S4 method for signature 'Canonical' expr(object) ## S4 method for signature 'Canonical' id(object) ## S4 method for signature 'Canonical' canonical_form(object) ## S4 method for signature 'Canonical' variables(object) ## S4 method for signature 'Canonical' parameters(object) ## S4 method for signature 'Canonical' constants(object) ## S4 method for signature 'Canonical' atoms(object) ## S4 method for signature 'Canonical' get_data(object)
## S4 method for signature 'Canonical' expr(object) ## S4 method for signature 'Canonical' id(object) ## S4 method for signature 'Canonical' canonical_form(object) ## S4 method for signature 'Canonical' variables(object) ## S4 method for signature 'Canonical' parameters(object) ## S4 method for signature 'Canonical' constants(object) ## S4 method for signature 'Canonical' atoms(object) ## S4 method for signature 'Canonical' get_data(object)
object |
A Canonical object. |
expr(Canonical)
: The expression associated with the input.
id(Canonical)
: The unique ID of the canonical expression.
canonical_form(Canonical)
: The graph implementation of the input.
variables(Canonical)
: List of Variable objects in the expression.
parameters(Canonical)
: List of Parameter objects in the expression.
constants(Canonical)
: List of Constant objects in the expression.
atoms(Canonical)
: List of Atom objects in the expression.
get_data(Canonical)
: Information needed to reconstruct the expression aside from its arguments.
This class represents a canonicalization reduction.
## S4 method for signature 'Canonicalization,Problem' perform(object, problem) ## S4 method for signature 'Canonicalization,Solution,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'Canonicalization' canonicalize_tree(object, expr) ## S4 method for signature 'Canonicalization' canonicalize_expr(object, expr, args)
## S4 method for signature 'Canonicalization,Problem' perform(object, problem) ## S4 method for signature 'Canonicalization,Solution,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'Canonicalization' canonicalize_tree(object, expr) ## S4 method for signature 'Canonicalization' canonicalize_expr(object, expr, args)
object |
A Canonicalization object. |
problem |
A Problem object. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
An InverseData object that contains the data encoding the original problem. |
expr |
An Expression object. |
args |
List of arguments to canonicalize the expression. |
perform(object = Canonicalization, problem = Problem)
: Recursively canonicalize the objective and every constraint.
invert(
object = Canonicalization,
solution = Solution,
inverse_data = InverseData
)
: Performs the reduction on a problem and returns an equivalent problem.
canonicalize_tree(Canonicalization)
: Recursively canonicalize an Expression.
canonicalize_expr(Canonicalization)
: Canonicalize an expression, w.r.t. canonicalized arguments.
Computes the graph implementation of a canonical expression.
canonicalize(object) canonical_form(object)
canonicalize(object) canonical_form(object)
object |
A Canonical object. |
A list of list(affine expression, list(constraints))
.
An interface to the CBC solver
CBC_CONIC() ## S4 method for signature 'CBC_CONIC' mip_capable(solver) ## S4 method for signature 'CBC_CONIC' status_map(solver, status) ## S4 method for signature 'CBC_CONIC' status_map_mip(solver, status) ## S4 method for signature 'CBC_CONIC' status_map_lp(solver, status) ## S4 method for signature 'CBC_CONIC' name(x) ## S4 method for signature 'CBC_CONIC' import_solver(solver) ## S4 method for signature 'CBC_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'CBC_CONIC,Problem' perform(object, problem) ## S4 method for signature 'CBC_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CBC_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
CBC_CONIC() ## S4 method for signature 'CBC_CONIC' mip_capable(solver) ## S4 method for signature 'CBC_CONIC' status_map(solver, status) ## S4 method for signature 'CBC_CONIC' status_map_mip(solver, status) ## S4 method for signature 'CBC_CONIC' status_map_lp(solver, status) ## S4 method for signature 'CBC_CONIC' name(x) ## S4 method for signature 'CBC_CONIC' import_solver(solver) ## S4 method for signature 'CBC_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'CBC_CONIC,Problem' perform(object, problem) ## S4 method for signature 'CBC_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CBC_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A CBC_CONIC object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(CBC_CONIC)
: Can the solver handle mixed-integer programs?
status_map(CBC_CONIC)
: Converts status returned by the CBC solver to its respective CVXPY status.
status_map_mip(CBC_CONIC)
: Converts status returned by the CBC solver to its respective CVXPY status for mixed integer problems.
status_map_lp(CBC_CONIC)
: Converts status returned by the CBC solver to its respective CVXPY status for linear problems.
name(CBC_CONIC)
: Returns the name of the solver
import_solver(CBC_CONIC)
: Imports the solver
accepts(object = CBC_CONIC, problem = Problem)
: Can CBC_CONIC solve the problem?
perform(object = CBC_CONIC, problem = Problem)
: Returns a new problem and data for inverting the new solution.
invert(object = CBC_CONIC, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(CBC_CONIC)
: Solve a problem represented by data returned from apply.
Global Monthly and Annual Temperature Anomalies (degrees C), 1850-2015 (Relative to the 1961-1990 Mean) (May 2016)
cdiac
cdiac
A data frame with 166 rows and 14 variables:
Year
Anomaly for month of January
Anomaly for month of February
Anomaly for month of March
Anomaly for month of April
Anomaly for month of May
Anomaly for month of June
Anomaly for month of July
Anomaly for month of August
Anomaly for month of September
Anomaly for month of October
Anomaly for month of November
Anomaly for month of December
Annual anomaly for the year
This class represents a reduction that replaces symbolic parameters with their constraint values.
## S4 method for signature 'Chain' as.character(x) ## S4 method for signature 'Chain,Problem' accepts(object, problem) ## S4 method for signature 'Chain,Problem' perform(object, problem) ## S4 method for signature 'Chain,SolutionORList,list' invert(object, solution, inverse_data)
## S4 method for signature 'Chain' as.character(x) ## S4 method for signature 'Chain,Problem' accepts(object, problem) ## S4 method for signature 'Chain,Problem' perform(object, problem) ## S4 method for signature 'Chain,SolutionORList,list' invert(object, solution, inverse_data)
x , object
|
A Chain object. |
problem |
A Problem object to check. |
solution |
A Solution or list. |
inverse_data |
A list that contains the data encoding the original problem. |
accepts(object = Chain, problem = Problem)
: A problem is accepted if the sequence of reductions is valid. In particular, the i-th reduction must accept the output of the i-1th
reduction, with the first reduction (self.reductions[0]) in the sequence taking as input the supplied problem.
perform(object = Chain, problem = Problem)
: Applies the chain to a problem and returns an equivalent problem.
invert(object = Chain, solution = SolutionORList, inverse_data = list)
: Performs the reduction on a problem and returns an equivalent problem.
An interface for the CLARABEL solver
CLARABEL() ## S4 method for signature 'CLARABEL' mip_capable(solver) ## S4 method for signature 'CLARABEL' status_map(solver, status) ## S4 method for signature 'CLARABEL' name(x) ## S4 method for signature 'CLARABEL' import_solver(solver) ## S4 method for signature 'CLARABEL' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'CLARABEL,Problem' perform(object, problem) ## S4 method for signature 'CLARABEL,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CLARABEL' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
CLARABEL() ## S4 method for signature 'CLARABEL' mip_capable(solver) ## S4 method for signature 'CLARABEL' status_map(solver, status) ## S4 method for signature 'CLARABEL' name(x) ## S4 method for signature 'CLARABEL' import_solver(solver) ## S4 method for signature 'CLARABEL' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'CLARABEL,Problem' perform(object, problem) ## S4 method for signature 'CLARABEL,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CLARABEL' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A CLARABEL object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
constr |
A Constraint to format. |
exp_cone_order |
A list indicating how the exponential cone arguments are ordered. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(CLARABEL)
: Can the solver handle mixed-integer programs?
status_map(CLARABEL)
: Converts status returned by CLARABEL solver to its respective CVXPY status.
name(CLARABEL)
: Returns the name of the solver
import_solver(CLARABEL)
: Imports the solver
reduction_format_constr(CLARABEL)
: Return a linear operator to multiply by PSD constraint coefficients.
perform(object = CLARABEL, problem = Problem)
: Returns a new problem and data for inverting the new solution
invert(object = CLARABEL, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(CLARABEL)
: Solve a problem represented by data returned from apply.
Utility method for formatting a ConeDims instance into a dictionary that can be supplied to Clarabel
CLARABEL.dims_to_solver_dict(cone_dims)
CLARABEL.dims_to_solver_dict(cone_dims)
cone_dims |
A ConeDims instance. |
The dimensions of the cones.
Special cases PSD constraints, as per the CLARABEL specification.
CLARABEL.extract_dual_value(result_vec, offset, constraint)
CLARABEL.extract_dual_value(result_vec, offset, constraint)
result_vec |
The vector to extract dual values from. |
offset |
The starting point of the vector to extract from. |
constraint |
A Constraint object. |
The dual values for the corresponding PSD constraints
Basic atoms that support complex arithmetic.
## S4 method for signature 'Expression' Re(z) ## S4 method for signature 'Expression' Im(z) ## S4 method for signature 'Expression' Conj(z)
## S4 method for signature 'Expression' Re(z) ## S4 method for signature 'Expression' Im(z) ## S4 method for signature 'Expression' Conj(z)
z |
An Expression object. |
An Expression object that represents the real, imaginary, or complex conjugate.
Determine if an expression is real, imaginary, or complex.
is_real(object) is_imag(object) is_complex(object)
is_real(object) is_imag(object) is_complex(object)
object |
An Expression object. |
A logical value.
This reduction takes in a complex problem and returns an equivalent real problem.
## S4 method for signature 'Complex2Real,Problem' accepts(object, problem) ## S4 method for signature 'Complex2Real,Problem' perform(object, problem) ## S4 method for signature 'Complex2Real,Solution,InverseData' invert(object, solution, inverse_data)
## S4 method for signature 'Complex2Real,Problem' accepts(object, problem) ## S4 method for signature 'Complex2Real,Problem' perform(object, problem) ## S4 method for signature 'Complex2Real,Solution,InverseData' invert(object, solution, inverse_data)
object |
A Complex2Real object. |
problem |
A Problem object. |
solution |
A Solution object to invert. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
accepts(object = Complex2Real, problem = Problem)
: Checks whether or not the problem involves any complex numbers.
perform(object = Complex2Real, problem = Problem)
: Converts a Complex problem into a Real one.
invert(object = Complex2Real, solution = Solution, inverse_data = InverseData)
: Returns a solution to the original problem given the inverse data.
Complex canonicalizer for the absolute value atom
Complex2Real.abs_canon(expr, real_args, imag_args, real2imag)
Complex2Real.abs_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of the absolute value atom of a complex expression, where the returned variables are its real and imaginary components parsed out.
Helper function to sum arguments.
Complex2Real.add(lh_arg, rh_arg, neg = FALSE)
Complex2Real.add(lh_arg, rh_arg, neg = FALSE)
lh_arg |
The arguments for the left-hand side |
rh_arg |
The arguments for the right-hand side |
neg |
Whether to negate the right hand side |
Upcast 0D and 1D to 2D.
Complex2Real.at_least_2D(expr)
Complex2Real.at_least_2D(expr)
expr |
An Expression object |
An expression of dimension at least 2.
Complex canonicalizer for the binary atom
Complex2Real.binary_canon(expr, real_args, imag_args, real2imag)
Complex2Real.binary_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a binary atom, where the returned variables are the real component and the imaginary component.
Canonicalizes a Complex Expression
Complex2Real.canonicalize_expr(expr, real_args, imag_args, real2imag, leaf_map)
Complex2Real.canonicalize_expr(expr, real_args, imag_args, real2imag, leaf_map)
expr |
An Expression object. |
real_args |
A list of Constraint objects for the real part of the expression. |
imag_args |
A list of Constraint objects for the imaginary part of the expression. |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
leaf_map |
A map that consists of a tree representation of the overall expression |
A list of the parsed out real and imaginary components of the expression at hand.
Recursively Canonicalizes a Complex Expression.
Complex2Real.canonicalize_tree(expr, real2imag, leaf_map)
Complex2Real.canonicalize_tree(expr, real2imag, leaf_map)
expr |
An Expression object. |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
leaf_map |
A map that consists of a tree representation of the expression. |
A list of the parsed out real and imaginary components of the expression that was constructed by performing the canonicalization of each leaf in the tree.
Complex canonicalizer for the conjugate atom
Complex2Real.conj_canon(expr, real_args, imag_args, real2imag)
Complex2Real.conj_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a conjugate atom, where the returned variables are the real components and negative of the imaginary component.
Complex canonicalizer for the constant atom
Complex2Real.constant_canon(expr, real_args, imag_args, real2imag)
Complex2Real.constant_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a constant atom, where the returned variables are the real component and the imaginary component in the Constant atom.
Complex canonicalizer for the hermitian atom
Complex2Real.hermitian_canon(expr, real_args, imag_args, real2imag)
Complex2Real.hermitian_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a hermitian matrix atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the imaginary atom
Complex2Real.imag_canon(expr, real_args, imag_args, real2imag)
Complex2Real.imag_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of an imaginary atom, where the returned variables are the imaginary component and NULL for the real component.
Helper function to combine arguments.
Complex2Real.join(expr, lh_arg, rh_arg)
Complex2Real.join(expr, lh_arg, rh_arg)
expr |
An Expression object |
lh_arg |
The arguments for the left-hand side |
rh_arg |
The arguments for the right-hand side |
A joined expression of both left and right expressions
Complex canonicalizer for the largest sum atom
Complex2Real.lambda_sum_largest_canon(expr, real_args, imag_args, real2imag)
Complex2Real.lambda_sum_largest_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of the largest sum atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the matrix fraction atom
Complex2Real.matrix_frac_canon(expr, real_args, imag_args, real2imag)
Complex2Real.matrix_frac_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a matrix atom, where the returned variables are converted to real variables.
Complex canonicalizer for the non-positive atom
Complex2Real.nonpos_canon(expr, real_args, imag_args, real2imag)
Complex2Real.nonpos_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a non positive atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the nuclear norm atom
Complex2Real.norm_nuc_canon(expr, real_args, imag_args, real2imag)
Complex2Real.norm_nuc_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a nuclear norm matrix atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the parameter matrix atom
Complex2Real.param_canon(expr, real_args, imag_args, real2imag)
Complex2Real.param_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a parameter matrix atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the p norm atom
Complex2Real.pnorm_canon(expr, real_args, imag_args, real2imag)
Complex2Real.pnorm_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a pnorm atom, where the returned variables are the real component and the NULL imaginary component.
Complex canonicalizer for the positive semidefinite atom
Complex2Real.psd_canon(expr, real_args, imag_args, real2imag)
Complex2Real.psd_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a positive semidefinite atom, where the returned variables are the real component and the NULL imaginary component.
Complex canonicalizer for the quadratic atom
Complex2Real.quad_canon(expr, real_args, imag_args, real2imag)
Complex2Real.quad_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a quadratic atom, where the returned variables are the real component and the imaginary component as NULL.
Complex canonicalizer for the quadratic over linear term atom
Complex2Real.quad_over_lin_canon(expr, real_args, imag_args, real2imag)
Complex2Real.quad_over_lin_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a quadratic over a linear term atom, where the returned variables are the real component and the imaginary component.
Complex canonicalizer for the real atom
Complex2Real.real_canon(expr, real_args, imag_args, real2imag)
Complex2Real.real_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a real atom, where the returned variables are the real component and NULL for the imaginary component.
Complex canonicalizer for the separable atom
Complex2Real.separable_canon(expr, real_args, imag_args, real2imag)
Complex2Real.separable_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a separable atom, where the returned variables are its real and imaginary components parsed out.
Complex canonicalizer for the SOC atom
Complex2Real.soc_canon(expr, real_args, imag_args, real2imag)
Complex2Real.soc_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a SOC atom, where the returned variables are the real component and the NULL imaginary component.
Complex canonicalizer for the variable atom
Complex2Real.variable_canon(expr, real_args, imag_args, real2imag)
Complex2Real.variable_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a variable atom, where the returned variables are the real component and the NULL imaginary component.
Complex canonicalizer for the zero atom
Complex2Real.zero_canon(expr, real_args, imag_args, real2imag)
Complex2Real.zero_canon(expr, real_args, imag_args, real2imag)
expr |
An Expression object |
real_args |
A list of Constraint objects for the real part of the expression |
imag_args |
A list of Constraint objects for the imaginary part of the expression |
real2imag |
A list mapping the ID of the real part of a complex expression to the ID of its imaginary part. |
A canonicalization of a zero atom, where the returned variables are the real component and the imaginary component.
The number of elementwise cones or a list of the sizes of the elementwise cones.
num_cones(object) cone_sizes(object)
num_cones(object) cone_sizes(object)
object |
An SOCAxis object. |
The number of cones, or the size of a cone.
Constraints must be formatted as dictionary that maps from constraint type to a list of constraints of that type.
Attributes ———- zero : int The dimension of the zero cone. nonpos : int The dimension of the non-positive cone. exp : int The dimension of the exponential cone. soc : list of int A list of the second-order cone dimensions. psd : list of int A list of the positive semidefinite cone dimensions, where the dimension of the PSD cone of k by k matrices is k.
Linear cone problems are assumed to have a linear objective and cone constraints, which may have zero or more arguments, all of which must be affine.
## S4 method for signature 'ConeMatrixStuffing,Problem' accepts(object, problem) ## S4 method for signature 'ConeMatrixStuffing,Problem,CoeffExtractor' stuffed_objective(object, problem, extractor)
## S4 method for signature 'ConeMatrixStuffing,Problem' accepts(object, problem) ## S4 method for signature 'ConeMatrixStuffing,Problem,CoeffExtractor' stuffed_objective(object, problem, extractor)
object |
A ConeMatrixStuffing object. |
problem |
A Problem object. |
extractor |
Used to extract the affine coefficients of the objective. |
minimize c^Tx subject to cone_constr1(A_1*x + b_1, ...) ... cone_constrK(A_K*x + b_K, ...)
accepts(object = ConeMatrixStuffing, problem = Problem)
: Is the solver accepted?
stuffed_objective(
object = ConeMatrixStuffing,
problem = Problem,
extractor = CoeffExtractor
)
: Returns a list of the stuffed matrices
Conic solver class with reduction semantics.
## S4 method for signature 'ConicSolver,Problem' accepts(object, problem) ## S4 method for signature 'ConicSolver' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'ConicSolver' group_coeff_offset(object, problem, constraints, exp_cone_order) ## S4 method for signature 'ConicSolver,Solution,InverseData' invert(object, solution, inverse_data)
## S4 method for signature 'ConicSolver,Problem' accepts(object, problem) ## S4 method for signature 'ConicSolver' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'ConicSolver' group_coeff_offset(object, problem, constraints, exp_cone_order) ## S4 method for signature 'ConicSolver,Solution,InverseData' invert(object, solution, inverse_data)
object |
A ConicSolver object. |
problem |
A Problem object. |
constr |
A Constraint to format. |
exp_cone_order |
A list indicating how the exponential cone arguments are ordered. |
constraints |
A list of Constraint objects. |
solution |
A Solution object to invert. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
accepts(object = ConicSolver, problem = Problem)
: Can the problem be solved with a conic solver?
reduction_format_constr(ConicSolver)
: Return a list representing a cone program whose problem data tensors
will yield the coefficient "A" and offset "b" for the respective constraints:
Linear Equations: ,
Linear inequalities:
,
Second order cone:
,
Exponential cone:
,
Semidefinite cone:
.
group_coeff_offset(ConicSolver)
: Combine the constraints into a single matrix, offset.
invert(object = ConicSolver, solution = Solution, inverse_data = InverseData)
: Returns the solution to the original problem given the inverse_data.
.Return the coefficient and offset in .
ConicSolver.get_coeff_offset(expr)
ConicSolver.get_coeff_offset(expr)
expr |
An Expression object. |
The coefficient and offset in .
Returns a sparse matrix that spaces out an expression.
ConicSolver.get_spacing_matrix(dim, spacing, offset)
ConicSolver.get_spacing_matrix(dim, spacing, offset)
dim |
A vector outlining the dimensions of the matrix. |
spacing |
An int of the number of rows between the start of each non-zero block. |
offset |
An int of the number of zeros at the beginning of the matrix. |
A sparse matrix that spaces out an expression
This class represents the complex conjugate of an expression.
Conjugate(expr) ## S4 method for signature 'Conjugate' to_numeric(object, values) ## S4 method for signature 'Conjugate' dim_from_args(object) ## S4 method for signature 'Conjugate' is_incr(object, idx) ## S4 method for signature 'Conjugate' is_decr(object, idx) ## S4 method for signature 'Conjugate' is_symmetric(object) ## S4 method for signature 'Conjugate' is_hermitian(object)
Conjugate(expr) ## S4 method for signature 'Conjugate' to_numeric(object, values) ## S4 method for signature 'Conjugate' dim_from_args(object) ## S4 method for signature 'Conjugate' is_incr(object, idx) ## S4 method for signature 'Conjugate' is_decr(object, idx) ## S4 method for signature 'Conjugate' is_symmetric(object) ## S4 method for signature 'Conjugate' is_hermitian(object)
expr |
An Expression or R numeric data. |
object |
A Conjugate object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
to_numeric(Conjugate)
: Elementwise complex conjugate of the constant.
dim_from_args(Conjugate)
: The (row, col) dimensions of the expression.
is_incr(Conjugate)
: Is the composition weakly increasing in argument idx?
is_decr(Conjugate)
: Is the composition weakly decreasing in argument idx?
is_symmetric(Conjugate)
: Is the expression symmetric?
is_hermitian(Conjugate)
: Is the expression hermitian?
expr
An Expression or R numeric data.
This class represents a constant.
Coerce an R object or expression into the Constant class.
Constant(value) ## S4 method for signature 'Constant' show(object) ## S4 method for signature 'Constant' name(x) ## S4 method for signature 'Constant' constants(object) ## S4 method for signature 'Constant' value(object) ## S4 method for signature 'Constant' is_pos(object) ## S4 method for signature 'Constant' grad(object) ## S4 method for signature 'Constant' dim(x) ## S4 method for signature 'Constant' canonicalize(object) ## S4 method for signature 'Constant' is_nonneg(object) ## S4 method for signature 'Constant' is_nonpos(object) ## S4 method for signature 'Constant' is_imag(object) ## S4 method for signature 'Constant' is_complex(object) ## S4 method for signature 'Constant' is_symmetric(object) ## S4 method for signature 'Constant' is_hermitian(object) ## S4 method for signature 'Constant' is_psd(object) ## S4 method for signature 'Constant' is_nsd(object) as.Constant(expr)
Constant(value) ## S4 method for signature 'Constant' show(object) ## S4 method for signature 'Constant' name(x) ## S4 method for signature 'Constant' constants(object) ## S4 method for signature 'Constant' value(object) ## S4 method for signature 'Constant' is_pos(object) ## S4 method for signature 'Constant' grad(object) ## S4 method for signature 'Constant' dim(x) ## S4 method for signature 'Constant' canonicalize(object) ## S4 method for signature 'Constant' is_nonneg(object) ## S4 method for signature 'Constant' is_nonpos(object) ## S4 method for signature 'Constant' is_imag(object) ## S4 method for signature 'Constant' is_complex(object) ## S4 method for signature 'Constant' is_symmetric(object) ## S4 method for signature 'Constant' is_hermitian(object) ## S4 method for signature 'Constant' is_psd(object) ## S4 method for signature 'Constant' is_nsd(object) as.Constant(expr)
value |
A numeric element, vector, matrix, or data.frame. Vectors are automatically cast into a matrix column. |
x , object
|
A Constant object. |
expr |
An Expression, numeric element, vector, matrix, or data.frame. |
A Constant representing the input as a constant.
name(Constant)
: The name of the constant.
constants(Constant)
: Returns itself as a constant.
value(Constant)
: The value of the constant.
is_pos(Constant)
: A logical value indicating whether all elements of the constant are positive.
grad(Constant)
: An empty list since the gradient of a constant is zero.
dim(Constant)
: The c(row, col)
dimensions of the constant.
canonicalize(Constant)
: The canonical form of the constant.
is_nonneg(Constant)
: A logical value indicating whether all elements of the constant are non-negative.
is_nonpos(Constant)
: A logical value indicating whether all elements of the constant are non-positive.
is_imag(Constant)
: A logical value indicating whether the constant is imaginary.
is_complex(Constant)
: A logical value indicating whether the constant is complex-valued.
is_symmetric(Constant)
: A logical value indicating whether the constant is symmetric.
is_hermitian(Constant)
: A logical value indicating whether the constant is a Hermitian matrix.
is_psd(Constant)
: A logical value indicating whether the constant is a positive semidefinite matrix.
is_nsd(Constant)
: A logical value indicating whether the constant is a negative semidefinite matrix.
value
A numeric element, vector, matrix, or data.frame. Vectors are automatically cast into a matrix column.
sparse
(Internal) A logical value indicating whether the value is a sparse matrix.
is_pos
(Internal) A logical value indicating whether all elements are non-negative.
is_neg
(Internal) A logical value indicating whether all elements are non-positive.
x <- Constant(5) y <- Constant(diag(3)) get_data(y) value(y) is_nonneg(y) size(y) as.Constant(y)
x <- Constant(5) y <- Constant(diag(3)) get_data(y) value(y) is_nonneg(y) size(y) as.Constant(y)
The ConstantSolver class.
## S4 method for signature 'ConstantSolver' mip_capable(solver) ## S4 method for signature 'ConstantSolver,Problem' accepts(object, problem) ## S4 method for signature 'ConstantSolver,Problem' perform(object, problem) ## S4 method for signature 'ConstantSolver,Solution,list' invert(object, solution, inverse_data) ## S4 method for signature 'ConstantSolver' name(x) ## S4 method for signature 'ConstantSolver' import_solver(solver) ## S4 method for signature 'ConstantSolver' is_installed(solver) ## S4 method for signature 'ConstantSolver' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'ConstantSolver,ANY' reduction_solve(object, problem, warm_start, verbose, solver_opts)
## S4 method for signature 'ConstantSolver' mip_capable(solver) ## S4 method for signature 'ConstantSolver,Problem' accepts(object, problem) ## S4 method for signature 'ConstantSolver,Problem' perform(object, problem) ## S4 method for signature 'ConstantSolver,Solution,list' invert(object, solution, inverse_data) ## S4 method for signature 'ConstantSolver' name(x) ## S4 method for signature 'ConstantSolver' import_solver(solver) ## S4 method for signature 'ConstantSolver' is_installed(solver) ## S4 method for signature 'ConstantSolver' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'ConstantSolver,ANY' reduction_solve(object, problem, warm_start, verbose, solver_opts)
solver , object , x
|
A ConstantSolver object. |
problem |
A Problem object. |
solution |
A Solution object to invert. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data for the solver. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(ConstantSolver)
: Can the solver handle mixed-integer programs?
accepts(object = ConstantSolver, problem = Problem)
: Is the solver capable of solving the problem?
perform(object = ConstantSolver, problem = Problem)
: Returns a list of the ConstantSolver, Problem, and an empty list.
invert(object = ConstantSolver, solution = Solution, inverse_data = list)
: Returns the solution.
name(ConstantSolver)
: Returns the name of the solver.
import_solver(ConstantSolver)
: Imports the solver.
is_installed(ConstantSolver)
: Is the solver installed?
solve_via_data(ConstantSolver)
: Solve a problem represented by data returned from apply.
reduction_solve(object = ConstantSolver, problem = ANY)
: Solve the problem and return a Solution object.
Checks whether the constraint violation is less than a tolerance.
constr_value(object, tolerance = 1e-08)
constr_value(object, tolerance = 1e-08)
object |
A Constraint object. |
tolerance |
A numeric scalar representing the absolute tolerance to impose on the violation. |
A logical value indicating whether the violation is less than the tolerance
. Raises an error if the residual is NA
.
This virtual class represents a mathematical constraint.
## S4 method for signature 'Constraint' as.character(x) ## S4 method for signature 'Constraint' dim(x) ## S4 method for signature 'Constraint' size(object) ## S4 method for signature 'Constraint' is_real(object) ## S4 method for signature 'Constraint' is_imag(object) ## S4 method for signature 'Constraint' is_complex(object) ## S4 method for signature 'Constraint' is_dcp(object) ## S4 method for signature 'Constraint' is_dgp(object) ## S4 method for signature 'Constraint' residual(object) ## S4 method for signature 'Constraint' violation(object) ## S4 method for signature 'Constraint' constr_value(object, tolerance = 1e-08) ## S4 method for signature 'Constraint' get_data(object) ## S4 method for signature 'Constraint' dual_value(object) ## S4 replacement method for signature 'Constraint' dual_value(object) <- value ## S4 method for signature 'ZeroConstraint' size(object)
## S4 method for signature 'Constraint' as.character(x) ## S4 method for signature 'Constraint' dim(x) ## S4 method for signature 'Constraint' size(object) ## S4 method for signature 'Constraint' is_real(object) ## S4 method for signature 'Constraint' is_imag(object) ## S4 method for signature 'Constraint' is_complex(object) ## S4 method for signature 'Constraint' is_dcp(object) ## S4 method for signature 'Constraint' is_dgp(object) ## S4 method for signature 'Constraint' residual(object) ## S4 method for signature 'Constraint' violation(object) ## S4 method for signature 'Constraint' constr_value(object, tolerance = 1e-08) ## S4 method for signature 'Constraint' get_data(object) ## S4 method for signature 'Constraint' dual_value(object) ## S4 replacement method for signature 'Constraint' dual_value(object) <- value ## S4 method for signature 'ZeroConstraint' size(object)
x , object
|
A Constraint object. |
tolerance |
The tolerance for checking if the constraint is violated. |
value |
A numeric scalar, vector, or matrix. |
dim(Constraint)
: The dimensions of the constrained expression.
size(Constraint)
: The size of the constrained expression.
is_real(Constraint)
: Is the constraint real?
is_imag(Constraint)
: Is the constraint imaginary?
is_complex(Constraint)
: Is the constraint complex?
is_dcp(Constraint)
: Is the constraint DCP?
is_dgp(Constraint)
: Is the constraint DGP?
residual(Constraint)
: The residual of a constraint
violation(Constraint)
: The violation of a constraint.
constr_value(Constraint)
: The value of a constraint.
get_data(Constraint)
: Information needed to reconstruct the object aside from the args.
dual_value(Constraint)
: The dual values of a constraint.
dual_value(Constraint) <- value
: Replaces the dual values of a constraint..
size(ZeroConstraint)
: The size of the constrained expression.
Builds a chain that rewrites a problem into an intermediate representation suitable for numeric reductions.
## S4 method for signature 'Problem,list' construct_intermediate_chain(problem, candidates, gp = FALSE)
## S4 method for signature 'Problem,list' construct_intermediate_chain(problem, candidates, gp = FALSE)
problem |
The problem for which to build a chain. |
candidates |
A list of candidate solvers. |
gp |
A logical value indicating whether the problem is a geometric program. |
A Chain object that can be used to convert the problem to an intermediate form.
Build a reduction chain from a problem to an installed solver.
construct_solving_chain(problem, candidates)
construct_solving_chain(problem, candidates)
problem |
The problem for which to build a chain. |
candidates |
A list of candidate solvers. |
A SolvingChain that can be used to solve the problem.
The 1-D discrete convolution of two vectors.
conv(lh_exp, rh_exp)
conv(lh_exp, rh_exp)
lh_exp |
An Expression or vector representing the left-hand value. |
rh_exp |
An Expression or vector representing the right-hand value. |
An Expression representing the convolution of the input.
set.seed(129) x <- Variable(5) h <- matrix(stats::rnorm(2), nrow = 2, ncol = 1) prob <- Problem(Minimize(sum(conv(h, x)))) result <- solve(prob) result$value result$getValue(x)
set.seed(129) x <- Variable(5) h <- matrix(stats::rnorm(2), nrow = 2, ncol = 1) prob <- Problem(Minimize(sum(conv(h, x)))) result <- solve(prob) result$value result$getValue(x)
This class represents the 1-D discrete convolution of two vectors.
Conv(lh_exp, rh_exp) ## S4 method for signature 'Conv' to_numeric(object, values) ## S4 method for signature 'Conv' validate_args(object) ## S4 method for signature 'Conv' dim_from_args(object) ## S4 method for signature 'Conv' sign_from_args(object) ## S4 method for signature 'Conv' is_incr(object, idx) ## S4 method for signature 'Conv' is_decr(object, idx) ## S4 method for signature 'Conv' graph_implementation(object, arg_objs, dim, data = NA_real_)
Conv(lh_exp, rh_exp) ## S4 method for signature 'Conv' to_numeric(object, values) ## S4 method for signature 'Conv' validate_args(object) ## S4 method for signature 'Conv' dim_from_args(object) ## S4 method for signature 'Conv' sign_from_args(object) ## S4 method for signature 'Conv' is_incr(object, idx) ## S4 method for signature 'Conv' is_decr(object, idx) ## S4 method for signature 'Conv' graph_implementation(object, arg_objs, dim, data = NA_real_)
lh_exp |
An Expression or R numeric data representing the left-hand vector. |
rh_exp |
An Expression or R numeric data representing the right-hand vector. |
object |
A Conv object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Conv)
: The convolution of the two values.
validate_args(Conv)
: Check both arguments are vectors and the first is a constant.
dim_from_args(Conv)
: The dimensions of the atom.
sign_from_args(Conv)
: The sign of the atom.
is_incr(Conv)
: Is the left-hand expression positive?
is_decr(Conv)
: Is the left-hand expression negative?
graph_implementation(Conv)
: The graph implementation of the atom.
lh_exp
An Expression or R numeric data representing the left-hand vector.
rh_exp
An Expression or R numeric data representing the right-hand vector.
An interface for the CPLEX solver
CPLEX_CONIC() CPLEX_CONIC() ## S4 method for signature 'CPLEX_CONIC' mip_capable(solver) ## S4 method for signature 'CPLEX_CONIC' name(x) ## S4 method for signature 'CPLEX_CONIC' import_solver(solver) ## S4 method for signature 'CPLEX_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'CPLEX_CONIC' status_map(solver, status) ## S4 method for signature 'CPLEX_CONIC,Problem' perform(object, problem) ## S4 method for signature 'CPLEX_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CPLEX_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
CPLEX_CONIC() CPLEX_CONIC() ## S4 method for signature 'CPLEX_CONIC' mip_capable(solver) ## S4 method for signature 'CPLEX_CONIC' name(x) ## S4 method for signature 'CPLEX_CONIC' import_solver(solver) ## S4 method for signature 'CPLEX_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'CPLEX_CONIC' status_map(solver, status) ## S4 method for signature 'CPLEX_CONIC,Problem' perform(object, problem) ## S4 method for signature 'CPLEX_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CPLEX_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A CPLEX_CONIC object. |
problem |
A Problem object. |
status |
A status code returned by the solver. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(CPLEX_CONIC)
: Can the solver handle mixed-integer programs?
name(CPLEX_CONIC)
: Returns the name of the solver.
import_solver(CPLEX_CONIC)
: Imports the solver.
accepts(object = CPLEX_CONIC, problem = Problem)
: Can CPLEX solve the problem?
status_map(CPLEX_CONIC)
: Converts status returned by the CPLEX solver to its respective CVXPY status.
perform(object = CPLEX_CONIC, problem = Problem)
: Returns a new problem and data for inverting the new solution.
invert(object = CPLEX_CONIC, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(CPLEX_CONIC)
: Solve a problem represented by data returned from apply.
An interface for the CPLEX solver.
CPLEX_QP() ## S4 method for signature 'CPLEX_QP' mip_capable(solver) ## S4 method for signature 'CPLEX_QP' status_map(solver, status) ## S4 method for signature 'CPLEX_QP' name(x) ## S4 method for signature 'CPLEX_QP' import_solver(solver) ## S4 method for signature 'CPLEX_QP,list,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'CPLEX_QP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
CPLEX_QP() ## S4 method for signature 'CPLEX_QP' mip_capable(solver) ## S4 method for signature 'CPLEX_QP' status_map(solver, status) ## S4 method for signature 'CPLEX_QP' name(x) ## S4 method for signature 'CPLEX_QP' import_solver(solver) ## S4 method for signature 'CPLEX_QP,list,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'CPLEX_QP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
status |
A status code returned by the solver. |
x , object , solver
|
A CPLEX_QP object. |
solution |
The raw solution returned by the solver. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(CPLEX_QP)
: Can the solver handle mixed-integer programs?
status_map(CPLEX_QP)
: Converts status returned by the CPLEX solver to its respective CVXPY status.
name(CPLEX_QP)
: Returns the name of the solver.
import_solver(CPLEX_QP)
: Imports the solver.
invert(object = CPLEX_QP, solution = list, inverse_data = InverseData)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(CPLEX_QP)
: Solve a problem represented by data returned from apply.
The cumulative maximum, for
.
When calling
cummax
, matrices are automatically flattened into column-major order before the max is taken.
cummax_axis(expr, axis = 2) ## S4 method for signature 'Expression' cummax(x)
cummax_axis(expr, axis = 2) ## S4 method for signature 'Expression' cummax(x)
axis |
(Optional) The dimension across which to apply the function: |
x , expr
|
An Expression, vector, or matrix. |
val <- cbind(c(1,2), c(3,4)) value(cummax(Constant(val))) value(cummax_axis(Constant(val))) x <- Variable(2,2) prob <- Problem(Minimize(cummax(x)[4]), list(x == val)) result <- solve(prob) result$value result$getValue(cummax(x))
val <- cbind(c(1,2), c(3,4)) value(cummax(Constant(val))) value(cummax_axis(Constant(val))) x <- Variable(2,2) prob <- Problem(Minimize(cummax(x)[4]), list(x == val)) result <- solve(prob) result$value result$getValue(cummax(x))
This class represents the cumulative maximum of an expression.
CumMax(expr, axis = 2) ## S4 method for signature 'CumMax' to_numeric(object, values) ## S4 method for signature 'CumMax' .grad(object, values) ## S4 method for signature 'CumMax' .column_grad(object, value) ## S4 method for signature 'CumMax' dim_from_args(object) ## S4 method for signature 'CumMax' sign_from_args(object) ## S4 method for signature 'CumMax' get_data(object) ## S4 method for signature 'CumMax' is_atom_convex(object) ## S4 method for signature 'CumMax' is_atom_concave(object) ## S4 method for signature 'CumMax' is_incr(object, idx) ## S4 method for signature 'CumMax' is_decr(object, idx)
CumMax(expr, axis = 2) ## S4 method for signature 'CumMax' to_numeric(object, values) ## S4 method for signature 'CumMax' .grad(object, values) ## S4 method for signature 'CumMax' .column_grad(object, value) ## S4 method for signature 'CumMax' dim_from_args(object) ## S4 method for signature 'CumMax' sign_from_args(object) ## S4 method for signature 'CumMax' get_data(object) ## S4 method for signature 'CumMax' is_atom_convex(object) ## S4 method for signature 'CumMax' is_atom_concave(object) ## S4 method for signature 'CumMax' is_incr(object, idx) ## S4 method for signature 'CumMax' is_decr(object, idx)
expr |
An Expression. |
axis |
A numeric vector indicating the axes along which to apply the function. For a 2D matrix, |
object |
A CumMax object. |
values |
A list of numeric values for the arguments |
value |
A numeric value. |
idx |
An index into the atom. |
to_numeric(CumMax)
: The cumulative maximum along the axis.
.grad(CumMax)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(CumMax)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
dim_from_args(CumMax)
: The dimensions of the atom determined from its arguments.
sign_from_args(CumMax)
: The (is positive, is negative) sign of the atom.
get_data(CumMax)
: Returns the axis along which the cumulative max is taken.
is_atom_convex(CumMax)
: Is the atom convex?
is_atom_concave(CumMax)
: Is the atom concave?
is_incr(CumMax)
: Is the atom weakly increasing in the index?
is_decr(CumMax)
: Is the atom weakly decreasing in the index?
expr
An Expression.
axis
A numeric vector indicating the axes along which to apply the function. For a 2D matrix, 1
indicates rows, 2
indicates columns, and c(1,2)
indicates rows and columns.
The cumulative sum, for
.
When calling
cumsum
, matrices are automatically flattened into column-major order before the sum is taken.
cumsum_axis(expr, axis = 2) ## S4 method for signature 'Expression' cumsum(x)
cumsum_axis(expr, axis = 2) ## S4 method for signature 'Expression' cumsum(x)
axis |
(Optional) The dimension across which to apply the function: |
x , expr
|
An Expression, vector, or matrix. |
val <- cbind(c(1,2), c(3,4)) value(cumsum(Constant(val))) value(cumsum_axis(Constant(val))) x <- Variable(2,2) prob <- Problem(Minimize(cumsum(x)[4]), list(x == val)) result <- solve(prob) result$value result$getValue(cumsum(x))
val <- cbind(c(1,2), c(3,4)) value(cumsum(Constant(val))) value(cumsum_axis(Constant(val))) x <- Variable(2,2) prob <- Problem(Minimize(cumsum(x)[4]), list(x == val)) result <- solve(prob) result$value result$getValue(cumsum(x))
This class represents the cumulative sum.
CumSum(expr, axis = 2) ## S4 method for signature 'CumSum' to_numeric(object, values) ## S4 method for signature 'CumSum' dim_from_args(object) ## S4 method for signature 'CumSum' get_data(object) ## S4 method for signature 'CumSum' .grad(object, values) ## S4 method for signature 'CumSum' graph_implementation(object, arg_objs, dim, data = NA_real_)
CumSum(expr, axis = 2) ## S4 method for signature 'CumSum' to_numeric(object, values) ## S4 method for signature 'CumSum' dim_from_args(object) ## S4 method for signature 'CumSum' get_data(object) ## S4 method for signature 'CumSum' .grad(object, values) ## S4 method for signature 'CumSum' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression to be summed. |
axis |
(Optional) The dimension across which to apply the function: |
object |
A CumSum object. |
values |
A list of numeric values for the arguments |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(CumSum)
: The cumulative sum of the values along the specified axis.
dim_from_args(CumSum)
: The dimensions of the atom.
get_data(CumSum)
: Returns the axis along which the cumulative sum is taken.
.grad(CumSum)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
graph_implementation(CumSum)
: The graph implementation of the atom.
expr
An Expression to be summed.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, and 2
indicates columns. The default is 2
.
The curvature of an expression.
The curvature of an expression.
curvature(object) ## S4 method for signature 'Expression' curvature(object)
curvature(object) ## S4 method for signature 'Expression' curvature(object)
object |
An Expression object. |
A string indicating the curvature of the expression, either "CONSTANT", "AFFINE", "CONVEX, "CONCAVE", or "UNKNOWN".
A string indicating the curvature of the expression, either "CONSTANT", "AFFINE", "CONVEX", "CONCAVE", or "UNKNOWN".
x <- Variable() c <- Constant(5) curvature(c) curvature(x) curvature(x^2) curvature(sqrt(x)) curvature(log(x^3) + sqrt(x))
x <- Variable() c <- Constant(5) curvature(c) curvature(x) curvature(x^2) curvature(sqrt(x)) curvature(log(x^3) + sqrt(x))
Determine if an atom is convex, concave, or affine.
is_atom_convex(object) is_atom_concave(object) is_atom_affine(object) ## S4 method for signature 'Atom' is_atom_convex(object) ## S4 method for signature 'Atom' is_atom_concave(object) ## S4 method for signature 'Atom' is_atom_affine(object) ## S4 method for signature 'Atom' is_atom_log_log_convex(object) ## S4 method for signature 'Atom' is_atom_log_log_concave(object) ## S4 method for signature 'Atom' is_atom_log_log_affine(object)
is_atom_convex(object) is_atom_concave(object) is_atom_affine(object) ## S4 method for signature 'Atom' is_atom_convex(object) ## S4 method for signature 'Atom' is_atom_concave(object) ## S4 method for signature 'Atom' is_atom_affine(object) ## S4 method for signature 'Atom' is_atom_log_log_convex(object) ## S4 method for signature 'Atom' is_atom_log_log_concave(object) ## S4 method for signature 'Atom' is_atom_log_log_affine(object)
object |
A Atom object. |
A logical value.
x <- Variable() is_atom_convex(x^2) is_atom_convex(sqrt(x)) is_atom_convex(log(x)) is_atom_concave(-abs(x)) is_atom_concave(x^2) is_atom_concave(sqrt(x)) is_atom_affine(2*x) is_atom_affine(x^2)
x <- Variable() is_atom_convex(x^2) is_atom_convex(sqrt(x)) is_atom_convex(log(x)) is_atom_concave(-abs(x)) is_atom_concave(x^2) is_atom_concave(sqrt(x)) is_atom_affine(2*x) is_atom_affine(x^2)
Determine whether a composition is non-decreasing or non-increasing in an index.
is_incr(object, idx) is_decr(object, idx) ## S4 method for signature 'Atom' is_incr(object, idx) ## S4 method for signature 'Atom' is_decr(object, idx)
is_incr(object, idx) is_decr(object, idx) ## S4 method for signature 'Atom' is_incr(object, idx) ## S4 method for signature 'Atom' is_decr(object, idx)
object |
A Atom object. |
idx |
An index into the atom. |
A logical value.
x <- Variable() is_incr(log(x), 1) is_incr(x^2, 1) is_decr(min(x), 1) is_decr(abs(x), 1)
x <- Variable() is_incr(log(x), 1) is_incr(x^2, 1) is_decr(min(x), 1) is_decr(abs(x), 1)
Determine if an expression is constant, affine, convex, concave, quadratic, piecewise linear (pwl), or quadratic/piecewise affine (qpwa).
is_constant(object) is_affine(object) is_convex(object) is_concave(object) is_quadratic(object) is_pwl(object) is_qpwa(object)
is_constant(object) is_affine(object) is_convex(object) is_concave(object) is_quadratic(object) is_pwl(object) is_qpwa(object)
object |
An Expression object. |
A logical value.
x <- Variable() c <- Constant(5) is_constant(c) is_constant(x) is_affine(c) is_affine(x) is_affine(x^2) is_convex(c) is_convex(x) is_convex(x^2) is_convex(sqrt(x)) is_concave(c) is_concave(x) is_concave(x^2) is_concave(sqrt(x)) is_quadratic(x^2) is_quadratic(sqrt(x)) is_pwl(c) is_pwl(x) is_pwl(x^2)
x <- Variable() c <- Constant(5) is_constant(c) is_constant(x) is_affine(c) is_affine(x) is_affine(x^2) is_convex(c) is_convex(x) is_convex(x^2) is_convex(sqrt(x)) is_concave(c) is_concave(x) is_concave(x^2) is_concave(sqrt(x)) is_quadratic(x^2) is_quadratic(sqrt(x)) is_pwl(c) is_pwl(x) is_pwl(x^2)
This class represents a reduction that expands convex variable attributes into constraints.
## S4 method for signature 'CvxAttr2Constr,Problem' perform(object, problem) ## S4 method for signature 'CvxAttr2Constr,Solution,list' invert(object, solution, inverse_data)
## S4 method for signature 'CvxAttr2Constr,Problem' perform(object, problem) ## S4 method for signature 'CvxAttr2Constr,Solution,list' invert(object, solution, inverse_data)
object |
A CvxAttr2Constr object. |
problem |
A Problem object. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
The inverse data returned by an invocation to apply. |
perform(object = CvxAttr2Constr, problem = Problem)
: Expand convex variable attributes to constraints.
invert(object = CvxAttr2Constr, solution = Solution, inverse_data = list)
: Performs the reduction on a problem and returns an equivalent problem.
An interface for the CVXOPT solver.
## S4 method for signature 'CVXOPT' mip_capable(solver) ## S4 method for signature 'CVXOPT' status_map(solver, status) ## S4 method for signature 'CVXOPT' name(x) ## S4 method for signature 'CVXOPT' import_solver(solver) ## S4 method for signature 'CVXOPT,Problem' accepts(object, problem) ## S4 method for signature 'CVXOPT,Problem' perform(object, problem) ## S4 method for signature 'CVXOPT,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CVXOPT' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
## S4 method for signature 'CVXOPT' mip_capable(solver) ## S4 method for signature 'CVXOPT' status_map(solver, status) ## S4 method for signature 'CVXOPT' name(x) ## S4 method for signature 'CVXOPT' import_solver(solver) ## S4 method for signature 'CVXOPT,Problem' accepts(object, problem) ## S4 method for signature 'CVXOPT,Problem' perform(object, problem) ## S4 method for signature 'CVXOPT,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'CVXOPT' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A CVXOPT object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(CVXOPT)
: Can the solver handle mixed-integer programs?
status_map(CVXOPT)
: Converts status returned by the CVXOPT solver to its respective CVXPY status.
name(CVXOPT)
: Returns the name of the solver.
import_solver(CVXOPT)
: Imports the solver.
accepts(object = CVXOPT, problem = Problem)
: Can CVXOPT solve the problem?
perform(object = CVXOPT, problem = Problem)
: Returns a new problem and data for inverting the new solution.
invert(object = CVXOPT, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(CVXOPT)
: Solve a problem represented by data returned from apply.
A wrapper on the different norm atoms. This is different from the standard "norm" method in the R base package.
If p = 2
, axis = NA
, and x
is a matrix, this returns the maximium singular value.
cvxr_norm(x, p = 2, axis = NA_real_, keepdims = FALSE)
cvxr_norm(x, p = 2, axis = NA_real_, keepdims = FALSE)
x |
An Expression or numeric constant representing a vector or matrix. |
p |
The type of norm. May be a number (p-norm), "inf" (infinity-norm), "nuc" (nuclear norm), or "fro" (Frobenius norm). The default is |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
An Expression representing the norm.
This reduction takes as input (minimization) DCP problems and converts them into problems with affine objectives and conic constraints whose arguments are affine.
## S4 method for signature 'Dcp2Cone,Problem' accepts(object, problem) ## S4 method for signature 'Dcp2Cone,Problem' perform(object, problem)
## S4 method for signature 'Dcp2Cone,Problem' accepts(object, problem) ## S4 method for signature 'Dcp2Cone,Problem' perform(object, problem)
object |
A Dcp2Cone object. |
problem |
A Problem object. |
accepts(object = Dcp2Cone, problem = Problem)
: A problem is accepted if it is a minimization and is DCP.
perform(object = Dcp2Cone, problem = Problem)
: Converts a DCP problem to a conic form.
Dcp2Cone canonicalizer for the entropy atom
Dcp2Cone.entr_canon(expr, args)
Dcp2Cone.entr_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from an entropy atom where the objective function is just the variable t with an ExpCone constraint.
Dcp2Cone canonicalizer for the exponential atom
Dcp2Cone.exp_canon(expr, args)
Dcp2Cone.exp_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from an exponential atom where the objective function is the variable t with an ExpCone constraint.
Dcp2Cone canonicalizer for the geometric mean atom
Dcp2Cone.geo_mean_canon(expr, args)
Dcp2Cone.geo_mean_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a geometric mean atom where the objective function is the variable t with geometric mean constraints
Dcp2Cone canonicalizer for the huber atom
Dcp2Cone.huber_canon(expr, args)
Dcp2Cone.huber_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a huber atom where the objective function is the variable t with square and absolute constraints
Dcp2Cone canonicalizer for the indicator atom
Dcp2Cone.indicator_canon(expr, args)
Dcp2Cone.indicator_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from an indicator atom and where 0 is the objective function with the given constraints in the function.
Dcp2Cone canonicalizer for the KL Divergence atom
Dcp2Cone.kl_div_canon(expr, args)
Dcp2Cone.kl_div_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a KL divergence atom where t is the objective function with the ExpCone constraints.
Dcp2Cone canonicalizer for the lambda maximization atom
Dcp2Cone.lambda_max_canon(expr, args)
Dcp2Cone.lambda_max_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a lambda maximization atom where t is the objective function and a PSD constraint and a constraint requiring I*t to be symmetric.
Dcp2Cone canonicalizer for the largest lambda sum atom
Dcp2Cone.lambda_sum_largest_canon(expr, args)
Dcp2Cone.lambda_sum_largest_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a lambda sum of the k largest elements atom where k*t + trace(Z) is the objective function. t denotes the variable subject to constraints and Z is a PSD matrix variable whose dimensions consist of the length of the vector at hand. The constraints require the the diagonal matrix of the vector to be symmetric and PSD.
Dcp2Cone canonicalizer for the log atom
Dcp2Cone.log_canon(expr, args)
Dcp2Cone.log_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a log atom where t is the objective function and the constraints consist of ExpCone constraints
Dcp2Cone canonicalizer for the log determinant atom
Dcp2Cone.log_det_canon(expr, args)
Dcp2Cone.log_det_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a log determinant atom where the objective function is the sum of the log of the vector D and the constraints consist of requiring the matrix Z to be diagonal and the diagonal Z to equal D, Z to be upper triangular and DZ; t(Z)A to be positive semidefinite, where A is a n by n matrix.
Dcp2Cone canonicalizer for the log sum of the exp atom
Dcp2Cone.log_sum_exp_canon(expr, args)
Dcp2Cone.log_sum_exp_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from the log sum of the exp atom where the objective is the t variable and the constraints consist of the ExpCone constraints and requiring t to be less than a matrix of ones of the same size.
Dcp2Cone canonicalizer for the log 1p atom
Dcp2Cone.log1p_canon(expr, args)
Dcp2Cone.log1p_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a log 1p atom where t is the objective function and the constraints consist of ExpCone constraints + 1.
Dcp2Cone canonicalizer for the logistic function atom
Dcp2Cone.logistic_canon(expr, args)
Dcp2Cone.logistic_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from the logistic atom where the objective function is given by t0 and the constraints consist of the ExpCone constraints.
Dcp2Cone canonicalizer for the matrix fraction atom
Dcp2Cone.matrix_frac_canon(expr, args)
Dcp2Cone.matrix_frac_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from the matrix fraction atom, where the objective function is the trace of Tvar, a m by m matrix where the constraints consist of the matrix of the Schur complement of Tvar to consist of P, an n by n, given matrix, X, an n by m given matrix, and Tvar.
Dcp2Cone canonicalizer for the nuclear norm atom
Dcp2Cone.normNuc_canon(expr, args)
Dcp2Cone.normNuc_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a nuclear norm atom, where the objective function consists of .5 times the trace of a matrix X of size m+n by m+n where the constraint consist of the top right corner of the matrix being the original matrix.
Dcp2Cone canonicalizer for the p norm atom
Dcp2Cone.pnorm_canon(expr, args)
Dcp2Cone.pnorm_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a pnorm atom, where the objective is a variable t of dimension of the original vector in the problem and the constraints consist of geometric mean constraints.
Dcp2Cone canonicalizer for the power atom
Dcp2Cone.power_canon(expr, args)
Dcp2Cone.power_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a power atom, where the objective function consists of the variable t which is of the dimension of the original vector from the power atom and the constraints consists of geometric mean constraints.
Dcp2Cone canonicalizer for the quadratic form atom
Dcp2Cone.quad_form_canon(expr, args)
Dcp2Cone.quad_form_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a quadratic form atom, where the objective function consists of the scaled objective function from the quadratic over linear canonicalization and same with the constraints.
Dcp2Cone canonicalizer for the quadratic over linear term atom
Dcp2Cone.quad_over_lin_canon(expr, args)
Dcp2Cone.quad_over_lin_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a quadratic over linear term atom where the objective function consists of a one dimensional variable t with SOC constraints.
Dcp2Cone canonicalizer for the sigma max atom
Dcp2Cone.sigma_max_canon(expr, args)
Dcp2Cone.sigma_max_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A cone program constructed from a sigma max atom where the objective function consists of the variable t that is of the same dimension as the original expression with specified constraints in the function.
This reduction takes as input a DGP problem and returns an equivalent DCP problem. Because every (generalized) geometric program is a DGP problem, this reduction can be used to convert geometric programs into convex form.
## S4 method for signature 'Dgp2Dcp,Problem' accepts(object, problem) ## S4 method for signature 'Dgp2Dcp,Problem' perform(object, problem) ## S4 method for signature 'Dgp2Dcp' canonicalize_expr(object, expr, args) ## S4 method for signature 'Dgp2Dcp,Solution,InverseData' invert(object, solution, inverse_data)
## S4 method for signature 'Dgp2Dcp,Problem' accepts(object, problem) ## S4 method for signature 'Dgp2Dcp,Problem' perform(object, problem) ## S4 method for signature 'Dgp2Dcp' canonicalize_expr(object, expr, args) ## S4 method for signature 'Dgp2Dcp,Solution,InverseData' invert(object, solution, inverse_data)
object |
A Dgp2Dcp object. |
problem |
A Problem object. |
expr |
An Expression object corresponding to the DGP problem. |
args |
A list of values corresponding to the DGP expression |
solution |
A Solution object to invert. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
accepts(object = Dgp2Dcp, problem = Problem)
: Is the problem DGP?
perform(object = Dgp2Dcp, problem = Problem)
: Converts the DGP problem to a DCP problem.
canonicalize_expr(Dgp2Dcp)
: Canonicalizes each atom within an Dgp2Dcp expression.
invert(object = Dgp2Dcp, solution = Solution, inverse_data = InverseData)
: Returns the solution to the original problem given the inverse_data.
Dgp2Dcp canonicalizer for the addition atom
Dgp2Dcp.add_canon(expr, args)
Dgp2Dcp.add_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the addition atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the constant atom
Dgp2Dcp.constant_canon(expr, args)
Dgp2Dcp.constant_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the constant atom of a DGP expression, where the returned expression is the DCP equivalent resulting from the log of the expression.
Dgp2Dcp canonicalizer for the division atom
Dgp2Dcp.div_canon(expr, args)
Dgp2Dcp.div_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the division atom of a DGP expression, where the returned expression is the log transformed DCP equivalent.
Dgp2Dcp canonicalizer for the exp atom
Dgp2Dcp.exp_canon(expr, args)
Dgp2Dcp.exp_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the exp atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
atomDgp2Dcp canonicalizer for the atom
Dgp2Dcp.eye_minus_inv_canon(expr, args)
Dgp2Dcp.eye_minus_inv_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the atom of a DGP expression,
where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the geometric mean atom
Dgp2Dcp.geo_mean_canon(expr, args)
Dgp2Dcp.geo_mean_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the geometric mean atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the log atom
Dgp2Dcp.log_canon(expr, args)
Dgp2Dcp.log_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the log atom of a DGP expression, where the returned expression is the log of the original expression..
Dgp2Dcp canonicalizer for the multiplication atom
Dgp2Dcp.mul_canon(expr, args)
Dgp2Dcp.mul_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the multiplication atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the multiplication expression atom
Dgp2Dcp.mulexpression_canon(expr, args)
Dgp2Dcp.mulexpression_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the multiplication expression atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the non-positive constraint atom
Dgp2Dcp.nonpos_constr_canon(expr, args)
Dgp2Dcp.nonpos_constr_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the non-positive contraint atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the infinite norm atom
Dgp2Dcp.norm_inf_canon(expr, args)
Dgp2Dcp.norm_inf_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the infinity norm atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the 1 norm atom
Dgp2Dcp.norm1_canon(expr, args)
Dgp2Dcp.norm1_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the norm1 atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the 1-x atom
Dgp2Dcp.one_minus_pos_canon(expr, args)
Dgp2Dcp.one_minus_pos_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the 1-x with 0 < x < 1 atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the parameter atom
Dgp2Dcp.parameter_canon(expr, args)
Dgp2Dcp.parameter_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the parameter atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the spectral radius atom
Dgp2Dcp.pf_eigenvalue_canon(expr, args)
Dgp2Dcp.pf_eigenvalue_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the spectral radius atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the p norm atom
Dgp2Dcp.pnorm_canon(expr, args)
Dgp2Dcp.pnorm_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the pnorm atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the power atom
Dgp2Dcp.power_canon(expr, args)
Dgp2Dcp.power_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the power atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the product atom
Dgp2Dcp.prod_canon(expr, args)
Dgp2Dcp.prod_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the product atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the quadratic form atom
Dgp2Dcp.quad_form_canon(expr, args)
Dgp2Dcp.quad_form_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the quadratic form atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the quadratic over linear term atom
Dgp2Dcp.quad_over_lin_canon(expr, args)
Dgp2Dcp.quad_over_lin_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the quadratic over linear atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the sum atom
Dgp2Dcp.sum_canon(expr, args)
Dgp2Dcp.sum_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the sum atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the trace atom
Dgp2Dcp.trace_canon(expr, args)
Dgp2Dcp.trace_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the trace atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Dgp2Dcp canonicalizer for the zero constraint atom
Dgp2Dcp.zero_constr_canon(expr, args)
Dgp2Dcp.zero_constr_canon(expr, args)
expr |
An Expression object |
args |
A list of values for the expr variable |
A canonicalization of the zero constraint atom of a DGP expression, where the returned expression is the transformed DCP equivalent.
Canonicalization of DGPs is a stateful procedure, hence the need for a class.
## S4 method for signature 'DgpCanonMethods' names(x) ## S4 method for signature 'DgpCanonMethods' x$name
## S4 method for signature 'DgpCanonMethods' names(x) ## S4 method for signature 'DgpCanonMethods' x$name
x |
A DgpCanonMethods object. |
name |
The name of the atom or expression to canonicalize. |
names(DgpCanonMethods)
: Returns the name of all the canonicalization methods
$
: Returns either a canonicalized variable or
a corresponding Dgp2Dcp canonicalization method
Turns an expression into a DiagVec object
Diag(expr)
Diag(expr)
expr |
An Expression that represents a vector or square matrix. |
An Expression representing the diagonal vector/matrix.
Extracts the diagonal from a matrix or makes a vector into a diagonal matrix.
## S4 method for signature 'Expression' diag(x = 1, nrow, ncol)
## S4 method for signature 'Expression' diag(x = 1, nrow, ncol)
x |
An Expression, vector, or square matrix. |
nrow , ncol
|
(Optional) Dimensions for the result when |
An Expression representing the diagonal vector or matrix.
C <- Variable(3,3) obj <- Maximize(C[1,3]) constraints <- list(diag(C) == 1, C[1,2] == 0.6, C[2,3] == -0.3, C == Variable(3,3, PSD = TRUE)) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(C)
C <- Variable(3,3) obj <- Maximize(C[1,3]) constraints <- list(diag(C) == 1, C[1,2] == 0.6, C[2,3] == -0.3, C == Variable(3,3, PSD = TRUE)) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(C)
This class represents the extraction of the diagonal from a square matrix.
DiagMat(expr) ## S4 method for signature 'DiagMat' to_numeric(object, values) ## S4 method for signature 'DiagMat' dim_from_args(object) ## S4 method for signature 'DiagMat' is_atom_log_log_convex(object) ## S4 method for signature 'DiagMat' is_atom_log_log_concave(object) ## S4 method for signature 'DiagMat' graph_implementation(object, arg_objs, dim, data = NA_real_)
DiagMat(expr) ## S4 method for signature 'DiagMat' to_numeric(object, values) ## S4 method for signature 'DiagMat' dim_from_args(object) ## S4 method for signature 'DiagMat' is_atom_log_log_convex(object) ## S4 method for signature 'DiagMat' is_atom_log_log_concave(object) ## S4 method for signature 'DiagMat' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression representing the matrix whose diagonal we are interested in. |
object |
A DiagMat object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(DiagMat)
: Extract the diagonal from a square matrix constant.
dim_from_args(DiagMat)
: The size of the atom.
is_atom_log_log_convex(DiagMat)
: Is the atom log-log convex?
is_atom_log_log_concave(DiagMat)
: Is the atom log-log concave?
graph_implementation(DiagMat)
: The graph implementation of the atom.
expr
An Expression representing the matrix whose diagonal we are interested in.
This class represents the conversion of a vector into a diagonal matrix.
DiagVec(expr) ## S4 method for signature 'DiagVec' to_numeric(object, values) ## S4 method for signature 'DiagVec' dim_from_args(object) ## S4 method for signature 'DiagVec' is_atom_log_log_convex(object) ## S4 method for signature 'DiagVec' is_atom_log_log_concave(object) ## S4 method for signature 'DiagVec' is_symmetric(object) ## S4 method for signature 'DiagVec' is_hermitian(object) ## S4 method for signature 'DiagVec' graph_implementation(object, arg_objs, dim, data = NA_real_)
DiagVec(expr) ## S4 method for signature 'DiagVec' to_numeric(object, values) ## S4 method for signature 'DiagVec' dim_from_args(object) ## S4 method for signature 'DiagVec' is_atom_log_log_convex(object) ## S4 method for signature 'DiagVec' is_atom_log_log_concave(object) ## S4 method for signature 'DiagVec' is_symmetric(object) ## S4 method for signature 'DiagVec' is_hermitian(object) ## S4 method for signature 'DiagVec' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression representing the vector to convert. |
object |
A DiagVec object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(DiagVec)
: Convert the vector constant into a diagonal matrix.
dim_from_args(DiagVec)
: The dimensions of the atom.
is_atom_log_log_convex(DiagVec)
: Is the atom log-log convex?
is_atom_log_log_concave(DiagVec)
: Is the atom log-log concave?
is_symmetric(DiagVec)
: Is the expression symmetric?
is_hermitian(DiagVec)
: Is the expression hermitian?
graph_implementation(DiagVec)
: The graph implementation of the atom.
expr
An Expression representing the vector to convert.
Takes the k-th order differences
Diff(x, lag = 1, k = 1, axis = 2)
Diff(x, lag = 1, k = 1, axis = 2)
x |
An Expression that represents a vector |
lag |
The degree of lag between differences |
k |
The integer value of the order of differences |
axis |
The axis along which to apply the function. For a 2D matrix, |
Takes in a vector of length n and returns a vector of length n-k of the kth order differences
The lagged and iterated differences of a vector.
If x
is length n
, this function returns a length vector of the
th order difference between the lagged terms.
diff(x)
returns the vector of differences between adjacent elements in the vector, i.e. [x[2] - x[1], x[3] - x[2], ...].
diff(x,1,2)
is the second-order differences vector, equivalently diff(diff(x)). diff(x,1,0)
returns the vector x unchanged.
diff(x,2)
returns the vector of differences [x[3] - x[1], x[4] - x[2], ...], equivalent to x[(1+lag):n] - x[1:(n-lag)]
.
## S4 method for signature 'Expression' diff(x, lag = 1, differences = 1, ...)
## S4 method for signature 'Expression' diff(x, lag = 1, differences = 1, ...)
x |
An Expression. |
lag |
An integer indicating which lag to use. |
differences |
An integer indicating the order of the difference. |
... |
(Optional) Addition |
An Expression representing the k
th order difference.
## Problem data m <- 101 L <- 2 h <- L/(m-1) ## Form objective and constraints x <- Variable(m) y <- Variable(m) obj <- sum(y) constr <- list(x[1] == 0, y[1] == 1, x[m] == 1, y[m] == 1, diff(x)^2 + diff(y)^2 <= h^2) ## Solve the catenary problem prob <- Problem(Minimize(obj), constr) result <- solve(prob) ## Plot and compare with ideal catenary xs <- result$getValue(x) ys <- result$getValue(y) plot(c(0, 1), c(0, 1), type = 'n', xlab = "x", ylab = "y") lines(xs, ys, col = "blue", lwd = 2) grid()
## Problem data m <- 101 L <- 2 h <- L/(m-1) ## Form objective and constraints x <- Variable(m) y <- Variable(m) obj <- sum(y) constr <- list(x[1] == 0, y[1] == 1, x[m] == 1, y[m] == 1, diff(x)^2 + diff(y)^2 <= h^2) ## Solve the catenary problem prob <- Problem(Minimize(obj), constr) result <- solve(prob) ## Plot and compare with ideal catenary xs <- result$getValue(x) ys <- result$getValue(y) plot(c(0, 1), c(0, 1), type = 'n', xlab = "x", ylab = "y") lines(xs, ys, col = "blue", lwd = 2) grid()
The difference between expressions, , where
.
DiffPos(x, y)
DiffPos(x, y)
x |
An Expression |
y |
An Expression |
The difference with domain
.
Determine the dimensions of an atom based on its arguments.
dim_from_args(object) ## S4 method for signature 'Atom' dim_from_args(object)
dim_from_args(object) ## S4 method for signature 'Atom' dim_from_args(object)
object |
A Atom object. |
A numeric vector c(row, col)
indicating the dimensions of the atom.
A list of constraints describing the closure of the region where the expression is finite.
domain(object)
domain(object)
object |
An Expression object. |
A list of Constraint objects.
a <- Variable(name = "a") dom <- domain(p_norm(a, -0.5)) prob <- Problem(Minimize(a), dom) result <- solve(prob) result$value b <- Variable() dom <- domain(kl_div(a, b)) result <- solve(Problem(Minimize(a + b), dom)) result$getValue(a) result$getValue(b) A <- Variable(2, 2, name = "A") dom <- domain(lambda_max(A)) A0 <- rbind(c(1,2), c(3,4)) result <- solve(Problem(Minimize(norm2(A - A0)), dom)) result$getValue(A) dom <- domain(log_det(A + diag(rep(1,2)))) prob <- Problem(Minimize(sum(diag(A))), dom) result <- solve(prob, solver = "SCS") result$value
a <- Variable(name = "a") dom <- domain(p_norm(a, -0.5)) prob <- Problem(Minimize(a), dom) result <- solve(prob) result$value b <- Variable() dom <- domain(kl_div(a, b)) result <- solve(Problem(Minimize(a + b), dom)) result$getValue(a) result$getValue(b) A <- Variable(2, 2, name = "A") dom <- domain(lambda_max(A)) A0 <- rbind(c(1,2), c(3,4)) result <- solve(Problem(Minimize(norm2(A - A0)), dom)) result$getValue(A) dom <- domain(log_det(A + diag(rep(1,2)))) prob <- Problem(Minimize(sum(diag(A))), dom) result <- solve(prob, solver = "SCS") result$value
Randomly generated data for direct standardization example.
Sex was drawn from a Bernoulli distribution, and age was drawn from a uniform distribution on .
The response was drawn from a normal distribution with a mean that depends on sex and age, and a variance of 1.
dspop
dspop
A data frame with 1000 rows and 3 variables:
Response variable
Sex of individual, coded male (0) and female (1)
Age of individual
A sample of dspop
for direct standardization example.
The sample is skewed such that young males are overrepresented in comparison to the population.
dssamp
dssamp
A data frame with 100 rows and 3 variables:
Response variable
Sex of individual, coded male (0) and female (1)
Age of individual
Get and set the value of the dual variable in a constraint.
dual_value(object) dual_value(object) <- value
dual_value(object) dual_value(object) <- value
object |
A Constraint object. |
value |
A numeric scalar, vector, or matrix to assign to the object. |
An interface for the ECOS BB solver.
ECOS_BB() ## S4 method for signature 'ECOS_BB' mip_capable(solver) ## S4 method for signature 'ECOS_BB' name(x) ## S4 method for signature 'ECOS_BB,Problem' perform(object, problem) ## S4 method for signature 'ECOS_BB' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
ECOS_BB() ## S4 method for signature 'ECOS_BB' mip_capable(solver) ## S4 method for signature 'ECOS_BB' name(x) ## S4 method for signature 'ECOS_BB,Problem' perform(object, problem) ## S4 method for signature 'ECOS_BB' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A ECOS_BB object. |
problem |
A Problem object. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(ECOS_BB)
: Can the solver handle mixed-integer programs?
name(ECOS_BB)
: Returns the name of the solver.
perform(object = ECOS_BB, problem = Problem)
: Returns a new problem and data for inverting the new solution.
solve_via_data(ECOS_BB)
: Solve a problem represented by data returned from apply.
An interface for the ECOS solver
ECOS() ## S4 method for signature 'ECOS' mip_capable(solver) ## S4 method for signature 'ECOS' status_map(solver, status) ## S4 method for signature 'ECOS' import_solver(solver) ## S4 method for signature 'ECOS' name(x) ## S4 method for signature 'ECOS,Problem' perform(object, problem) ## S4 method for signature 'ECOS,list,list' invert(object, solution, inverse_data)
ECOS() ## S4 method for signature 'ECOS' mip_capable(solver) ## S4 method for signature 'ECOS' status_map(solver, status) ## S4 method for signature 'ECOS' import_solver(solver) ## S4 method for signature 'ECOS' name(x) ## S4 method for signature 'ECOS,Problem' perform(object, problem) ## S4 method for signature 'ECOS,list,list' invert(object, solution, inverse_data)
solver , object , x
|
A ECOS object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
mip_capable(ECOS)
: Can the solver handle mixed-integer programs?
status_map(ECOS)
: Converts status returned by the ECOS solver to its respective CVXPY status.
import_solver(ECOS)
: Imports the solver
name(ECOS)
: Returns the name of the solver
perform(object = ECOS, problem = Problem)
: Returns a new problem and data for inverting the new solution.
invert(object = ECOS, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
Utility method for formatting a ConeDims instance into a dictionary that can be supplied to ECOS.
ECOS.dims_to_solver_dict(cone_dims)
ECOS.dims_to_solver_dict(cone_dims)
cone_dims |
A ConeDims instance. |
A dictionary of cone dimensions
This virtual class represents an elementwise atom.
## S4 method for signature 'Elementwise' dim_from_args(object) ## S4 method for signature 'Elementwise' validate_args(object) ## S4 method for signature 'Elementwise' is_symmetric(object)
## S4 method for signature 'Elementwise' dim_from_args(object) ## S4 method for signature 'Elementwise' validate_args(object) ## S4 method for signature 'Elementwise' is_symmetric(object)
object |
An Elementwise object. |
dim_from_args(Elementwise)
: Dimensions is the same as the sum of the arguments' dimensions.
validate_args(Elementwise)
: Verify that all the dimensions are the same or can be promoted.
is_symmetric(Elementwise)
: Is the expression symmetric?
This class eliminates piecewise linear atoms.
## S4 method for signature 'EliminatePwl,Problem' accepts(object, problem)
## S4 method for signature 'EliminatePwl,Problem' accepts(object, problem)
object |
An EliminatePwl object. |
problem |
A Problem object. |
accepts(object = EliminatePwl, problem = Problem)
: Does this problem contain piecewise linear atoms?
EliminatePwl canonicalizer for the absolute atom
EliminatePwl.abs_canon(expr, args)
EliminatePwl.abs_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the picewise-lienar atom constructed from an absolute atom where the objective function consists of the variable that is of the same dimension as the original expression and the constraints consist of splitting the absolute value into two inequalities.
EliminatePwl canonicalizer for the cumulative max atom
EliminatePwl.cummax_canon(expr, args)
EliminatePwl.cummax_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed from a cumulative max atom where the objective function consists of the variable Y which is of the same dimension as the original expression and the constraints consist of row/column constraints depending on the axis
EliminatePwl canonicalizer for the cumulative sum atom
EliminatePwl.cumsum_canon(expr, args)
EliminatePwl.cumsum_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed from a cumulative sum atom where the objective is Y that is of the same dimension as the matrix of the expression and the constraints consist of various row constraints
EliminatePwl canonicalizer for the elementwise maximum atom
EliminatePwl.max_elemwise_canon(expr, args)
EliminatePwl.max_elemwise_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by a elementwise maximum atom where the objective function is the variable t of the same dimension as the expression and the constraints consist of a simple inequality.
EliminatePwl canonicalizer for the max entries atom
EliminatePwl.max_entries_canon(expr, args)
EliminatePwl.max_entries_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed from the max entries atom where the objective function consists of the variable t of the same size as the original expression and the constraints consist of a vector multiplied by a vector of 1's.
EliminatePwl canonicalizer for the elementwise minimum atom
EliminatePwl.min_elemwise_canon(expr, args)
EliminatePwl.min_elemwise_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by a minimum elementwise atom where the objective function is the negative of variable t t produced by max_elemwise_canon of the same dimension as the expression and the constraints consist of a simple inequality.
EliminatePwl canonicalizer for the minimum entries atom
EliminatePwl.min_entries_canon(expr, args)
EliminatePwl.min_entries_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by a minimum entries atom where the objective function is the negative of variable t produced by max_elemwise_canon of the same dimension as the expression and the constraints consist of a simple inequality.
EliminatePwl canonicalizer for the infinite norm atom
EliminatePwl.norm_inf_canon(expr, args)
EliminatePwl.norm_inf_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by the infinite norm atom where the objective function consists variable t of the same dimension as the expression and the constraints consist of a vector constructed by multiplying t to a vector of 1's
EliminatePwl canonicalizer for the 1 norm atom
EliminatePwl.norm1_canon(expr, args)
EliminatePwl.norm1_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by the norm1 atom where the objective functino consists of the sum of the variables created by the abs_canon function and the constraints consist of constraints generated by abs_canon.
EliminatePwl canonicalizer for the largest sum atom
EliminatePwl.sum_largest_canon(expr, args)
EliminatePwl.sum_largest_canon(expr, args)
expr |
An Expression object |
args |
A list of Constraint objects |
A canonicalization of the piecewise-lienar atom constructed by the k largest sums atom where the objective function consists of the sum of variables t that is of the same dimension as the expression plus k
The elementwise entropy function, .
entr(x)
entr(x)
x |
An Expression, vector, or matrix. |
An Expression representing the entropy of the input.
x <- Variable(5) obj <- Maximize(sum(entr(x))) prob <- Problem(obj, list(sum(x) == 1)) result <- solve(prob) result$getValue(x)
x <- Variable(5) obj <- Maximize(sum(entr(x))) prob <- Problem(obj, list(sum(x) == 1)) result <- solve(prob) result$getValue(x)
This class represents the elementwise operation .
Entr(x) ## S4 method for signature 'Entr' to_numeric(object, values) ## S4 method for signature 'Entr' sign_from_args(object) ## S4 method for signature 'Entr' is_atom_convex(object) ## S4 method for signature 'Entr' is_atom_concave(object) ## S4 method for signature 'Entr' is_incr(object, idx) ## S4 method for signature 'Entr' is_decr(object, idx) ## S4 method for signature 'Entr' .grad(object, values) ## S4 method for signature 'Entr' .domain(object)
Entr(x) ## S4 method for signature 'Entr' to_numeric(object, values) ## S4 method for signature 'Entr' sign_from_args(object) ## S4 method for signature 'Entr' is_atom_convex(object) ## S4 method for signature 'Entr' is_atom_concave(object) ## S4 method for signature 'Entr' is_incr(object, idx) ## S4 method for signature 'Entr' is_decr(object, idx) ## S4 method for signature 'Entr' .grad(object, values) ## S4 method for signature 'Entr' .domain(object)
x |
An Expression or numeric constant. |
object |
An Entr object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(Entr)
: The elementwise entropy function evaluated at the value.
sign_from_args(Entr)
: The sign of the atom is unknown.
is_atom_convex(Entr)
: The atom is not convex.
is_atom_concave(Entr)
: The atom is concave.
is_incr(Entr)
: The atom is weakly increasing.
is_decr(Entr)
: The atom is weakly decreasing.
.grad(Entr)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(Entr)
: Returns constraints descrbing the domain of the node
x
An Expression or numeric constant.
This class represents a reduction that replaces symbolic parameters with their constaint values.
## S4 method for signature 'EvalParams,Problem' perform(object, problem) ## S4 method for signature 'EvalParams,Solution,list' invert(object, solution, inverse_data)
## S4 method for signature 'EvalParams,Problem' perform(object, problem) ## S4 method for signature 'EvalParams,Solution,list' invert(object, solution, inverse_data)
object |
A EvalParams object. |
problem |
A Problem object. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
The inverse data returned by an invocation to apply. |
perform(object = EvalParams, problem = Problem)
: Replace parameters with constant values.
invert(object = EvalParams, solution = Solution, inverse_data = list)
: Returns a solution to the original problem given the inverse_data.
This class represents the elementwise natural exponential .
Exp(x) ## S4 method for signature 'Exp' to_numeric(object, values) ## S4 method for signature 'Exp' sign_from_args(object) ## S4 method for signature 'Exp' is_atom_convex(object) ## S4 method for signature 'Exp' is_atom_concave(object) ## S4 method for signature 'Exp' is_atom_log_log_convex(object) ## S4 method for signature 'Exp' is_atom_log_log_concave(object) ## S4 method for signature 'Exp' is_incr(object, idx) ## S4 method for signature 'Exp' is_decr(object, idx) ## S4 method for signature 'Exp' .grad(object, values)
Exp(x) ## S4 method for signature 'Exp' to_numeric(object, values) ## S4 method for signature 'Exp' sign_from_args(object) ## S4 method for signature 'Exp' is_atom_convex(object) ## S4 method for signature 'Exp' is_atom_concave(object) ## S4 method for signature 'Exp' is_atom_log_log_convex(object) ## S4 method for signature 'Exp' is_atom_log_log_concave(object) ## S4 method for signature 'Exp' is_incr(object, idx) ## S4 method for signature 'Exp' is_decr(object, idx) ## S4 method for signature 'Exp' .grad(object, values)
x |
An Expression object. |
object |
An Exp object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(Exp)
: The matrix with each element exponentiated.
sign_from_args(Exp)
: The atom is positive.
is_atom_convex(Exp)
: The atom is convex.
is_atom_concave(Exp)
: The atom is not concave.
is_atom_log_log_convex(Exp)
: Is the atom log-log convex?
is_atom_log_log_concave(Exp)
: Is the atom log-log concave?
is_incr(Exp)
: The atom is weakly increasing.
is_decr(Exp)
: The atom is not weakly decreasing.
.grad(Exp)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression object.
The elementwise natural exponential.
## S4 method for signature 'Expression' exp(x)
## S4 method for signature 'Expression' exp(x)
x |
An Expression. |
An Expression representing the natural exponential of the input.
x <- Variable(5) obj <- Minimize(sum(exp(x))) prob <- Problem(obj, list(sum(x) == 1)) result <- solve(prob) result$getValue(x)
x <- Variable(5) obj <- Minimize(sum(exp(x))) prob <- Problem(obj, list(sum(x) == 1)) result <- solve(prob) result$getValue(x)
This class represents a reformulated exponential cone constraint operating elementwise on .
ExpCone(x, y, z, id = NA_integer_) ## S4 method for signature 'ExpCone' as.character(x) ## S4 method for signature 'ExpCone' residual(object) ## S4 method for signature 'ExpCone' size(object) ## S4 method for signature 'ExpCone' num_cones(object) ## S4 method for signature 'ExpCone' cone_sizes(object) ## S4 method for signature 'ExpCone' is_dcp(object) ## S4 method for signature 'ExpCone' is_dgp(object) ## S4 method for signature 'ExpCone' canonicalize(object)
ExpCone(x, y, z, id = NA_integer_) ## S4 method for signature 'ExpCone' as.character(x) ## S4 method for signature 'ExpCone' residual(object) ## S4 method for signature 'ExpCone' size(object) ## S4 method for signature 'ExpCone' num_cones(object) ## S4 method for signature 'ExpCone' cone_sizes(object) ## S4 method for signature 'ExpCone' is_dcp(object) ## S4 method for signature 'ExpCone' is_dgp(object) ## S4 method for signature 'ExpCone' canonicalize(object)
x |
The variable |
y |
The variable |
z |
The variable |
id |
(Optional) A numeric value representing the constraint ID. |
object |
A ExpCone object. |
Original cone:
Reformulated cone:
residual(ExpCone)
: The size of the x
argument.
size(ExpCone)
: The number of entries in the combined cones.
num_cones(ExpCone)
: The number of elementwise cones.
cone_sizes(ExpCone)
: The dimensions of the exponential cones.
is_dcp(ExpCone)
: An exponential constraint is DCP if each argument is affine.
is_dgp(ExpCone)
: Is the constraint DGP?
canonicalize(ExpCone)
: Canonicalizes by converting expressions to LinOps.
x
The variable in the exponential cone.
y
The variable in the exponential cone.
z
The variable in the exponential cone.
This class represents a mathematical expression.
## S4 method for signature 'Expression' value(object) ## S4 method for signature 'Expression' grad(object) ## S4 method for signature 'Expression' domain(object) ## S4 method for signature 'Expression' as.character(x) ## S4 method for signature 'Expression' name(x) ## S4 method for signature 'Expression' expr(object) ## S4 method for signature 'Expression' is_constant(object) ## S4 method for signature 'Expression' is_affine(object) ## S4 method for signature 'Expression' is_convex(object) ## S4 method for signature 'Expression' is_concave(object) ## S4 method for signature 'Expression' is_dcp(object) ## S4 method for signature 'Expression' is_log_log_constant(object) ## S4 method for signature 'Expression' is_log_log_affine(object) ## S4 method for signature 'Expression' is_log_log_convex(object) ## S4 method for signature 'Expression' is_log_log_concave(object) ## S4 method for signature 'Expression' is_dgp(object) ## S4 method for signature 'Expression' is_hermitian(object) ## S4 method for signature 'Expression' is_psd(object) ## S4 method for signature 'Expression' is_nsd(object) ## S4 method for signature 'Expression' is_quadratic(object) ## S4 method for signature 'Expression' is_symmetric(object) ## S4 method for signature 'Expression' is_pwl(object) ## S4 method for signature 'Expression' is_qpwa(object) ## S4 method for signature 'Expression' is_zero(object) ## S4 method for signature 'Expression' is_nonneg(object) ## S4 method for signature 'Expression' is_nonpos(object) ## S4 method for signature 'Expression' dim(x) ## S4 method for signature 'Expression' is_real(object) ## S4 method for signature 'Expression' is_imag(object) ## S4 method for signature 'Expression' is_complex(object) ## S4 method for signature 'Expression' size(object) ## S4 method for signature 'Expression' ndim(object) ## S4 method for signature 'Expression' flatten(object) ## S4 method for signature 'Expression' is_scalar(object) ## S4 method for signature 'Expression' is_vector(object) ## S4 method for signature 'Expression' is_matrix(object) ## S4 method for signature 'Expression' nrow(x) ## S4 method for signature 'Expression' ncol(x)
## S4 method for signature 'Expression' value(object) ## S4 method for signature 'Expression' grad(object) ## S4 method for signature 'Expression' domain(object) ## S4 method for signature 'Expression' as.character(x) ## S4 method for signature 'Expression' name(x) ## S4 method for signature 'Expression' expr(object) ## S4 method for signature 'Expression' is_constant(object) ## S4 method for signature 'Expression' is_affine(object) ## S4 method for signature 'Expression' is_convex(object) ## S4 method for signature 'Expression' is_concave(object) ## S4 method for signature 'Expression' is_dcp(object) ## S4 method for signature 'Expression' is_log_log_constant(object) ## S4 method for signature 'Expression' is_log_log_affine(object) ## S4 method for signature 'Expression' is_log_log_convex(object) ## S4 method for signature 'Expression' is_log_log_concave(object) ## S4 method for signature 'Expression' is_dgp(object) ## S4 method for signature 'Expression' is_hermitian(object) ## S4 method for signature 'Expression' is_psd(object) ## S4 method for signature 'Expression' is_nsd(object) ## S4 method for signature 'Expression' is_quadratic(object) ## S4 method for signature 'Expression' is_symmetric(object) ## S4 method for signature 'Expression' is_pwl(object) ## S4 method for signature 'Expression' is_qpwa(object) ## S4 method for signature 'Expression' is_zero(object) ## S4 method for signature 'Expression' is_nonneg(object) ## S4 method for signature 'Expression' is_nonpos(object) ## S4 method for signature 'Expression' dim(x) ## S4 method for signature 'Expression' is_real(object) ## S4 method for signature 'Expression' is_imag(object) ## S4 method for signature 'Expression' is_complex(object) ## S4 method for signature 'Expression' size(object) ## S4 method for signature 'Expression' ndim(object) ## S4 method for signature 'Expression' flatten(object) ## S4 method for signature 'Expression' is_scalar(object) ## S4 method for signature 'Expression' is_vector(object) ## S4 method for signature 'Expression' is_matrix(object) ## S4 method for signature 'Expression' nrow(x) ## S4 method for signature 'Expression' ncol(x)
x , object
|
An Expression object. |
value(Expression)
: The value of the expression.
grad(Expression)
: The (sub/super)-gradient of the expression with respect to each variable.
domain(Expression)
: A list of constraints describing the closure of the region where the expression is finite.
as.character(Expression)
: The string representation of the expression.
name(Expression)
: The name of the expression.
expr(Expression)
: The expression itself.
is_constant(Expression)
: The expression is constant if it contains no variables or is identically zero.
is_affine(Expression)
: The expression is affine if it is constant or both convex and concave.
is_convex(Expression)
: A logical value indicating whether the expression is convex.
is_concave(Expression)
: A logical value indicating whether the expression is concave.
is_dcp(Expression)
: The expression is DCP if it is convex or concave.
is_log_log_constant(Expression)
: Is the expression log-log constant, i.e., elementwise positive?
is_log_log_affine(Expression)
: Is the expression log-log affine?
is_log_log_convex(Expression)
: Is the expression log-log convex?
is_log_log_concave(Expression)
: Is the expression log-log concave?
is_dgp(Expression)
: The expression is DGP if it is log-log DCP.
is_hermitian(Expression)
: A logical value indicating whether the expression is a Hermitian matrix.
is_psd(Expression)
: A logical value indicating whether the expression is a positive semidefinite matrix.
is_nsd(Expression)
: A logical value indicating whether the expression is a negative semidefinite matrix.
is_quadratic(Expression)
: A logical value indicating whether the expression is quadratic.
is_symmetric(Expression)
: A logical value indicating whether the expression is symmetric.
is_pwl(Expression)
: A logical value indicating whether the expression is piecewise linear.
is_qpwa(Expression)
: A logical value indicating whether the expression is quadratic of piecewise affine.
is_zero(Expression)
: The expression is zero if it is both nonnegative and nonpositive.
is_nonneg(Expression)
: A logical value indicating whether the expression is nonnegative.
is_nonpos(Expression)
: A logical value indicating whether the expression is nonpositive.
dim(Expression)
: The c(row, col)
dimensions of the expression.
is_real(Expression)
: A logical value indicating whether the expression is real.
is_imag(Expression)
: A logical value indicating whether the expression is imaginary.
is_complex(Expression)
: A logical value indicating whether the expression is complex.
size(Expression)
: The number of entries in the expression.
ndim(Expression)
: The number of dimensions of the expression.
flatten(Expression)
: Vectorizes the expression.
is_scalar(Expression)
: A logical value indicating whether the expression is a scalar.
is_vector(Expression)
: A logical value indicating whether the expression is a row or column vector.
is_matrix(Expression)
: A logical value indicating whether the expression is a matrix.
nrow(Expression)
: Number of rows in the expression.
ncol(Expression)
: Number of columns in the expression.
List the variables, parameters, constants, or atoms in a canonical expression.
variables(object) parameters(object) constants(object) atoms(object)
variables(object) parameters(object) constants(object) atoms(object)
object |
A Leaf object. |
A list of Variable, Parameter, Constant, or Atom objects.
set.seed(67) m <- 50 n <- 10 beta <- Variable(n) y <- matrix(rnorm(m), nrow = m) X <- matrix(rnorm(m*n), nrow = m, ncol = n) lambda <- Parameter() expr <- sum_squares(y - X %*% beta) + lambda*p_norm(beta, 1) variables(expr) parameters(expr) constants(expr) lapply(constants(expr), function(c) { value(c) })
set.seed(67) m <- 50 n <- 10 beta <- Variable(n) y <- matrix(rnorm(m), nrow = m) X <- matrix(rnorm(m*n), nrow = m, ncol = n) lambda <- Parameter() expr <- sum_squares(y - X %*% beta) + lambda*p_norm(beta, 1) variables(expr) parameters(expr) constants(expr) lapply(constants(expr), function(c) { value(c) })
Gets a specified value of a dual variable.
extract_dual_value(result_vec, offset, constraint)
extract_dual_value(result_vec, offset, constraint)
result_vec |
A vector containing the dual variable values. |
offset |
An offset to get correct index of dual values. |
constraint |
A list of the constraints in the problem. |
A list of a dual variable value and its offset.
Coalesces bool, int indices for variables.
extract_mip_idx(variables)
extract_mip_idx(variables)
variables |
A list of Variable objects. |
Coalesces bool, int indices for variables. The indexing scheme assumes that the variables will be coalesced into a single one-dimensional variable, with each variable being reshaped in Fortran order.
The unity resolvent of a positive matrix. For an elementwise positive matrix , this atom represents
,
and it enforces the constraint that the spectral radius of
is at most 1.
eye_minus_inv(X)
eye_minus_inv(X)
X |
An Expression or positive square matrix. |
This atom is log-log convex.
An Expression representing the unity resolvent of the input.
A <- Variable(2,2, pos = TRUE) prob <- Problem(Minimize(matrix_trace(A)), list(eye_minus_inv(A) <=1)) result <- solve(prob, gp = TRUE) result$value result$getValue(A)
A <- Variable(2,2, pos = TRUE) prob <- Problem(Minimize(matrix_trace(A)), list(eye_minus_inv(A) <=1)) result <- solve(prob, gp = TRUE) result$value result$getValue(A)
This class represents the unity resolvent of an elementwise positive matrix , i.e.,
,
and it enforces the constraint that the spectral radius of
is at most 1.
This atom is log-log convex.
EyeMinusInv(X) ## S4 method for signature 'EyeMinusInv' to_numeric(object, values) ## S4 method for signature 'EyeMinusInv' name(x) ## S4 method for signature 'EyeMinusInv' dim_from_args(object) ## S4 method for signature 'EyeMinusInv' sign_from_args(object) ## S4 method for signature 'EyeMinusInv' is_atom_convex(object) ## S4 method for signature 'EyeMinusInv' is_atom_concave(object) ## S4 method for signature 'EyeMinusInv' is_atom_log_log_convex(object) ## S4 method for signature 'EyeMinusInv' is_atom_log_log_concave(object) ## S4 method for signature 'EyeMinusInv' is_incr(object, idx) ## S4 method for signature 'EyeMinusInv' is_decr(object, idx) ## S4 method for signature 'EyeMinusInv' .grad(object, values)
EyeMinusInv(X) ## S4 method for signature 'EyeMinusInv' to_numeric(object, values) ## S4 method for signature 'EyeMinusInv' name(x) ## S4 method for signature 'EyeMinusInv' dim_from_args(object) ## S4 method for signature 'EyeMinusInv' sign_from_args(object) ## S4 method for signature 'EyeMinusInv' is_atom_convex(object) ## S4 method for signature 'EyeMinusInv' is_atom_concave(object) ## S4 method for signature 'EyeMinusInv' is_atom_log_log_convex(object) ## S4 method for signature 'EyeMinusInv' is_atom_log_log_concave(object) ## S4 method for signature 'EyeMinusInv' is_incr(object, idx) ## S4 method for signature 'EyeMinusInv' is_decr(object, idx) ## S4 method for signature 'EyeMinusInv' .grad(object, values)
X |
An Expression or numeric matrix. |
object , x
|
An EyeMinusInv object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(EyeMinusInv)
: The unity resolvent of the matrix.
name(EyeMinusInv)
: The name and arguments of the atom.
dim_from_args(EyeMinusInv)
: The dimensions of the atom determined from its arguments.
sign_from_args(EyeMinusInv)
: The (is positive, is negative) sign of the atom.
is_atom_convex(EyeMinusInv)
: Is the atom convex?
is_atom_concave(EyeMinusInv)
: Is the atom concave?
is_atom_log_log_convex(EyeMinusInv)
: Is the atom log-log convex?
is_atom_log_log_concave(EyeMinusInv)
: Is the atom log-log concave?
is_incr(EyeMinusInv)
: Is the atom weakly increasing in the index?
is_decr(EyeMinusInv)
: Is the atom weakly decreasing in the index?
.grad(EyeMinusInv)
: Gives EyeMinusInv the (sub/super)gradient of the atom w.r.t. each variable
X
An Expression or numeric matrix.
This class represents a reduction that flips a minimization objective to a maximization and vice versa.
## S4 method for signature 'FlipObjective,Problem' perform(object, problem) ## S4 method for signature 'FlipObjective,Solution,list' invert(object, solution, inverse_data)
## S4 method for signature 'FlipObjective,Problem' perform(object, problem) ## S4 method for signature 'FlipObjective,Solution,list' invert(object, solution, inverse_data)
object |
A FlipObjective object. |
problem |
A Problem object. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
The inverse data returned by an invocation to apply. |
perform(object = FlipObjective, problem = Problem)
: Flip a minimization objective to a maximization and vice versa.
invert(object = FlipObjective, solution = Solution, inverse_data = list)
: Map the solution of the flipped problem to that of the original.
Format constraints for the solver.
format_constr(object, eq_constr, leq_constr, dims, solver)
format_constr(object, eq_constr, leq_constr, dims, solver)
object |
A Constraint object. |
eq_constr |
A list of the equality constraints in the canonical problem. |
leq_constr |
A list of the inequality constraints in the canonical problem. |
dims |
A list with the dimensions of the conic constraints. |
solver |
A string representing the solver to be called. |
A list containing equality constraints, inequality constraints, and dimensions.
The (weighted) geometric mean of vector with optional powers given by
.
geo_mean(x, p = NA_real_, max_denom = 1024)
geo_mean(x, p = NA_real_, max_denom = 1024)
x |
An Expression or vector. |
p |
(Optional) A vector of weights for the weighted geometric mean. Defaults to a vector of ones, giving the unweighted geometric mean |
max_denom |
(Optional) The maximum denominator to use in approximating |
The geometric mean includes an implicit constraint that whenever
. If
will be unconstrained.
The only exception to this rule occurs when
has exactly one nonzero element, say
, in which case
geo_mean(x,p)
is equivalent to (without the nonnegativity constraint).
A specific case of this is when
.
An Expression representing the geometric mean of the input.
x <- Variable(2) cost <- geo_mean(x) prob <- Problem(Maximize(cost), list(sum(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## Not run: x <- Variable(5) p <- c(0.07, 0.12, 0.23, 0.19, 0.39) prob <- Problem(Maximize(geo_mean(x,p)), list(p_norm(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
x <- Variable(2) cost <- geo_mean(x) prob <- Problem(Maximize(cost), list(sum(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## Not run: x <- Variable(5) p <- c(0.07, 0.12, 0.23, 0.19, 0.39) prob <- Problem(Maximize(geo_mean(x,p)), list(p_norm(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
This class represents the (weighted) geometric mean of vector with optional powers given by
.
GeoMean(x, p = NA_real_, max_denom = 1024) ## S4 method for signature 'GeoMean' to_numeric(object, values) ## S4 method for signature 'GeoMean' .domain(object) ## S4 method for signature 'GeoMean' .grad(object, values) ## S4 method for signature 'GeoMean' name(x) ## S4 method for signature 'GeoMean' dim_from_args(object) ## S4 method for signature 'GeoMean' sign_from_args(object) ## S4 method for signature 'GeoMean' is_atom_convex(object) ## S4 method for signature 'GeoMean' is_atom_concave(object) ## S4 method for signature 'GeoMean' is_atom_log_log_convex(object) ## S4 method for signature 'GeoMean' is_atom_log_log_concave(object) ## S4 method for signature 'GeoMean' is_incr(object, idx) ## S4 method for signature 'GeoMean' is_decr(object, idx) ## S4 method for signature 'GeoMean' get_data(object) ## S4 method for signature 'GeoMean' copy(object, args = NULL, id_objects = list())
GeoMean(x, p = NA_real_, max_denom = 1024) ## S4 method for signature 'GeoMean' to_numeric(object, values) ## S4 method for signature 'GeoMean' .domain(object) ## S4 method for signature 'GeoMean' .grad(object, values) ## S4 method for signature 'GeoMean' name(x) ## S4 method for signature 'GeoMean' dim_from_args(object) ## S4 method for signature 'GeoMean' sign_from_args(object) ## S4 method for signature 'GeoMean' is_atom_convex(object) ## S4 method for signature 'GeoMean' is_atom_concave(object) ## S4 method for signature 'GeoMean' is_atom_log_log_convex(object) ## S4 method for signature 'GeoMean' is_atom_log_log_concave(object) ## S4 method for signature 'GeoMean' is_incr(object, idx) ## S4 method for signature 'GeoMean' is_decr(object, idx) ## S4 method for signature 'GeoMean' get_data(object) ## S4 method for signature 'GeoMean' copy(object, args = NULL, id_objects = list())
x |
An Expression or numeric vector. |
p |
(Optional) A vector of weights for the weighted geometric mean. The default is a vector of ones, giving the unweighted geometric mean |
max_denom |
(Optional) The maximum denominator to use in approximating |
object |
A GeoMean object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
args |
An optional list that contains the arguments to reconstruct the atom. Default is to use current arguments of the atom. |
id_objects |
Currently unused. |
The geometric mean includes an implicit constraint that whenever
. If
will be unconstrained.
The only exception to this rule occurs when
has exactly one nonzero element, say
, in which case
GeoMean(x,p)
is equivalent to (without the nonnegativity constraint).
A specific case of this is when
.
to_numeric(GeoMean)
: The (weighted) geometric mean of the elements of x
.
.domain(GeoMean)
: Returns constraints describing the domain of the node
.grad(GeoMean)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
name(GeoMean)
: The name and arguments of the atom.
dim_from_args(GeoMean)
: The atom is a scalar.
sign_from_args(GeoMean)
: The atom is non-negative.
is_atom_convex(GeoMean)
: The atom is not convex.
is_atom_concave(GeoMean)
: The atom is concave.
is_atom_log_log_convex(GeoMean)
: Is the atom log-log convex?
is_atom_log_log_concave(GeoMean)
: Is the atom log-log concave?
is_incr(GeoMean)
: The atom is weakly increasing in every argument.
is_decr(GeoMean)
: The atom is not weakly decreasing in any argument.
get_data(GeoMean)
: Returns list(w, dyadic completion, tree of dyads)
.
copy(GeoMean)
: Returns a shallow copy of the GeoMean atom
x
An Expression or numeric vector.
p
(Optional) A vector of weights for the weighted geometric mean. The default is a vector of ones, giving the unweighted geometric mean .
max_denom
(Optional) The maximum denominator to use in approximating p/sum(p)
with w
. If w
is not an exact representation, increasing max_denom
may offer a more accurate representation, at the cost of requiring more convex inequalities to represent the geometric mean. Defaults to 1024.
w
(Internal) A list of bigq
objects that represent a rational approximation of p/sum(p)
.
approx_error
(Internal) The error in approximating p/sum(p)
with w
, given by .
Get information needed to reconstruct the expression aside from its arguments.
get_data(object)
get_data(object)
object |
A Expression object. |
A list containing data.
Gets the values of the dual variables.
get_dual_values(result_vec, parse_func, constraints)
get_dual_values(result_vec, parse_func, constraints)
result_vec |
A vector containing the dual variable values. |
parse_func |
Function handle for the parser. |
constraints |
A list of the constraints in the problem. |
A map of constraint ID to dual variable value.
Get the next identifier value.
get_id()
get_id()
A new unique integer identifier.
## Not run: get_id() ## End(Not run)
## Not run: get_id() ## End(Not run)
Get the numpy handle or fail if not available
get_np()
get_np()
the numpy handle
## Not run: get_np ## End(Not run)
## Not run: get_np ## End(Not run)
Get the problem data used in the call to the solver.
get_problem_data(object, solver, gp)
get_problem_data(object, solver, gp)
object |
A Problem object. |
solver |
A string indicating the solver that the problem data is for. Call |
gp |
(Optional) A logical value indicating whether the problem is a geometric program. |
A list containing the data for the solver, the solving chain for the problem, and the inverse data needed to invert the solution.
a <- Variable(name = "a") data <- get_problem_data(Problem(Minimize(exp(a) + 2)), "SCS")[[1]] data[["dims"]] data[["c"]] data[["A"]] x <- Variable(2, name = "x") data <- get_problem_data(Problem(Minimize(p_norm(x) + 3)), "ECOS")[[1]] data[["dims"]] data[["c"]] data[["A"]] data[["G"]]
a <- Variable(name = "a") data <- get_problem_data(Problem(Minimize(exp(a) + 2)), "SCS")[[1]] data[["dims"]] data[["c"]] data[["A"]] x <- Variable(2, name = "x") data <- get_problem_data(Problem(Minimize(p_norm(x) + 3)), "ECOS")[[1]] data[["dims"]] data[["c"]] data[["A"]] data[["G"]]
Get the scipy handle or fail if not available
get_sp()
get_sp()
the scipy handle
## Not run: get_sp ## End(Not run)
## Not run: get_sp ## End(Not run)
An interface for the GLPK MI solver.
GLPK_MI() ## S4 method for signature 'GLPK_MI' mip_capable(solver) ## S4 method for signature 'GLPK_MI' status_map(solver, status) ## S4 method for signature 'GLPK_MI' name(x) ## S4 method for signature 'GLPK_MI' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
GLPK_MI() ## S4 method for signature 'GLPK_MI' mip_capable(solver) ## S4 method for signature 'GLPK_MI' status_map(solver, status) ## S4 method for signature 'GLPK_MI' name(x) ## S4 method for signature 'GLPK_MI' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A GLPK_MI object. |
status |
A status code returned by the solver. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(GLPK_MI)
: Can the solver handle mixed-integer programs?
status_map(GLPK_MI)
: Converts status returned by the GLPK_MI solver to its respective CVXPY status.
name(GLPK_MI)
: Returns the name of the solver.
solve_via_data(GLPK_MI)
: Solve a problem represented by data returned from apply.
An interface for the GLPK solver.
GLPK() ## S4 method for signature 'GLPK' mip_capable(solver) ## S4 method for signature 'GLPK' status_map(solver, status) ## S4 method for signature 'GLPK' name(x) ## S4 method for signature 'GLPK' import_solver(solver) ## S4 method for signature 'GLPK,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'GLPK' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
GLPK() ## S4 method for signature 'GLPK' mip_capable(solver) ## S4 method for signature 'GLPK' status_map(solver, status) ## S4 method for signature 'GLPK' name(x) ## S4 method for signature 'GLPK' import_solver(solver) ## S4 method for signature 'GLPK,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'GLPK' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A GLPK object. |
status |
A status code returned by the solver. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(GLPK)
: Can the solver handle mixed-integer programs?
status_map(GLPK)
: Converts status returned by the GLPK solver to its respective CVXPY status.
name(GLPK)
: Returns the name of the solver.
import_solver(GLPK)
: Imports the solver.
invert(object = GLPK, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(GLPK)
: Solve a problem represented by data returned from apply.
The (sub/super)-gradient of the expression with respect to each variable.
Matrix expressions are vectorized, so the gradient is a matrix. NA
indicates variable values are unknown or outside the domain.
grad(object)
grad(object)
object |
An Expression object. |
A list mapping each variable to a sparse matrix.
x <- Variable(2, name = "x") A <- Variable(2, 2, name = "A") value(x) <- c(-3,4) expr <- p_norm(x, 2) grad(expr) value(A) <- rbind(c(3,-4), c(4,3)) expr <- p_norm(A, 0.5) grad(expr) value(A) <- cbind(c(1,2), c(-1,0)) expr <- abs(A) grad(expr)
x <- Variable(2, name = "x") A <- Variable(2, 2, name = "A") value(x) <- c(-3,4) expr <- p_norm(x, 2) grad(expr) value(A) <- rbind(c(3,-4), c(4,3)) expr <- p_norm(A, 0.5) grad(expr) value(A) <- cbind(c(1,2), c(-1,0)) expr <- abs(A) grad(expr)
Reduces the atom to an affine expression and list of constraints.
graph_implementation(object, arg_objs, dim, data)
graph_implementation(object, arg_objs, dim, data)
object |
An Expression object. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
A list of list(LinOp for objective, list of constraints)
, where LinOp is a list representing the linear operator.
Organize the constraints into a dictionary keyed by constraint names.
group_constraints(constraints)
group_constraints(constraints)
constraints |
a list of constraints. |
A list of constraint types where constr_map[[cone_type]] maps to a list.
An interface for the GUROBI conic solver.
GUROBI_CONIC() ## S4 method for signature 'GUROBI_CONIC' mip_capable(solver) ## S4 method for signature 'GUROBI_CONIC' name(x) ## S4 method for signature 'GUROBI_CONIC' import_solver(solver) ## S4 method for signature 'GUROBI_CONIC' status_map(solver, status) ## S4 method for signature 'GUROBI_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'GUROBI_CONIC,Problem' perform(object, problem) ## S4 method for signature 'GUROBI_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'GUROBI_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
GUROBI_CONIC() ## S4 method for signature 'GUROBI_CONIC' mip_capable(solver) ## S4 method for signature 'GUROBI_CONIC' name(x) ## S4 method for signature 'GUROBI_CONIC' import_solver(solver) ## S4 method for signature 'GUROBI_CONIC' status_map(solver, status) ## S4 method for signature 'GUROBI_CONIC,Problem' accepts(object, problem) ## S4 method for signature 'GUROBI_CONIC,Problem' perform(object, problem) ## S4 method for signature 'GUROBI_CONIC,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'GUROBI_CONIC' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A GUROBI_CONIC object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(GUROBI_CONIC)
: Can the solver handle mixed-integer programs?
name(GUROBI_CONIC)
: Returns the name of the solver.
import_solver(GUROBI_CONIC)
: Imports the solver.
status_map(GUROBI_CONIC)
: Converts status returned by the GUROBI solver to its respective CVXPY status.
accepts(object = GUROBI_CONIC, problem = Problem)
: Can GUROBI_CONIC solve the problem?
perform(object = GUROBI_CONIC, problem = Problem)
: Returns a new problem and data for inverting the new solution.
invert(object = GUROBI_CONIC, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(GUROBI_CONIC)
: Solve a problem represented by data returned from apply.
An interface for the GUROBI_QP solver.
GUROBI_QP() ## S4 method for signature 'GUROBI_QP' mip_capable(solver) ## S4 method for signature 'GUROBI_QP' status_map(solver, status) ## S4 method for signature 'GUROBI_QP' name(x) ## S4 method for signature 'GUROBI_QP' import_solver(solver) ## S4 method for signature 'GUROBI_QP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'GUROBI_QP,list,InverseData' invert(object, solution, inverse_data)
GUROBI_QP() ## S4 method for signature 'GUROBI_QP' mip_capable(solver) ## S4 method for signature 'GUROBI_QP' status_map(solver, status) ## S4 method for signature 'GUROBI_QP' name(x) ## S4 method for signature 'GUROBI_QP' import_solver(solver) ## S4 method for signature 'GUROBI_QP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'GUROBI_QP,list,InverseData' invert(object, solution, inverse_data)
solver , object , x
|
A GUROBI_QP object. |
status |
A status code returned by the solver. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
solution |
The raw solution returned by the solver. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
mip_capable(GUROBI_QP)
: Can the solver handle mixed-integer programs?
status_map(GUROBI_QP)
: Converts status returned by the GUROBI solver to its respective CVXPY status.
name(GUROBI_QP)
: Returns the name of the solver.
import_solver(GUROBI_QP)
: Imports the solver.
solve_via_data(GUROBI_QP)
: Solve a problem represented by data returned from apply.
invert(object = GUROBI_QP, solution = list, inverse_data = InverseData)
: Returns the solution to the original problem given the inverse_data.
The harmonic mean, . For a matrix, the function is applied over all entries.
harmonic_mean(x)
harmonic_mean(x)
x |
An Expression, vector, or matrix. |
An Expression representing the harmonic mean of the input.
x <- Variable() prob <- Problem(Maximize(harmonic_mean(x)), list(x >= 0, x <= 5)) result <- solve(prob) result$value result$getValue(x)
x <- Variable() prob <- Problem(Maximize(harmonic_mean(x)), list(x >= 0, x <= 5)) result <- solve(prob) result$value result$getValue(x)
The harmonic mean of x, , where n is the length of x.
HarmonicMean(x)
HarmonicMean(x)
x |
An expression or number whose harmonic mean is to be computed. Must have positive entries. |
The harmonic mean of x
.
The horizontal concatenation of expressions.
This is equivalent to cbind
when applied to objects with the same number of rows.
hstack(...)
hstack(...)
... |
Expression objects, vectors, or matrices. All arguments must have the same number of rows. |
An Expression representing the concatenated inputs.
x <- Variable(2) y <- Variable(3) c <- matrix(1, nrow = 1, ncol = 5) prob <- Problem(Minimize(c %*% t(hstack(t(x), t(y)))), list(x == c(1,2), y == c(3,4,5))) result <- solve(prob) result$value c <- matrix(1, nrow = 1, ncol = 4) prob <- Problem(Minimize(c %*% t(hstack(t(x), t(x)))), list(x == c(1,2))) result <- solve(prob) result$value A <- Variable(2,2) C <- Variable(3,2) c <- matrix(1, nrow = 2, ncol = 2) prob <- Problem(Minimize(sum_entries(hstack(t(A), t(C)))), list(A >= 2*c, C == -2)) result <- solve(prob) result$value result$getValue(A) D <- Variable(3,3) expr <- hstack(C, D) obj <- expr[1,2] + sum(hstack(expr, expr)) constr <- list(C >= 0, D >= 0, D[1,1] == 2, C[1,2] == 3) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value result$getValue(C) result$getValue(D)
x <- Variable(2) y <- Variable(3) c <- matrix(1, nrow = 1, ncol = 5) prob <- Problem(Minimize(c %*% t(hstack(t(x), t(y)))), list(x == c(1,2), y == c(3,4,5))) result <- solve(prob) result$value c <- matrix(1, nrow = 1, ncol = 4) prob <- Problem(Minimize(c %*% t(hstack(t(x), t(x)))), list(x == c(1,2))) result <- solve(prob) result$value A <- Variable(2,2) C <- Variable(3,2) c <- matrix(1, nrow = 2, ncol = 2) prob <- Problem(Minimize(sum_entries(hstack(t(A), t(C)))), list(A >= 2*c, C == -2)) result <- solve(prob) result$value result$getValue(A) D <- Variable(3,3) expr <- hstack(C, D) obj <- expr[1,2] + sum(hstack(expr, expr)) constr <- list(C >= 0, D >= 0, D[1,1] == 2, C[1,2] == 3) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value result$getValue(C) result$getValue(D)
Horizontal concatenation of values.
HStack(...) ## S4 method for signature 'HStack' to_numeric(object, values) ## S4 method for signature 'HStack' dim_from_args(object) ## S4 method for signature 'HStack' is_atom_log_log_convex(object) ## S4 method for signature 'HStack' is_atom_log_log_concave(object) ## S4 method for signature 'HStack' validate_args(object) ## S4 method for signature 'HStack' graph_implementation(object, arg_objs, dim, data = NA_real_)
HStack(...) ## S4 method for signature 'HStack' to_numeric(object, values) ## S4 method for signature 'HStack' dim_from_args(object) ## S4 method for signature 'HStack' is_atom_log_log_convex(object) ## S4 method for signature 'HStack' is_atom_log_log_concave(object) ## S4 method for signature 'HStack' validate_args(object) ## S4 method for signature 'HStack' graph_implementation(object, arg_objs, dim, data = NA_real_)
... |
Expression objects or matrices. All arguments must have the same dimensions except for axis 2 (columns). |
object |
A HStack object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(HStack)
: Horizontally concatenate the values using cbind
.
dim_from_args(HStack)
: The dimensions of the atom.
is_atom_log_log_convex(HStack)
: Is the atom log-log convex?
is_atom_log_log_concave(HStack)
: Is the atom log-log concave?
validate_args(HStack)
: Check all arguments have the same height.
graph_implementation(HStack)
: The graph implementation of the atom.
...
Expression objects or matrices. All arguments must have the same dimensions except for axis 2 (columns).
The elementwise Huber function,
for
for
huber(x, M = 1)
huber(x, M = 1)
x |
An Expression, vector, or matrix. |
M |
(Optional) A positive scalar value representing the threshold. Defaults to 1. |
An Expression representing the Huber function evaluated at the input.
set.seed(11) n <- 10 m <- 450 p <- 0.1 # Fraction of responses with sign flipped # Generate problem data beta_true <- 5*matrix(stats::rnorm(n), nrow = n) X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) y_true <- X %*% beta_true eps <- matrix(stats::rnorm(m), nrow = m) # Randomly flip sign of some responses factor <- 2*rbinom(m, size = 1, prob = 1-p) - 1 y <- factor * y_true + eps # Huber regression beta <- Variable(n) obj <- sum(huber(y - X %*% beta, 1)) prob <- Problem(Minimize(obj)) result <- solve(prob) result$getValue(beta)
set.seed(11) n <- 10 m <- 450 p <- 0.1 # Fraction of responses with sign flipped # Generate problem data beta_true <- 5*matrix(stats::rnorm(n), nrow = n) X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) y_true <- X %*% beta_true eps <- matrix(stats::rnorm(m), nrow = m) # Randomly flip sign of some responses factor <- 2*rbinom(m, size = 1, prob = 1-p) - 1 y <- factor * y_true + eps # Huber regression beta <- Variable(n) obj <- sum(huber(y - X %*% beta, 1)) prob <- Problem(Minimize(obj)) result <- solve(prob) result$getValue(beta)
This class represents the elementwise Huber function,
for
for
Huber(x, M = 1) ## S4 method for signature 'Huber' to_numeric(object, values) ## S4 method for signature 'Huber' sign_from_args(object) ## S4 method for signature 'Huber' is_atom_convex(object) ## S4 method for signature 'Huber' is_atom_concave(object) ## S4 method for signature 'Huber' is_incr(object, idx) ## S4 method for signature 'Huber' is_decr(object, idx) ## S4 method for signature 'Huber' is_quadratic(object) ## S4 method for signature 'Huber' get_data(object) ## S4 method for signature 'Huber' validate_args(object) ## S4 method for signature 'Huber' .grad(object, values)
Huber(x, M = 1) ## S4 method for signature 'Huber' to_numeric(object, values) ## S4 method for signature 'Huber' sign_from_args(object) ## S4 method for signature 'Huber' is_atom_convex(object) ## S4 method for signature 'Huber' is_atom_concave(object) ## S4 method for signature 'Huber' is_incr(object, idx) ## S4 method for signature 'Huber' is_decr(object, idx) ## S4 method for signature 'Huber' is_quadratic(object) ## S4 method for signature 'Huber' get_data(object) ## S4 method for signature 'Huber' validate_args(object) ## S4 method for signature 'Huber' .grad(object, values)
x |
An Expression object. |
M |
A positive scalar value representing the threshold. Defaults to 1. |
object |
A Huber object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(Huber)
: The Huber function evaluted elementwise on the input value.
sign_from_args(Huber)
: The atom is positive.
is_atom_convex(Huber)
: The atom is convex.
is_atom_concave(Huber)
: The atom is not concave.
is_incr(Huber)
: A logical value indicating whether the atom is weakly increasing.
is_decr(Huber)
: A logical value indicating whether the atom is weakly decreasing.
is_quadratic(Huber)
: The atom is quadratic if x
is affine.
get_data(Huber)
: A list containing the parameter M
.
validate_args(Huber)
: Check that M
is a non-negative constant.
.grad(Huber)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric constant.
M
A positive scalar value representing the threshold. Defaults to 1.
A unique identification number used internally to keep track of variables and constraints. Should not be modified by the user.
id(object)
id(object)
object |
A Variable or Constraint object. |
A non-negative integer identifier.
x <- Variable() constr <- (x >= 5) id(x) id(constr)
x <- Variable() constr <- (x >= 5) id(x) id(constr)
This class represents the imaginary part of an expression.
Imag(expr) ## S4 method for signature 'Imag' to_numeric(object, values) ## S4 method for signature 'Imag' dim_from_args(object) ## S4 method for signature 'Imag' is_imag(object) ## S4 method for signature 'Imag' is_complex(object) ## S4 method for signature 'Imag' is_symmetric(object)
Imag(expr) ## S4 method for signature 'Imag' to_numeric(object, values) ## S4 method for signature 'Imag' dim_from_args(object) ## S4 method for signature 'Imag' is_imag(object) ## S4 method for signature 'Imag' is_complex(object) ## S4 method for signature 'Imag' is_symmetric(object)
expr |
An Expression representing a vector or matrix. |
object |
An Imag object. |
values |
A list of arguments to the atom. |
to_numeric(Imag)
: The imaginary part of the given value.
dim_from_args(Imag)
: The dimensions of the atom.
is_imag(Imag)
: Is the atom imaginary?
is_complex(Imag)
: Is the atom complex valued?
is_symmetric(Imag)
: Is the atom symmetric?
expr
An Expression representing a vector or matrix.
Import the R library that interfaces with the specified solver.
import_solver(solver)
import_solver(solver)
solver |
A ReductionSolver object. |
import_solver(ECOS()) import_solver(SCS())
import_solver(ECOS()) import_solver(SCS())
List available solvers, taking currently blacklisted solvers into account.
installed_solvers() add_to_solver_blacklist(solvers) remove_from_solver_blacklist(solvers) set_solver_blacklist(solvers)
installed_solvers() add_to_solver_blacklist(solvers) remove_from_solver_blacklist(solvers) set_solver_blacklist(solvers)
solvers |
a character vector of solver names, default |
The names of all the installed solvers as a character vector.
The current blacklist (character vector), invisibly.
add_to_solver_blacklist()
: Add to solver blacklist, useful for temporarily disabling a solver
remove_from_solver_blacklist()
: Remove solvers from blacklist
set_solver_blacklist()
: Set solver blacklist to a value
The elementwise reciprocal function,
inv_pos(x)
inv_pos(x)
x |
An Expression, vector, or matrix. |
An Expression representing the reciprocal of the input.
A <- Variable(2,2) val <- cbind(c(1,2), c(3,4)) prob <- Problem(Minimize(inv_pos(A)[1,2]), list(A == val)) result <- solve(prob) result$value
A <- Variable(2,2) val <- cbind(c(1,2), c(3,4)) prob <- Problem(Minimize(inv_pos(A)[1,2]), list(A == val)) result <- solve(prob) result$value
Returns a solution to the original problem given the inverse data.
invert(object, solution, inverse_data)
invert(object, solution, inverse_data)
object |
A Reduction object. |
solution |
A Solution to a problem that generated |
inverse_data |
A InverseData object encoding the original problem. |
A Solution to the original problem.
Determine if a problem or expression complies with the disciplined convex programming rules.
is_dcp(object)
is_dcp(object)
object |
A Problem or Expression object. |
A logical value indicating whether the problem or expression is DCP compliant, i.e. no unknown curvatures.
x <- Variable() prob <- Problem(Minimize(x^2), list(x >= 5)) is_dcp(prob) solve(prob)
x <- Variable() prob <- Problem(Minimize(x^2), list(x >= 5)) is_dcp(prob) solve(prob)
Determine if a problem or expression complies with the disciplined geometric programming rules.
is_dgp(object)
is_dgp(object)
object |
A Problem or Expression object. |
A logical value indicating whether the problem or expression is DCP compliant, i.e. no unknown curvatures.
x <- Variable(pos = TRUE) y <- Variable(pos = TRUE) prob <- Problem(Minimize(x*y), list(x >= 5, y >= 5)) is_dgp(prob) solve(prob, gp = TRUE)
x <- Variable(pos = TRUE) y <- Variable(pos = TRUE) prob <- Problem(Minimize(x*y), list(x >= 5, y >= 5)) is_dgp(prob) solve(prob, gp = TRUE)
Determine if a problem is a mixed-integer program.
is_mixed_integer(object)
is_mixed_integer(object)
object |
A Problem object. |
A logical value indicating whether the problem is a mixed-integer program
Determine if a problem is a quadratic program.
is_qp(object)
is_qp(object)
object |
A Problem object. |
A logical value indicating whether the problem is a quadratic program.
Is the constraint a stuffed cone constraint?
is_stuffed_cone_constraint(constraint)
is_stuffed_cone_constraint(constraint)
constraint |
A Constraint object. |
Is the constraint a stuffed-cone constraint?
Is the objective a stuffed cone objective?
is_stuffed_cone_objective(objective)
is_stuffed_cone_objective(objective)
objective |
An Objective object. |
Is the objective a stuffed-cone objective?
Is the QP objective stuffed?
is_stuffed_qp_objective(objective)
is_stuffed_qp_objective(objective)
objective |
A Minimize or Maximize object representing the optimization objective. |
Is the objective a stuffed QP?
The elementwise Kullback-Leibler divergence, .
kl_div(x, y)
kl_div(x, y)
x |
An Expression, vector, or matrix. |
y |
An Expression, vector, or matrix. |
An Expression representing the KL-divergence of the input.
n <- 5 alpha <- seq(10, n-1+10)/n beta <- seq(10, n-1+10)/n P_tot <- 0.5 W_tot <- 1.0 P <- Variable(n) W <- Variable(n) R <- kl_div(alpha*W, alpha*(W + beta*P)) - alpha*beta*P obj <- sum(R) constr <- list(P >= 0, W >= 0, sum(P) == P_tot, sum(W) == W_tot) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value result$getValue(P) result$getValue(W)
n <- 5 alpha <- seq(10, n-1+10)/n beta <- seq(10, n-1+10)/n P_tot <- 0.5 W_tot <- 1.0 P <- Variable(n) W <- Variable(n) R <- kl_div(alpha*W, alpha*(W + beta*P)) - alpha*beta*P obj <- sum(R) constr <- list(P >= 0, W >= 0, sum(P) == P_tot, sum(W) == W_tot) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value result$getValue(P) result$getValue(W)
The elementwise KL-divergence .
KLDiv(x, y) ## S4 method for signature 'KLDiv' to_numeric(object, values) ## S4 method for signature 'KLDiv' sign_from_args(object) ## S4 method for signature 'KLDiv' is_atom_convex(object) ## S4 method for signature 'KLDiv' is_atom_concave(object) ## S4 method for signature 'KLDiv' is_incr(object, idx) ## S4 method for signature 'KLDiv' is_decr(object, idx) ## S4 method for signature 'KLDiv' .grad(object, values) ## S4 method for signature 'KLDiv' .domain(object)
KLDiv(x, y) ## S4 method for signature 'KLDiv' to_numeric(object, values) ## S4 method for signature 'KLDiv' sign_from_args(object) ## S4 method for signature 'KLDiv' is_atom_convex(object) ## S4 method for signature 'KLDiv' is_atom_concave(object) ## S4 method for signature 'KLDiv' is_incr(object, idx) ## S4 method for signature 'KLDiv' is_decr(object, idx) ## S4 method for signature 'KLDiv' .grad(object, values) ## S4 method for signature 'KLDiv' .domain(object)
x |
An Expression or numeric constant. |
y |
An Expression or numeric constant. |
object |
A KLDiv object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(KLDiv)
: The KL-divergence evaluted elementwise on the input value.
sign_from_args(KLDiv)
: The atom is positive.
is_atom_convex(KLDiv)
: The atom is convex.
is_atom_concave(KLDiv)
: The atom is not concave.
is_incr(KLDiv)
: The atom is not monotonic in any argument.
is_decr(KLDiv)
: The atom is not monotonic in any argument.
.grad(KLDiv)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(KLDiv)
: Returns constraints describng the domain of the node
x
An Expression or numeric constant.
y
An Expression or numeric constant.
This class represents the kronecker product.
Kron(lh_exp, rh_exp) ## S4 method for signature 'Kron' to_numeric(object, values) ## S4 method for signature 'Kron' validate_args(object) ## S4 method for signature 'Kron' dim_from_args(object) ## S4 method for signature 'Kron' sign_from_args(object) ## S4 method for signature 'Kron' is_incr(object, idx) ## S4 method for signature 'Kron' is_decr(object, idx) ## S4 method for signature 'Kron' graph_implementation(object, arg_objs, dim, data = NA_real_)
Kron(lh_exp, rh_exp) ## S4 method for signature 'Kron' to_numeric(object, values) ## S4 method for signature 'Kron' validate_args(object) ## S4 method for signature 'Kron' dim_from_args(object) ## S4 method for signature 'Kron' sign_from_args(object) ## S4 method for signature 'Kron' is_incr(object, idx) ## S4 method for signature 'Kron' is_decr(object, idx) ## S4 method for signature 'Kron' graph_implementation(object, arg_objs, dim, data = NA_real_)
lh_exp |
An Expression or numeric constant representing the left-hand matrix. |
rh_exp |
An Expression or numeric constant representing the right-hand matrix. |
object |
A Kron object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector with two elements representing the size of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Kron)
: The kronecker product of the two values.
validate_args(Kron)
: Check both arguments are vectors and the first is a constant.
dim_from_args(Kron)
: The dimensions of the atom.
sign_from_args(Kron)
: The sign of the atom.
is_incr(Kron)
: Is the left-hand expression positive?
is_decr(Kron)
: Is the right-hand expression negative?
graph_implementation(Kron)
: The graph implementation of the atom.
lh_exp
An Expression or numeric constant representing the left-hand matrix.
rh_exp
An Expression or numeric constant representing the right-hand matrix.
The generalized kronecker product of two matrices.
## S4 method for signature 'Expression,ANY' kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...) ## S4 method for signature 'ANY,Expression' kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...)
## S4 method for signature 'Expression,ANY' kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...) ## S4 method for signature 'ANY,Expression' kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...)
X |
An Expression or matrix. |
Y |
An Expression or matrix. |
FUN |
Hardwired to "*" for the kronecker product. |
make.dimnames |
(Unimplemented) Dimension names are not supported in Expression objects. |
... |
(Unimplemented) Optional arguments. |
An Expression that represents the kronecker product.
X <- cbind(c(1,2), c(3,4)) Y <- Variable(2,2) val <- cbind(c(5,6), c(7,8)) obj <- X %x% Y prob <- Problem(Minimize(kronecker(X,Y)[1,1]), list(Y == val)) result <- solve(prob) result$value result$getValue(kronecker(X,Y))
X <- cbind(c(1,2), c(3,4)) Y <- Variable(2,2) val <- cbind(c(5,6), c(7,8)) obj <- X %x% Y prob <- Problem(Minimize(kronecker(X,Y)[1,1]), list(Y == val)) result <- solve(prob) result$value result$getValue(kronecker(X,Y))
The maximum eigenvalue of a matrix, .
lambda_max(A)
lambda_max(A)
A |
An Expression or matrix. |
An Expression representing the maximum eigenvalue of the input.
A <- Variable(2,2) prob <- Problem(Minimize(lambda_max(A)), list(A >= 2)) result <- solve(prob) result$value result$getValue(A) obj <- Maximize(A[2,1] - A[1,2]) prob <- Problem(obj, list(lambda_max(A) <= 100, A[1,1] == 2, A[2,2] == 2, A[2,1] == 2)) result <- solve(prob) result$value result$getValue(A)
A <- Variable(2,2) prob <- Problem(Minimize(lambda_max(A)), list(A >= 2)) result <- solve(prob) result$value result$getValue(A) obj <- Maximize(A[2,1] - A[1,2]) prob <- Problem(obj, list(lambda_max(A) <= 100, A[1,1] == 2, A[2,2] == 2, A[2,1] == 2)) result <- solve(prob) result$value result$getValue(A)
The minimum eigenvalue of a matrix, .
lambda_min(A)
lambda_min(A)
A |
An Expression or matrix. |
An Expression representing the minimum eigenvalue of the input.
A <- Variable(2,2) val <- cbind(c(5,7), c(7,-3)) prob <- Problem(Maximize(lambda_min(A)), list(A == val)) result <- solve(prob) result$value result$getValue(A)
A <- Variable(2,2) val <- cbind(c(5,7), c(7,-3)) prob <- Problem(Maximize(lambda_min(A)), list(A == val)) result <- solve(prob) result$value result$getValue(A)
The sum of the largest eigenvalues of a matrix.
lambda_sum_largest(A, k)
lambda_sum_largest(A, k)
A |
An Expression or matrix. |
k |
The number of eigenvalues to sum over. |
An Expression representing the sum of the largest k
eigenvalues of the input.
C <- Variable(3,3) val <- cbind(c(1,2,3), c(2,4,5), c(3,5,6)) prob <- Problem(Minimize(lambda_sum_largest(C,2)), list(C == val)) result <- solve(prob) result$value result$getValue(C)
C <- Variable(3,3) val <- cbind(c(1,2,3), c(2,4,5), c(3,5,6)) prob <- Problem(Minimize(lambda_sum_largest(C,2)), list(C == val)) result <- solve(prob) result$value result$getValue(C)
The sum of the smallest eigenvalues of a matrix.
lambda_sum_smallest(A, k)
lambda_sum_smallest(A, k)
A |
An Expression or matrix. |
k |
The number of eigenvalues to sum over. |
An Expression representing the sum of the smallest k
eigenvalues of the input.
C <- Variable(3,3) val <- cbind(c(1,2,3), c(2,4,5), c(3,5,6)) prob <- Problem(Maximize(lambda_sum_smallest(C,2)), list(C == val)) result <- solve(prob) result$value result$getValue(C)
C <- Variable(3,3) val <- cbind(c(1,2,3), c(2,4,5), c(3,5,6)) prob <- Problem(Maximize(lambda_sum_smallest(C,2)), list(C == val)) result <- solve(prob) result$value result$getValue(C)
The maximum eigenvalue of a matrix, .
LambdaMax(A) ## S4 method for signature 'LambdaMax' to_numeric(object, values) ## S4 method for signature 'LambdaMax' .domain(object) ## S4 method for signature 'LambdaMax' .grad(object, values) ## S4 method for signature 'LambdaMax' validate_args(object) ## S4 method for signature 'LambdaMax' dim_from_args(object) ## S4 method for signature 'LambdaMax' sign_from_args(object) ## S4 method for signature 'LambdaMax' is_atom_convex(object) ## S4 method for signature 'LambdaMax' is_atom_concave(object) ## S4 method for signature 'LambdaMax' is_incr(object, idx) ## S4 method for signature 'LambdaMax' is_decr(object, idx)
LambdaMax(A) ## S4 method for signature 'LambdaMax' to_numeric(object, values) ## S4 method for signature 'LambdaMax' .domain(object) ## S4 method for signature 'LambdaMax' .grad(object, values) ## S4 method for signature 'LambdaMax' validate_args(object) ## S4 method for signature 'LambdaMax' dim_from_args(object) ## S4 method for signature 'LambdaMax' sign_from_args(object) ## S4 method for signature 'LambdaMax' is_atom_convex(object) ## S4 method for signature 'LambdaMax' is_atom_concave(object) ## S4 method for signature 'LambdaMax' is_incr(object, idx) ## S4 method for signature 'LambdaMax' is_decr(object, idx)
A |
An Expression or numeric matrix. |
object |
A LambdaMax object. |
values |
A list of arguments to the atom. |
idx |
An index into the atom. |
to_numeric(LambdaMax)
: The largest eigenvalue of A
. Requires that A
be symmetric.
.domain(LambdaMax)
: Returns the constraints describing the domain of the atom.
.grad(LambdaMax)
: Gives the (sub/super)gradient of the atom with respect to each argument. Matrix expressions are vectorized, so the gradient is a matrix.
validate_args(LambdaMax)
: Check that A
is square.
dim_from_args(LambdaMax)
: The atom is a scalar.
sign_from_args(LambdaMax)
: The sign of the atom is unknown.
is_atom_convex(LambdaMax)
: The atom is convex.
is_atom_concave(LambdaMax)
: The atom is not concave.
is_incr(LambdaMax)
: The atom is not monotonic in any argument.
is_decr(LambdaMax)
: The atom is not monotonic in any argument.
A
An Expression or numeric matrix.
The minimum eigenvalue of a matrix, .
LambdaMin(A)
LambdaMin(A)
A |
An Expression or numeric matrix. |
Returns the minimum eigenvalue of a matrix.
This class represents the sum of the k
largest eigenvalues of a matrix.
LambdaSumLargest(A, k) ## S4 method for signature 'LambdaSumLargest' allow_complex(object) ## S4 method for signature 'LambdaSumLargest' to_numeric(object, values) ## S4 method for signature 'LambdaSumLargest' validate_args(object) ## S4 method for signature 'LambdaSumLargest' get_data(object) ## S4 method for signature 'LambdaSumLargest' .grad(object, values)
LambdaSumLargest(A, k) ## S4 method for signature 'LambdaSumLargest' allow_complex(object) ## S4 method for signature 'LambdaSumLargest' to_numeric(object, values) ## S4 method for signature 'LambdaSumLargest' validate_args(object) ## S4 method for signature 'LambdaSumLargest' get_data(object) ## S4 method for signature 'LambdaSumLargest' .grad(object, values)
A |
An Expression or numeric matrix. |
k |
A positive integer. |
object |
A LambdaSumLargest object. |
values |
A list of numeric values for the arguments |
allow_complex(LambdaSumLargest)
: Does the atom handle complex numbers?
to_numeric(LambdaSumLargest)
: Returns the largest eigenvalue of A
, which must be symmetric.
validate_args(LambdaSumLargest)
: Verify that the argument A
is square.
get_data(LambdaSumLargest)
: Returns the parameter k
.
.grad(LambdaSumLargest)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
k
A positive integer.
This class represents the sum of the k
smallest eigenvalues of a matrix.
LambdaSumSmallest(A, k)
LambdaSumSmallest(A, k)
A |
An Expression or numeric matrix. |
k |
A positive integer. |
Returns the sum of the k smallest eigenvalues of a matrix.
Determine if an expression is positive or negative.
is_pos(object) is_neg(object)
is_pos(object) is_neg(object)
object |
A Leaf object. |
A logical value.
This class represents a leaf node, i.e. a Variable, Constant, or Parameter.
## S4 method for signature 'Leaf' get_data(object) ## S4 method for signature 'Leaf' dim(x) ## S4 method for signature 'Leaf' variables(object) ## S4 method for signature 'Leaf' parameters(object) ## S4 method for signature 'Leaf' constants(object) ## S4 method for signature 'Leaf' atoms(object) ## S4 method for signature 'Leaf' is_convex(object) ## S4 method for signature 'Leaf' is_concave(object) ## S4 method for signature 'Leaf' is_log_log_convex(object) ## S4 method for signature 'Leaf' is_log_log_concave(object) ## S4 method for signature 'Leaf' is_nonneg(object) ## S4 method for signature 'Leaf' is_nonpos(object) ## S4 method for signature 'Leaf' is_pos(object) ## S4 method for signature 'Leaf' is_neg(object) ## S4 method for signature 'Leaf' is_hermitian(object) ## S4 method for signature 'Leaf' is_symmetric(object) ## S4 method for signature 'Leaf' is_imag(object) ## S4 method for signature 'Leaf' is_complex(object) ## S4 method for signature 'Leaf' domain(object) ## S4 method for signature 'Leaf' project(object, value) ## S4 method for signature 'Leaf' project_and_assign(object, value) ## S4 method for signature 'Leaf' value(object) ## S4 replacement method for signature 'Leaf' value(object) <- value ## S4 method for signature 'Leaf' validate_val(object, val) ## S4 method for signature 'Leaf' is_psd(object) ## S4 method for signature 'Leaf' is_nsd(object) ## S4 method for signature 'Leaf' is_quadratic(object) ## S4 method for signature 'Leaf' is_pwl(object)
## S4 method for signature 'Leaf' get_data(object) ## S4 method for signature 'Leaf' dim(x) ## S4 method for signature 'Leaf' variables(object) ## S4 method for signature 'Leaf' parameters(object) ## S4 method for signature 'Leaf' constants(object) ## S4 method for signature 'Leaf' atoms(object) ## S4 method for signature 'Leaf' is_convex(object) ## S4 method for signature 'Leaf' is_concave(object) ## S4 method for signature 'Leaf' is_log_log_convex(object) ## S4 method for signature 'Leaf' is_log_log_concave(object) ## S4 method for signature 'Leaf' is_nonneg(object) ## S4 method for signature 'Leaf' is_nonpos(object) ## S4 method for signature 'Leaf' is_pos(object) ## S4 method for signature 'Leaf' is_neg(object) ## S4 method for signature 'Leaf' is_hermitian(object) ## S4 method for signature 'Leaf' is_symmetric(object) ## S4 method for signature 'Leaf' is_imag(object) ## S4 method for signature 'Leaf' is_complex(object) ## S4 method for signature 'Leaf' domain(object) ## S4 method for signature 'Leaf' project(object, value) ## S4 method for signature 'Leaf' project_and_assign(object, value) ## S4 method for signature 'Leaf' value(object) ## S4 replacement method for signature 'Leaf' value(object) <- value ## S4 method for signature 'Leaf' validate_val(object, val) ## S4 method for signature 'Leaf' is_psd(object) ## S4 method for signature 'Leaf' is_nsd(object) ## S4 method for signature 'Leaf' is_quadratic(object) ## S4 method for signature 'Leaf' is_pwl(object)
object , x
|
A Leaf object. |
value |
A numeric scalar, vector, or matrix. |
val |
The assigned value. |
get_data(Leaf)
: Leaves are not copied.
dim(Leaf)
: The dimensions of the leaf node.
variables(Leaf)
: List of Variable objects in the leaf node.
parameters(Leaf)
: List of Parameter objects in the leaf node.
constants(Leaf)
: List of Constant objects in the leaf node.
atoms(Leaf)
: List of Atom objects in the leaf node.
is_convex(Leaf)
: A logical value indicating whether the leaf node is convex.
is_concave(Leaf)
: A logical value indicating whether the leaf node is concave.
is_log_log_convex(Leaf)
: Is the expression log-log convex?
is_log_log_concave(Leaf)
: Is the expression log-log concave?
is_nonneg(Leaf)
: A logical value indicating whether the leaf node is nonnegative.
is_nonpos(Leaf)
: A logical value indicating whether the leaf node is nonpositive.
is_pos(Leaf)
: Is the expression positive?
is_neg(Leaf)
: Is the expression negative?
is_hermitian(Leaf)
: A logical value indicating whether the leaf node is hermitian.
is_symmetric(Leaf)
: A logical value indicating whether the leaf node is symmetric.
is_imag(Leaf)
: A logical value indicating whether the leaf node is imaginary.
is_complex(Leaf)
: A logical value indicating whether the leaf node is complex.
domain(Leaf)
: A list of constraints describing the closure of the region where the leaf node is finite. Default is the full domain.
project(Leaf)
: Project value onto the attribute set of the leaf.
project_and_assign(Leaf)
: Project and assign a value to the leaf.
value(Leaf)
: Get the value of the leaf.
value(Leaf) <- value
: Set the value of the leaf.
validate_val(Leaf)
: Check that val
satisfies symbolic attributes of leaf.
is_psd(Leaf)
: A logical value indicating whether the leaf node is a positive semidefinite matrix.
is_nsd(Leaf)
: A logical value indicating whether the leaf node is a negative semidefinite matrix.
is_quadratic(Leaf)
: Leaf nodes are always quadratic.
is_pwl(Leaf)
: Leaf nodes are always piecewise linear.
id
(Internal) A unique integer identification number used internally.
dim
The dimensions of the leaf.
value
The numeric value of the leaf.
nonneg
Is the leaf nonnegative?
nonpos
Is the leaf nonpositive?
complex
Is the leaf a complex number?
imag
Is the leaf imaginary?
symmetric
Is the leaf a symmetric matrix?
diag
Is the leaf a diagonal matrix?
PSD
Is the leaf positive semidefinite?
NSD
Is the leaf negative semidefinite?
hermitian
Is the leaf hermitian?
boolean
Is the leaf boolean? Is the variable boolean? May be TRUE
= entire leaf is boolean, FALSE
= entire leaf is not boolean, or a vector of
indices which should be constrained as boolean, where each index is a vector of length exactly equal to the length of dim
.
integer
Is the leaf integer? The semantics are the same as the boolean
argument.
sparsity
A matrix representing the fixed sparsity pattern of the leaf.
pos
Is the leaf strictly positive?
neg
Is the leaf strictly negative?
Gives an elementwise lower (upper) bound for convex (concave) expressions that is tight at the current variable/parameter values. No guarantees for non-DCP expressions.
linearize(expr)
linearize(expr)
expr |
An Expression to linearize. |
If f and g are convex, the objective f-g can be (heuristically) minimized using the implementation below of the convex-concave method:
for(iters in 1:N)
solve(Problem(Minimize(f - linearize(g))))
An affine expression or NA
if cannot be linearized.
A Class Union of List and Constraint
## S4 method for signature 'ListORConstr' id(object)
## S4 method for signature 'ListORConstr' id(object)
object |
A list or Constraint object. |
id(ListORConstr)
: Returns the ID associated with the list or constraint.
The natural logarithm of the determinant of a matrix, .
log_det(A)
log_det(A)
A |
An Expression or matrix. |
An Expression representing the log-determinant of the input.
x <- t(data.frame(c(0.55, 0.25, -0.2, -0.25, -0.0, 0.4), c(0.0, 0.35, 0.2, -0.1, -0.3, -0.2))) n <- nrow(x) m <- ncol(x) A <- Variable(n,n) b <- Variable(n) obj <- Maximize(log_det(A)) constr <- lapply(1:m, function(i) { p_norm(A %*% as.matrix(x[,i]) + b) <= 1 }) prob <- Problem(obj, constr) result <- solve(prob) result$value
x <- t(data.frame(c(0.55, 0.25, -0.2, -0.25, -0.0, 0.4), c(0.0, 0.35, 0.2, -0.1, -0.3, -0.2))) n <- nrow(x) m <- ncol(x) A <- Variable(n,n) b <- Variable(n) obj <- Maximize(log_det(A)) constr <- lapply(1:m, function(i) { p_norm(A %*% as.matrix(x[,i]) + b) <= 1 }) prob <- Problem(obj, constr) result <- solve(prob) result$value
The log-log curvature of an expression.
The log-log curvature of an expression.
log_log_curvature(object) ## S4 method for signature 'Expression' log_log_curvature(object)
log_log_curvature(object) ## S4 method for signature 'Expression' log_log_curvature(object)
object |
An Expression object. |
A string indicating the log-log curvature of the expression, either "LOG_LOG_CONSTANT", "LOG_LOG_AFFINE", "LOG_LOG_CONVEX, "LOG_LOG_CONCAVE", or "UNKNOWN".
A string indicating the log-log curvature of the expression, either "LOG_LOG_CONSTANT", "LOG_LOG_AFFINE", "LOG_LOG_CONVEX", "LOG_LOG_CONCAVE", or "UNKNOWN".
Determine if an atom is log-log convex, concave, or affine.
is_atom_log_log_convex(object) is_atom_log_log_concave(object) is_atom_log_log_affine(object)
is_atom_log_log_convex(object) is_atom_log_log_concave(object) is_atom_log_log_affine(object)
object |
A Atom object. |
A logical value.
Determine if an expression is log-log constant, log-log affine, log-log convex, or log-log concave.
is_log_log_constant(object) is_log_log_affine(object) is_log_log_convex(object) is_log_log_concave(object)
is_log_log_constant(object) is_log_log_affine(object) is_log_log_convex(object) is_log_log_concave(object)
object |
An Expression object. |
A logical value.
The natural logarithm of the sum of the elementwise exponential, .
log_sum_exp(x, axis = NA_real_, keepdims = FALSE)
log_sum_exp(x, axis = NA_real_, keepdims = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
An Expression representing the log-sum-exponential of the input.
A <- Variable(2,2) val <- cbind(c(5,7), c(0,-3)) prob <- Problem(Minimize(log_sum_exp(A)), list(A == val)) result <- solve(prob) result$getValue(A)
A <- Variable(2,2) val <- cbind(c(5,7), c(0,-3)) prob <- Problem(Minimize(log_sum_exp(A)), list(A == val)) result <- solve(prob) result$getValue(A)
This class represents the elementwise natural logarithm .
Log(x) ## S4 method for signature 'Log' to_numeric(object, values) ## S4 method for signature 'Log' sign_from_args(object) ## S4 method for signature 'Log' is_atom_convex(object) ## S4 method for signature 'Log' is_atom_concave(object) ## S4 method for signature 'Log' is_atom_log_log_convex(object) ## S4 method for signature 'Log' is_atom_log_log_concave(object) ## S4 method for signature 'Log' is_incr(object, idx) ## S4 method for signature 'Log' is_decr(object, idx) ## S4 method for signature 'Log' .grad(object, values) ## S4 method for signature 'Log' .domain(object)
Log(x) ## S4 method for signature 'Log' to_numeric(object, values) ## S4 method for signature 'Log' sign_from_args(object) ## S4 method for signature 'Log' is_atom_convex(object) ## S4 method for signature 'Log' is_atom_concave(object) ## S4 method for signature 'Log' is_atom_log_log_convex(object) ## S4 method for signature 'Log' is_atom_log_log_concave(object) ## S4 method for signature 'Log' is_incr(object, idx) ## S4 method for signature 'Log' is_decr(object, idx) ## S4 method for signature 'Log' .grad(object, values) ## S4 method for signature 'Log' .domain(object)
x |
An Expression or numeric constant. |
object |
A Log object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(Log)
: The elementwise natural logarithm of the input value.
sign_from_args(Log)
: The sign of the atom is unknown.
is_atom_convex(Log)
: The atom is not convex.
is_atom_concave(Log)
: The atom is concave.
is_atom_log_log_convex(Log)
: Is the atom log-log convex?
is_atom_log_log_concave(Log)
: Is the atom log-log concave?
is_incr(Log)
: The atom is weakly increasing.
is_decr(Log)
: The atom is not weakly decreasing.
.grad(Log)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(Log)
: Returns constraints describng the domain of the node
x
An Expression or numeric constant.
The elementwise logarithm.
log
computes the logarithm, by default the natural logarithm, log10
computes the common (i.e., base 10) logarithm, and log2
computes the binary (i.e., base 2) logarithms. The general form log(x, base)
computes logarithms with base base
.
log1p
computes elementwise the function .
## S4 method for signature 'Expression' log(x, base = base::exp(1)) ## S4 method for signature 'Expression' log10(x) ## S4 method for signature 'Expression' log2(x) ## S4 method for signature 'Expression' log1p(x)
## S4 method for signature 'Expression' log(x, base = base::exp(1)) ## S4 method for signature 'Expression' log10(x) ## S4 method for signature 'Expression' log2(x) ## S4 method for signature 'Expression' log1p(x)
x |
An Expression. |
base |
(Optional) A positive number that is the base with respect to which the logarithm is computed. Defaults to |
An Expression representing the exponentiated input.
# Log in objective x <- Variable(2) obj <- Maximize(sum(log(x))) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Log in constraint obj <- Minimize(sum(x)) constr <- list(log2(x) >= 0, x <= matrix(c(1,1))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Index into log obj <- Maximize(log10(x)[2]) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value # Scalar log obj <- Maximize(log1p(x[2])) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value
# Log in objective x <- Variable(2) obj <- Maximize(sum(log(x))) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Log in constraint obj <- Minimize(sum(x)) constr <- list(log2(x) >= 0, x <= matrix(c(1,1))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Index into log obj <- Maximize(log10(x)[2]) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value # Scalar log obj <- Maximize(log1p(x[2])) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value
This class represents the elementwise operation .
Log1p(x) ## S4 method for signature 'Log1p' to_numeric(object, values) ## S4 method for signature 'Log1p' sign_from_args(object) ## S4 method for signature 'Log1p' .grad(object, values) ## S4 method for signature 'Log1p' .domain(object)
Log1p(x) ## S4 method for signature 'Log1p' to_numeric(object, values) ## S4 method for signature 'Log1p' sign_from_args(object) ## S4 method for signature 'Log1p' .grad(object, values) ## S4 method for signature 'Log1p' .domain(object)
x |
An Expression or numeric constant. |
object |
A Log1p object. |
values |
A list of numeric values for the arguments |
to_numeric(Log1p)
: The elementwise natural logarithm of one plus the input value.
sign_from_args(Log1p)
: The sign of the atom.
.grad(Log1p)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(Log1p)
: Returns constraints describng the domain of the node
x
An Expression or numeric constant.
The natural logarithm of the determinant of a matrix, .
LogDet(A) ## S4 method for signature 'LogDet' to_numeric(object, values) ## S4 method for signature 'LogDet' validate_args(object) ## S4 method for signature 'LogDet' dim_from_args(object) ## S4 method for signature 'LogDet' sign_from_args(object) ## S4 method for signature 'LogDet' is_atom_convex(object) ## S4 method for signature 'LogDet' is_atom_concave(object) ## S4 method for signature 'LogDet' is_incr(object, idx) ## S4 method for signature 'LogDet' is_decr(object, idx) ## S4 method for signature 'LogDet' .grad(object, values) ## S4 method for signature 'LogDet' .domain(object)
LogDet(A) ## S4 method for signature 'LogDet' to_numeric(object, values) ## S4 method for signature 'LogDet' validate_args(object) ## S4 method for signature 'LogDet' dim_from_args(object) ## S4 method for signature 'LogDet' sign_from_args(object) ## S4 method for signature 'LogDet' is_atom_convex(object) ## S4 method for signature 'LogDet' is_atom_concave(object) ## S4 method for signature 'LogDet' is_incr(object, idx) ## S4 method for signature 'LogDet' is_decr(object, idx) ## S4 method for signature 'LogDet' .grad(object, values) ## S4 method for signature 'LogDet' .domain(object)
A |
An Expression or numeric matrix. |
object |
A LogDet object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(LogDet)
: The log-determinant of SDP matrix A
. This is the sum of logs of the eigenvalues and is equivalent to the nuclear norm of the matrix logarithm of A
.
validate_args(LogDet)
: Check that A
is square.
dim_from_args(LogDet)
: The atom is a scalar.
sign_from_args(LogDet)
: The atom is non-negative.
is_atom_convex(LogDet)
: The atom is not convex.
is_atom_concave(LogDet)
: The atom is concave.
is_incr(LogDet)
: The atom is not monotonic in any argument.
is_decr(LogDet)
: The atom is not monotonic in any argument.
.grad(LogDet)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(LogDet)
: Returns constraints describing the domain of the node
A
An Expression or numeric matrix.
The elementwise logistic function, .
This is a special case of log(sum(exp)) that evaluates to a vector rather than to a scalar, which is useful for logistic regression.
logistic(x)
logistic(x)
x |
An Expression, vector, or matrix. |
An Expression representing the logistic function evaluated at the input.
set.seed(92) n <- 20 m <- 1000 sigma <- 45 beta_true <- stats::rnorm(n) idxs <- sample(n, size = 0.8*n, replace = FALSE) beta_true[idxs] <- 0 X <- matrix(stats::rnorm(m*n, 0, 5), nrow = m, ncol = n) y <- sign(X %*% beta_true + stats::rnorm(m, 0, sigma)) beta <- Variable(n) X_sign <- apply(X, 2, function(x) { ifelse(y <= 0, -1, 1) * x }) obj <- -sum(logistic(-X[y <= 0,] %*% beta)) - sum(logistic(X[y == 1,] %*% beta)) prob <- Problem(Maximize(obj)) result <- solve(prob) log_odds <- result$getValue(X %*% beta) beta_res <- result$getValue(beta) y_probs <- 1/(1 + exp(-X %*% beta_res)) log(y_probs/(1 - y_probs))
set.seed(92) n <- 20 m <- 1000 sigma <- 45 beta_true <- stats::rnorm(n) idxs <- sample(n, size = 0.8*n, replace = FALSE) beta_true[idxs] <- 0 X <- matrix(stats::rnorm(m*n, 0, 5), nrow = m, ncol = n) y <- sign(X %*% beta_true + stats::rnorm(m, 0, sigma)) beta <- Variable(n) X_sign <- apply(X, 2, function(x) { ifelse(y <= 0, -1, 1) * x }) obj <- -sum(logistic(-X[y <= 0,] %*% beta)) - sum(logistic(X[y == 1,] %*% beta)) prob <- Problem(Maximize(obj)) result <- solve(prob) log_odds <- result$getValue(X %*% beta) beta_res <- result$getValue(beta) y_probs <- 1/(1 + exp(-X %*% beta_res)) log(y_probs/(1 - y_probs))
This class represents the elementwise operation .
This is a special case of log(sum(exp)) that evaluates to a vector rather than to a scalar,
which is useful for logistic regression.
Logistic(x) ## S4 method for signature 'Logistic' to_numeric(object, values) ## S4 method for signature 'Logistic' sign_from_args(object) ## S4 method for signature 'Logistic' is_atom_convex(object) ## S4 method for signature 'Logistic' is_atom_concave(object) ## S4 method for signature 'Logistic' is_incr(object, idx) ## S4 method for signature 'Logistic' is_decr(object, idx) ## S4 method for signature 'Logistic' .grad(object, values)
Logistic(x) ## S4 method for signature 'Logistic' to_numeric(object, values) ## S4 method for signature 'Logistic' sign_from_args(object) ## S4 method for signature 'Logistic' is_atom_convex(object) ## S4 method for signature 'Logistic' is_atom_concave(object) ## S4 method for signature 'Logistic' is_incr(object, idx) ## S4 method for signature 'Logistic' is_decr(object, idx) ## S4 method for signature 'Logistic' .grad(object, values)
x |
An Expression or numeric constant. |
object |
A Logistic object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(Logistic)
: Evaluates e^x
elementwise, adds one, and takes the natural logarithm.
sign_from_args(Logistic)
: The atom is positive.
is_atom_convex(Logistic)
: The atom is convex.
is_atom_concave(Logistic)
: The atom is not concave.
is_incr(Logistic)
: The atom is weakly increasing.
is_decr(Logistic)
: The atom is not weakly decreasing.
.grad(Logistic)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric constant.
The natural logarithm of the sum of the elementwise exponential, .
LogSumExp(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'LogSumExp' to_numeric(object, values) ## S4 method for signature 'LogSumExp' .grad(object, values) ## S4 method for signature 'LogSumExp' .column_grad(object, value) ## S4 method for signature 'LogSumExp' sign_from_args(object) ## S4 method for signature 'LogSumExp' is_atom_convex(object) ## S4 method for signature 'LogSumExp' is_atom_concave(object) ## S4 method for signature 'LogSumExp' is_incr(object, idx) ## S4 method for signature 'LogSumExp' is_decr(object, idx)
LogSumExp(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'LogSumExp' to_numeric(object, values) ## S4 method for signature 'LogSumExp' .grad(object, values) ## S4 method for signature 'LogSumExp' .column_grad(object, value) ## S4 method for signature 'LogSumExp' sign_from_args(object) ## S4 method for signature 'LogSumExp' is_atom_convex(object) ## S4 method for signature 'LogSumExp' is_atom_concave(object) ## S4 method for signature 'LogSumExp' is_incr(object, idx) ## S4 method for signature 'LogSumExp' is_decr(object, idx)
x |
An Expression representing a vector or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A LogSumExp object. |
values |
A list of numeric values. |
value |
A numeric value. |
idx |
An index into the atom. |
to_numeric(LogSumExp)
: Evaluates elementwise, sums, and takes the natural log.
.grad(LogSumExp)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(LogSumExp)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable.
sign_from_args(LogSumExp)
: Returns sign (is positive, is negative) of the atom.
is_atom_convex(LogSumExp)
: The atom is convex.
is_atom_concave(LogSumExp)
: The atom is not concave.
is_incr(LogSumExp)
: The atom is weakly increasing in the index.
is_decr(LogSumExp)
: The atom is not weakly decreasing in the index.
x
An Expression representing a vector or matrix.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
Make a CSC sparse diagonal matrix
make_sparse_diagonal_matrix(size, diagonal = NULL)
make_sparse_diagonal_matrix(size, diagonal = NULL)
size |
number of rows or columns |
diagonal |
if specified, the diagonal values, in which case size is ignored |
a compressed sparse column diagonal matrix
.
matrix_frac(X, P)
matrix_frac(X, P)
X |
An Expression or matrix. Must have the same number of rows as |
P |
An Expression or matrix. Must be an invertible square matrix. |
An Expression representing the matrix fraction evaluated at the input.
## Not run: set.seed(192) m <- 100 n <- 80 r <- 70 A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) b <- matrix(stats::rnorm(m), nrow = m, ncol = 1) G <- matrix(stats::rnorm(r*n), nrow = r, ncol = n) h <- matrix(stats::rnorm(r), nrow = r, ncol = 1) # ||Ax-b||^2 = x^T (A^T A) x - 2(A^T b)^T x + ||b||^2 P <- t(A) %*% A q <- -2 * t(A) %*% b r <- t(b) %*% b Pinv <- base::solve(P) x <- Variable(n) obj <- matrix_frac(x, Pinv) + t(q) %*% x + r constr <- list(G %*% x == h) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value ## End(Not run)
## Not run: set.seed(192) m <- 100 n <- 80 r <- 70 A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) b <- matrix(stats::rnorm(m), nrow = m, ncol = 1) G <- matrix(stats::rnorm(r*n), nrow = r, ncol = n) h <- matrix(stats::rnorm(r), nrow = r, ncol = 1) # ||Ax-b||^2 = x^T (A^T A) x - 2(A^T b)^T x + ||b||^2 P <- t(A) %*% A q <- -2 * t(A) %*% b r <- t(b) %*% b Pinv <- base::solve(P) x <- Variable(n) obj <- matrix_frac(x, Pinv) + t(q) %*% x + r constr <- list(G %*% x == h) prob <- Problem(Minimize(obj), constr) result <- solve(prob) result$value ## End(Not run)
Determine if an expression is positive semidefinite, negative semidefinite, hermitian, and/or symmetric.
is_psd(object) is_nsd(object) is_hermitian(object) is_symmetric(object)
is_psd(object) is_nsd(object) is_hermitian(object) is_symmetric(object)
object |
An Expression object. |
A logical value.
The sum of the diagonal entries in a matrix.
matrix_trace(expr)
matrix_trace(expr)
expr |
An Expression or matrix. |
An Expression representing the trace of the input.
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Maximize(matrix_trace(C)), list(C == val)) result <- solve(prob) result$value
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Maximize(matrix_trace(C)), list(C == val)) result <- solve(prob) result$value
The matrix fraction function .
MatrixFrac(X, P) ## S4 method for signature 'MatrixFrac' allow_complex(object) ## S4 method for signature 'MatrixFrac' to_numeric(object, values) ## S4 method for signature 'MatrixFrac' validate_args(object) ## S4 method for signature 'MatrixFrac' dim_from_args(object) ## S4 method for signature 'MatrixFrac' sign_from_args(object) ## S4 method for signature 'MatrixFrac' is_atom_convex(object) ## S4 method for signature 'MatrixFrac' is_atom_concave(object) ## S4 method for signature 'MatrixFrac' is_incr(object, idx) ## S4 method for signature 'MatrixFrac' is_decr(object, idx) ## S4 method for signature 'MatrixFrac' is_quadratic(object) ## S4 method for signature 'MatrixFrac' is_qpwa(object) ## S4 method for signature 'MatrixFrac' .domain(object) ## S4 method for signature 'MatrixFrac' .grad(object, values)
MatrixFrac(X, P) ## S4 method for signature 'MatrixFrac' allow_complex(object) ## S4 method for signature 'MatrixFrac' to_numeric(object, values) ## S4 method for signature 'MatrixFrac' validate_args(object) ## S4 method for signature 'MatrixFrac' dim_from_args(object) ## S4 method for signature 'MatrixFrac' sign_from_args(object) ## S4 method for signature 'MatrixFrac' is_atom_convex(object) ## S4 method for signature 'MatrixFrac' is_atom_concave(object) ## S4 method for signature 'MatrixFrac' is_incr(object, idx) ## S4 method for signature 'MatrixFrac' is_decr(object, idx) ## S4 method for signature 'MatrixFrac' is_quadratic(object) ## S4 method for signature 'MatrixFrac' is_qpwa(object) ## S4 method for signature 'MatrixFrac' .domain(object) ## S4 method for signature 'MatrixFrac' .grad(object, values)
X |
An Expression or numeric matrix. |
P |
An Expression or numeric matrix. |
object |
A MatrixFrac object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
allow_complex(MatrixFrac)
: Does the atom handle complex numbers?
to_numeric(MatrixFrac)
: The trace of .
validate_args(MatrixFrac)
: Check that the dimensions of x
and P
match.
dim_from_args(MatrixFrac)
: The atom is a scalar.
sign_from_args(MatrixFrac)
: The atom is positive.
is_atom_convex(MatrixFrac)
: The atom is convex.
is_atom_concave(MatrixFrac)
: The atom is not concave.
is_incr(MatrixFrac)
: The atom is not monotonic in any argument.
is_decr(MatrixFrac)
: The atom is not monotonic in any argument.
is_quadratic(MatrixFrac)
: True if x is affine and P is constant.
is_qpwa(MatrixFrac)
: True if x is piecewise linear and P is constant.
.domain(MatrixFrac)
: Returns constraints describing the domain of the node
.grad(MatrixFrac)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
X
An Expression or numeric matrix.
P
An Expression or numeric matrix.
The MatrixStuffing class.
## S4 method for signature 'MatrixStuffing,Problem' perform(object, problem) ## S4 method for signature 'MatrixStuffing,Solution,InverseData' invert(object, solution, inverse_data)
## S4 method for signature 'MatrixStuffing,Problem' perform(object, problem) ## S4 method for signature 'MatrixStuffing,Solution,InverseData' invert(object, solution, inverse_data)
object |
A MatrixStuffing object. |
problem |
A Problem object to stuff; the arguments of every constraint must be affine. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
The data encoding the original problem. |
perform(object = MatrixStuffing, problem = Problem)
: Returns a stuffed problem. The returned problem is a minimization problem in which every
constraint in the problem has affine arguments that are expressed in the form A
invert(
object = MatrixStuffing,
solution = Solution,
inverse_data = InverseData
)
: Returns the solution to the original problem given the inverse_data.
The elementwise maximum.
max_elemwise(arg1, arg2, ...)
max_elemwise(arg1, arg2, ...)
arg1 |
An Expression, vector, or matrix. |
arg2 |
An Expression, vector, or matrix. |
... |
Additional Expression objects, vectors, or matrices. |
An Expression representing the elementwise maximum of the inputs.
c <- matrix(c(1,-1)) prob <- Problem(Minimize(max_elemwise(t(c), 2, 2 + t(c))[2])) result <- solve(prob) result$value
c <- matrix(c(1,-1)) prob <- Problem(Minimize(max_elemwise(t(c), 2, 2 + t(c))[2])) result <- solve(prob) result$value
The maximum of an expression.
max_entries(x, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' max(..., na.rm = FALSE)
max_entries(x, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' max(..., na.rm = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
... |
Numeric scalar, vector, matrix, or Expression objects. |
na.rm |
(Unimplemented) A logical value indicating whether missing values should be removed. |
An Expression representing the maximum of the input.
x <- Variable(2) val <- matrix(c(-5,-10)) prob <- Problem(Minimize(max_entries(x)), list(x == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- rbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(max_entries(A, axis = 1)[2,1]), list(A == val)) result <- solve(prob) result$value x <- Variable(2) val <- matrix(c(-5,-10)) prob <- Problem(Minimize(max_entries(x)), list(x == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- rbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(max_entries(A, axis = 1)[2,1]), list(A == val)) result <- solve(prob) result$value
x <- Variable(2) val <- matrix(c(-5,-10)) prob <- Problem(Minimize(max_entries(x)), list(x == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- rbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(max_entries(A, axis = 1)[2,1]), list(A == val)) result <- solve(prob) result$value x <- Variable(2) val <- matrix(c(-5,-10)) prob <- Problem(Minimize(max_entries(x)), list(x == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- rbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(max_entries(A, axis = 1)[2,1]), list(A == val)) result <- solve(prob) result$value
This class represents the elementwise maximum.
MaxElemwise(arg1, arg2, ...) ## S4 method for signature 'MaxElemwise' to_numeric(object, values) ## S4 method for signature 'MaxElemwise' sign_from_args(object) ## S4 method for signature 'MaxElemwise' is_atom_convex(object) ## S4 method for signature 'MaxElemwise' is_atom_concave(object) ## S4 method for signature 'MaxElemwise' is_atom_log_log_convex(object) ## S4 method for signature 'MaxElemwise' is_atom_log_log_concave(object) ## S4 method for signature 'MaxElemwise' is_incr(object, idx) ## S4 method for signature 'MaxElemwise' is_decr(object, idx) ## S4 method for signature 'MaxElemwise' is_pwl(object) ## S4 method for signature 'MaxElemwise' .grad(object, values)
MaxElemwise(arg1, arg2, ...) ## S4 method for signature 'MaxElemwise' to_numeric(object, values) ## S4 method for signature 'MaxElemwise' sign_from_args(object) ## S4 method for signature 'MaxElemwise' is_atom_convex(object) ## S4 method for signature 'MaxElemwise' is_atom_concave(object) ## S4 method for signature 'MaxElemwise' is_atom_log_log_convex(object) ## S4 method for signature 'MaxElemwise' is_atom_log_log_concave(object) ## S4 method for signature 'MaxElemwise' is_incr(object, idx) ## S4 method for signature 'MaxElemwise' is_decr(object, idx) ## S4 method for signature 'MaxElemwise' is_pwl(object) ## S4 method for signature 'MaxElemwise' .grad(object, values)
arg1 |
The first Expression in the maximum operation. |
arg2 |
The second Expression in the maximum operation. |
... |
Additional Expression objects in the maximum operation. |
object |
A MaxElemwise object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(MaxElemwise)
: The elementwise maximum.
sign_from_args(MaxElemwise)
: The sign of the atom.
is_atom_convex(MaxElemwise)
: The atom is convex.
is_atom_concave(MaxElemwise)
: The atom is not concave.
is_atom_log_log_convex(MaxElemwise)
: Is the atom log-log convex?
is_atom_log_log_concave(MaxElemwise)
: Is the atom log-log concave?
is_incr(MaxElemwise)
: The atom is weakly increasing.
is_decr(MaxElemwise)
: The atom is not weakly decreasing.
is_pwl(MaxElemwise)
: Are all the arguments piecewise linear?
.grad(MaxElemwise)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
arg1
The first Expression in the maximum operation.
arg2
The second Expression in the maximum operation.
...
Additional Expression objects in the maximum operation.
The maximum of an expression.
MaxEntries(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'MaxEntries' to_numeric(object, values) ## S4 method for signature 'MaxEntries' sign_from_args(object) ## S4 method for signature 'MaxEntries' is_atom_convex(object) ## S4 method for signature 'MaxEntries' is_atom_concave(object) ## S4 method for signature 'MaxEntries' is_atom_log_log_convex(object) ## S4 method for signature 'MaxEntries' is_atom_log_log_concave(object) ## S4 method for signature 'MaxEntries' is_incr(object, idx) ## S4 method for signature 'MaxEntries' is_decr(object, idx) ## S4 method for signature 'MaxEntries' is_pwl(object) ## S4 method for signature 'MaxEntries' .grad(object, values) ## S4 method for signature 'MaxEntries' .column_grad(object, value)
MaxEntries(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'MaxEntries' to_numeric(object, values) ## S4 method for signature 'MaxEntries' sign_from_args(object) ## S4 method for signature 'MaxEntries' is_atom_convex(object) ## S4 method for signature 'MaxEntries' is_atom_concave(object) ## S4 method for signature 'MaxEntries' is_atom_log_log_convex(object) ## S4 method for signature 'MaxEntries' is_atom_log_log_concave(object) ## S4 method for signature 'MaxEntries' is_incr(object, idx) ## S4 method for signature 'MaxEntries' is_decr(object, idx) ## S4 method for signature 'MaxEntries' is_pwl(object) ## S4 method for signature 'MaxEntries' .grad(object, values) ## S4 method for signature 'MaxEntries' .column_grad(object, value)
x |
An Expression representing a vector or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A MaxEntries object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value |
to_numeric(MaxEntries)
: The largest entry in x
.
sign_from_args(MaxEntries)
: The sign of the atom.
is_atom_convex(MaxEntries)
: The atom is convex.
is_atom_concave(MaxEntries)
: The atom is not concave.
is_atom_log_log_convex(MaxEntries)
: Is the atom log-log convex.
is_atom_log_log_concave(MaxEntries)
: Is the atom log-log concave.
is_incr(MaxEntries)
: The atom is weakly increasing in every argument.
is_decr(MaxEntries)
: The atom is not weakly decreasing in any argument.
is_pwl(MaxEntries)
: Is x
piecewise linear?
.grad(MaxEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(MaxEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
x
An Expression representing a vector or matrix.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
This class represents an optimization objective for maximization.
Maximize(expr) ## S4 method for signature 'Maximize' canonicalize(object) ## S4 method for signature 'Maximize' is_dcp(object) ## S4 method for signature 'Maximize' is_dgp(object)
Maximize(expr) ## S4 method for signature 'Maximize' canonicalize(object) ## S4 method for signature 'Maximize' is_dcp(object) ## S4 method for signature 'Maximize' is_dgp(object)
expr |
A scalar Expression to maximize. |
object |
A Maximize object. |
canonicalize(Maximize)
: Negates the target expression's objective.
is_dcp(Maximize)
: A logical value indicating whether the objective is concave.
is_dgp(Maximize)
: A logical value indicating whether the objective is log-log concave.
expr
A scalar Expression to maximize.
x <- Variable(3) alpha <- c(0.8,1.0,1.2) obj <- sum(log(alpha + x)) constr <- list(x >= 0, sum(x) == 1) prob <- Problem(Maximize(obj), constr) result <- solve(prob) result$value result$getValue(x)
x <- Variable(3) alpha <- c(0.8,1.0,1.2) obj <- sum(log(alpha + x)) constr <- list(x >= 0, sum(x) == 1) prob <- Problem(Maximize(obj), constr) result <- solve(prob) result$value result$getValue(x)
The arithmetic mean of an expression.
## S3 method for class 'Expression' mean(x, trim = 0, na.rm = FALSE, ...)
## S3 method for class 'Expression' mean(x, trim = 0, na.rm = FALSE, ...)
x |
An Expression object. |
trim |
(Unimplemented) The fraction (0 to 0.5) of observations to be trimmed from each end of |
na.rm |
(Unimplemented) A logical value indicating whether missing values should be removed. |
... |
(Unimplemented) Optional arguments. |
An Expression representing the mean of the input.
A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(mean(A)), list(A == val)) result <- solve(prob) result$value
A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(mean(A)), list(A == val)) result <- solve(prob) result$value
The elementwise minimum.
min_elemwise(arg1, arg2, ...)
min_elemwise(arg1, arg2, ...)
arg1 |
An Expression, vector, or matrix. |
arg2 |
An Expression, vector, or matrix. |
... |
Additional Expression objects, vectors, or matrices. |
An Expression representing the elementwise minimum of the inputs.
a <- cbind(c(-5,2), c(-3,-1)) b <- cbind(c(5,4), c(-1,2)) prob <- Problem(Minimize(min_elemwise(a, 0, b)[1,2])) result <- solve(prob) result$value
a <- cbind(c(-5,2), c(-3,-1)) b <- cbind(c(5,4), c(-1,2)) prob <- Problem(Minimize(min_elemwise(a, 0, b)[1,2])) result <- solve(prob) result$value
The minimum of an expression.
min_entries(x, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' min(..., na.rm = FALSE)
min_entries(x, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' min(..., na.rm = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
... |
Numeric scalar, vector, matrix, or Expression objects. |
na.rm |
(Unimplemented) A logical value indicating whether missing values should be removed. |
An Expression representing the minimum of the input.
A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Maximize(min_entries(A)), list(A == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Maximize(min_entries(A)), list(A == val)) result <- solve(prob) result$value
A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Maximize(min_entries(A)), list(A == val)) result <- solve(prob) result$value A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Maximize(min_entries(A)), list(A == val)) result <- solve(prob) result$value
This class represents the elementwise minimum.
MinElemwise(arg1, arg2, ...) ## S4 method for signature 'MinElemwise' to_numeric(object, values) ## S4 method for signature 'MinElemwise' sign_from_args(object) ## S4 method for signature 'MinElemwise' is_atom_convex(object) ## S4 method for signature 'MinElemwise' is_atom_concave(object) ## S4 method for signature 'MinElemwise' is_atom_log_log_convex(object) ## S4 method for signature 'MinElemwise' is_atom_log_log_concave(object) ## S4 method for signature 'MinElemwise' is_incr(object, idx) ## S4 method for signature 'MinElemwise' is_decr(object, idx) ## S4 method for signature 'MinElemwise' is_pwl(object) ## S4 method for signature 'MinElemwise' .grad(object, values)
MinElemwise(arg1, arg2, ...) ## S4 method for signature 'MinElemwise' to_numeric(object, values) ## S4 method for signature 'MinElemwise' sign_from_args(object) ## S4 method for signature 'MinElemwise' is_atom_convex(object) ## S4 method for signature 'MinElemwise' is_atom_concave(object) ## S4 method for signature 'MinElemwise' is_atom_log_log_convex(object) ## S4 method for signature 'MinElemwise' is_atom_log_log_concave(object) ## S4 method for signature 'MinElemwise' is_incr(object, idx) ## S4 method for signature 'MinElemwise' is_decr(object, idx) ## S4 method for signature 'MinElemwise' is_pwl(object) ## S4 method for signature 'MinElemwise' .grad(object, values)
arg1 |
The first Expression in the minimum operation. |
arg2 |
The second Expression in the minimum operation. |
... |
Additional Expression objects in the minimum operation. |
object |
A MinElemwise object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(MinElemwise)
: The elementwise minimum.
sign_from_args(MinElemwise)
: The sign of the atom.
is_atom_convex(MinElemwise)
: The atom is not convex.
is_atom_concave(MinElemwise)
: The atom is not concave.
is_atom_log_log_convex(MinElemwise)
: Is the atom log-log convex?
is_atom_log_log_concave(MinElemwise)
: Is the atom log-log concave?
is_incr(MinElemwise)
: The atom is weakly increasing.
is_decr(MinElemwise)
: The atom is not weakly decreasing.
is_pwl(MinElemwise)
: Are all the arguments piecewise linear?
.grad(MinElemwise)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
arg1
The first Expression in the minimum operation.
arg2
The second Expression in the minimum operation.
...
Additional Expression objects in the minimum operation.
The minimum of an expression.
MinEntries(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'MinEntries' to_numeric(object, values) ## S4 method for signature 'MinEntries' sign_from_args(object) ## S4 method for signature 'MinEntries' is_atom_convex(object) ## S4 method for signature 'MinEntries' is_atom_concave(object) ## S4 method for signature 'MinEntries' is_atom_log_log_convex(object) ## S4 method for signature 'MinEntries' is_atom_log_log_concave(object) ## S4 method for signature 'MinEntries' is_incr(object, idx) ## S4 method for signature 'MinEntries' is_decr(object, idx) ## S4 method for signature 'MinEntries' is_pwl(object) ## S4 method for signature 'MinEntries' .grad(object, values) ## S4 method for signature 'MinEntries' .column_grad(object, value)
MinEntries(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'MinEntries' to_numeric(object, values) ## S4 method for signature 'MinEntries' sign_from_args(object) ## S4 method for signature 'MinEntries' is_atom_convex(object) ## S4 method for signature 'MinEntries' is_atom_concave(object) ## S4 method for signature 'MinEntries' is_atom_log_log_convex(object) ## S4 method for signature 'MinEntries' is_atom_log_log_concave(object) ## S4 method for signature 'MinEntries' is_incr(object, idx) ## S4 method for signature 'MinEntries' is_decr(object, idx) ## S4 method for signature 'MinEntries' is_pwl(object) ## S4 method for signature 'MinEntries' .grad(object, values) ## S4 method for signature 'MinEntries' .column_grad(object, value)
x |
An Expression representing a vector or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A MinEntries object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value |
to_numeric(MinEntries)
: The largest entry in x
.
sign_from_args(MinEntries)
: The sign of the atom.
is_atom_convex(MinEntries)
: The atom is not convex.
is_atom_concave(MinEntries)
: The atom is concave.
is_atom_log_log_convex(MinEntries)
: Is the atom log-log convex?
is_atom_log_log_concave(MinEntries)
: Is the atom log-log concave?
is_incr(MinEntries)
: The atom is weakly increasing in every argument.
is_decr(MinEntries)
: The atom is not weakly decreasing in any argument.
is_pwl(MinEntries)
: Is x
piecewise linear?
.grad(MinEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(MinEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
x
An Expression representing a vector or matrix.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
This class represents an optimization objective for minimization.
Minimize(expr) ## S4 method for signature 'Minimize' canonicalize(object) ## S4 method for signature 'Minimize' is_dcp(object) ## S4 method for signature 'Minimize' is_dgp(object)
Minimize(expr) ## S4 method for signature 'Minimize' canonicalize(object) ## S4 method for signature 'Minimize' is_dcp(object) ## S4 method for signature 'Minimize' is_dgp(object)
expr |
A scalar Expression to minimize. |
object |
A Minimize object. |
canonicalize(Minimize)
: Pass on the target expression's objective and constraints.
is_dcp(Minimize)
: A logical value indicating whether the objective is convex.
is_dgp(Minimize)
: A logical value indicating whether the objective is log-log convex.
expr
A scalar Expression to minimize.
Determine if a solver is capable of solving a mixed-integer program (MIP).
mip_capable(solver)
mip_capable(solver)
solver |
A ReductionSolver object. |
A logical value.
mip_capable(ECOS())
mip_capable(ECOS())
.
mixed_norm(X, p = 2, q = 1)
mixed_norm(X, p = 2, q = 1)
X |
An Expression, vector, or matrix. |
p |
The type of inner norm. |
q |
The type of outer norm. |
An Expression representing the norm of the input.
A <- Variable(2,2) val <- cbind(c(3,3), c(4,4)) prob <- Problem(Minimize(mixed_norm(A,2,1)), list(A == val)) result <- solve(prob) result$value result$getValue(A) val <- cbind(c(1,4), c(5,6)) prob <- Problem(Minimize(mixed_norm(A,1,Inf)), list(A == val)) result <- solve(prob) result$value result$getValue(A)
A <- Variable(2,2) val <- cbind(c(3,3), c(4,4)) prob <- Problem(Minimize(mixed_norm(A,2,1)), list(A == val)) result <- solve(prob) result$value result$getValue(A) val <- cbind(c(1,4), c(5,6)) prob <- Problem(Minimize(mixed_norm(A,1,Inf)), list(A == val)) result <- solve(prob) result$value result$getValue(A)
The norm of X,
.
MixedNorm(X, p = 2, q = 1)
MixedNorm(X, p = 2, q = 1)
X |
The matrix to take the |
p |
The type of inner norm |
q |
The type of outer norm |
Returns the mixed norm of X with specified parameters p and q
An interface for the MOSEK solver.
MOSEK() ## S4 method for signature 'MOSEK' mip_capable(solver) ## S4 method for signature 'MOSEK' import_solver(solver) ## S4 method for signature 'MOSEK' name(x) ## S4 method for signature 'MOSEK,Problem' accepts(object, problem) ## S4 method for signature 'MOSEK' block_format(object, problem, constraints, exp_cone_order = NA) ## S4 method for signature 'MOSEK,Problem' perform(object, problem) ## S4 method for signature 'MOSEK' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'MOSEK,ANY,ANY' invert(object, solution, inverse_data)
MOSEK() ## S4 method for signature 'MOSEK' mip_capable(solver) ## S4 method for signature 'MOSEK' import_solver(solver) ## S4 method for signature 'MOSEK' name(x) ## S4 method for signature 'MOSEK,Problem' accepts(object, problem) ## S4 method for signature 'MOSEK' block_format(object, problem, constraints, exp_cone_order = NA) ## S4 method for signature 'MOSEK,Problem' perform(object, problem) ## S4 method for signature 'MOSEK' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'MOSEK,ANY,ANY' invert(object, solution, inverse_data)
solver , object , x
|
A MOSEK object. |
problem |
A Problem object. |
constraints |
A list of Constraint objects for which coefficient andd offset data ("G", "h" respectively) is needed |
exp_cone_order |
A parameter that is only used when a Constraint object describes membership in the exponential cone. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
mip_capable(MOSEK)
: Can the solver handle mixed-integer programs?
import_solver(MOSEK)
: Imports the solver.
name(MOSEK)
: Returns the name of the solver.
accepts(object = MOSEK, problem = Problem)
: Can MOSEK solve the problem?
block_format(MOSEK)
: Returns a large matrix "coeff" and a vector of constants "offset" such
that every Constraint in "constraints" holds at z in R^n iff
"coeff" * z <=_K offset", where K is a product of cones supported by MOSEK
and CVXR (zero cone, nonnegative orthant, second order cone, exponential cone). The
nature of K is inferred later by accessing the data in "lengths" and "ids".
perform(object = MOSEK, problem = Problem)
: Returns a new problem and data for inverting the new solution.
solve_via_data(MOSEK)
: Solve a problem represented by data returned from apply.
invert(object = MOSEK, solution = ANY, inverse_data = ANY)
: Returns the solution to the original problem given the inverse_data.
Parses MOSEK dual variables into corresponding CVXR constraints and dual values
MOSEK.parse_dual_vars(dual_var, constr_id_to_constr_dim)
MOSEK.parse_dual_vars(dual_var, constr_id_to_constr_dim)
dual_var |
List of the dual variables returned by the MOSEK solution. |
constr_id_to_constr_dim |
A list that contains the mapping of entry "id" that is the index of the CVXR Constraint object to which the next "dim" entries of the dual variable belong. |
A list with the mapping of the CVXR Constraint object indices with the corresponding dual values.
Recovers MOSEK solutions dual variables
MOSEK.recover_dual_variables(sol, inverse_data)
MOSEK.recover_dual_variables(sol, inverse_data)
sol |
List of the solutions returned by the MOSEK solver. |
inverse_data |
A list of the data returned by the perform function. |
A list containing the mapping of CVXR's Constraint object's id to its corresponding dual variables in the current solution.
The elementwise product of two expressions. The first expression must be constant.
multiply(lh_exp, rh_exp)
multiply(lh_exp, rh_exp)
lh_exp |
An Expression, vector, or matrix representing the left-hand value. |
rh_exp |
An Expression, vector, or matrix representing the right-hand value. |
An Expression representing the elementwise product of the inputs.
A <- Variable(2,2) c <- cbind(c(1,-1), c(2,-2)) expr <- multiply(c, A) obj <- Minimize(norm_inf(expr)) prob <- Problem(obj, list(A == 5)) result <- solve(prob) result$value result$getValue(expr)
A <- Variable(2,2) c <- cbind(c(1,-1), c(2,-2)) expr <- multiply(c, A) obj <- Minimize(norm_inf(expr)) prob <- Problem(obj, list(A == 5)) result <- solve(prob) result$value result$getValue(expr)
This class represents the elementwise product of two expressions.
Multiply(lh_exp, rh_exp) ## S4 method for signature 'Multiply' to_numeric(object, values) ## S4 method for signature 'Multiply' dim_from_args(object) ## S4 method for signature 'Multiply' is_atom_log_log_convex(object) ## S4 method for signature 'Multiply' is_atom_log_log_concave(object) ## S4 method for signature 'Multiply' is_psd(object) ## S4 method for signature 'Multiply' is_nsd(object) ## S4 method for signature 'Multiply' graph_implementation(object, arg_objs, dim, data = NA_real_)
Multiply(lh_exp, rh_exp) ## S4 method for signature 'Multiply' to_numeric(object, values) ## S4 method for signature 'Multiply' dim_from_args(object) ## S4 method for signature 'Multiply' is_atom_log_log_convex(object) ## S4 method for signature 'Multiply' is_atom_log_log_concave(object) ## S4 method for signature 'Multiply' is_psd(object) ## S4 method for signature 'Multiply' is_nsd(object) ## S4 method for signature 'Multiply' graph_implementation(object, arg_objs, dim, data = NA_real_)
lh_exp |
An Expression or R numeric data. |
rh_exp |
An Expression or R numeric data. |
object |
A Multiply object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Multiply)
: Multiplies the values elementwise.
dim_from_args(Multiply)
: The sum of the argument dimensions - 1.
is_atom_log_log_convex(Multiply)
: Is the atom log-log convex?
is_atom_log_log_concave(Multiply)
: Is the atom log-log concave?
is_psd(Multiply)
: Is the expression a positive semidefinite matrix?
is_nsd(Multiply)
: Is the expression a negative semidefinite matrix?
graph_implementation(Multiply)
: The graph implementation of the expression.
The string representation of a variable, parameter, or expression.
name(x)
name(x)
x |
A Variable, Parameter, or Expression object. |
For Variable or Parameter objects, the value in the name slot. For Expression objects, a string indicating the nested atoms and their respective arguments.
x <- Variable() y <- Variable(3, name = "yVar") name(x) name(y)
x <- Variable() y <- Variable(3, name = "yVar") name(x) name(y)
The elementwise absolute negative portion of an expression, . This is equivalent to
-min_elemwise(x,0)
.
neg(x)
neg(x)
x |
An Expression, vector, or matrix. |
An Expression representing the negative portion of the input.
x <- Variable(2) val <- matrix(c(-3,3)) prob <- Problem(Minimize(neg(x)[1]), list(x == val)) result <- solve(prob) result$value
x <- Variable(2) val <- matrix(c(-3,3)) prob <- Problem(Minimize(neg(x)[1]), list(x == val)) result <- solve(prob) result$value
An alias for -MinElemwise(x, 0)
Neg(x)
Neg(x)
x |
An R numeric value or Expression. |
An alias for -MinElemwise(x, 0)
This class represents a nonlinear inequality constraint, where
is twice-differentiable.
NonlinearConstraint(f, vars_, id = NA_integer_)
NonlinearConstraint(f, vars_, id = NA_integer_)
f |
A nonlinear function. |
vars_ |
A list of variables involved in the function. |
id |
(Optional) An integer representing the unique ID of the contraint. |
f
A nonlinear function.
vars_
A list of variables involved in the function.
.x_dim
(Internal) The dimensions of a column vector with number of elements equal to the total elements in all the variables.
The NonPosConstraint class
## S4 method for signature 'NonPosConstraint' name(x) ## S4 method for signature 'NonPosConstraint' is_dcp(object) ## S4 method for signature 'NonPosConstraint' is_dgp(object) ## S4 method for signature 'NonPosConstraint' canonicalize(object) ## S4 method for signature 'NonPosConstraint' residual(object)
## S4 method for signature 'NonPosConstraint' name(x) ## S4 method for signature 'NonPosConstraint' is_dcp(object) ## S4 method for signature 'NonPosConstraint' is_dgp(object) ## S4 method for signature 'NonPosConstraint' canonicalize(object) ## S4 method for signature 'NonPosConstraint' residual(object)
x , object
|
A NonPosConstraint object. |
name(NonPosConstraint)
: The string representation of the constraint.
is_dcp(NonPosConstraint)
: Is the constraint DCP?
is_dgp(NonPosConstraint)
: Is the constraint DGP?
canonicalize(NonPosConstraint)
: The graph implementation of the object.
residual(NonPosConstraint)
: The residual of the constraint.
Wrapper around the different norm atoms.
Norm(x, p = 2, axis = NA_real_, keepdims = FALSE)
Norm(x, p = 2, axis = NA_real_, keepdims = FALSE)
x |
The matrix to take the norm of |
p |
The type of norm. Valid options include any positive integer, 'fro' (for frobenius), 'nuc' (sum of singular values), np.inf or 'inf' (infinity norm). |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
Returns the specified norm of x.
.
norm_inf(x, axis = NA_real_, keepdims = FALSE)
norm_inf(x, axis = NA_real_, keepdims = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
An Expression representing the infinity-norm of the input.
a <- Variable() b <- Variable() c <- Variable() prob <- Problem(Minimize(norm_inf(a)), list(a >= 2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Minimize(3*norm_inf(a + 2*b) + c), list(a >= 2, b <= -1, c == 3)) result <- solve(prob) result$value result$getValue(a + 2*b) result$getValue(c) prob <- Problem(Maximize(-norm_inf(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm_inf(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x[1] - z[1])
a <- Variable() b <- Variable() c <- Variable() prob <- Problem(Minimize(norm_inf(a)), list(a >= 2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Minimize(3*norm_inf(a + 2*b) + c), list(a >= 2, b <= -1, c == 3)) result <- solve(prob) result$value result$getValue(a + 2*b) result$getValue(c) prob <- Problem(Maximize(-norm_inf(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm_inf(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x[1] - z[1])
The nuclear norm, i.e. sum of the singular values of a matrix.
norm_nuc(A)
norm_nuc(A)
A |
An Expression or matrix. |
An Expression representing the nuclear norm of the input.
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Minimize(norm_nuc(C)), list(C == val)) result <- solve(prob) result$value
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Minimize(norm_nuc(C)), list(C == val)) result <- solve(prob) result$value
The matrix norm, which can be the 1-norm ("1"), infinity-norm ("I"), Frobenius norm ("F"), maximum modulus of all the entries ("M"), or the spectral norm ("2"), as determined by the value of type.
## S4 method for signature 'Expression,character' norm(x, type)
## S4 method for signature 'Expression,character' norm(x, type)
x |
An Expression. |
type |
A character indicating the type of norm desired.
|
An Expression representing the norm of the input.
The p_norm
function calculates the vector p-norm.
C <- Variable(3,2) val <- Constant(rbind(c(1,2), c(3,4), c(5,6))) prob <- Problem(Minimize(norm(C, "F")), list(C == val)) result <- solve(prob, solver = "SCS") result$value
C <- Variable(3,2) val <- Constant(rbind(c(1,2), c(3,4), c(5,6))) prob <- Problem(Minimize(norm(C, "F")), list(C == val)) result <- solve(prob, solver = "SCS") result$value
.
norm1(x, axis = NA_real_, keepdims = FALSE)
norm1(x, axis = NA_real_, keepdims = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
An Expression representing the 1-norm of the input.
a <- Variable() prob <- Problem(Minimize(norm1(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Maximize(-norm1(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm1(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x[1] - z[1])
a <- Variable() prob <- Problem(Minimize(norm1(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Maximize(-norm1(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm1(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x[1] - z[1])
This class represents the 1-norm of an expression.
Norm1(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'Norm1' name(x) ## S4 method for signature 'Norm1' to_numeric(object, values) ## S4 method for signature 'Norm1' allow_complex(object) ## S4 method for signature 'Norm1' sign_from_args(object) ## S4 method for signature 'Norm1' is_atom_convex(object) ## S4 method for signature 'Norm1' is_atom_concave(object) ## S4 method for signature 'Norm1' is_incr(object, idx) ## S4 method for signature 'Norm1' is_decr(object, idx) ## S4 method for signature 'Norm1' is_pwl(object) ## S4 method for signature 'Norm1' get_data(object) ## S4 method for signature 'Norm1' .domain(object) ## S4 method for signature 'Norm1' .grad(object, values) ## S4 method for signature 'Norm1' .column_grad(object, value)
Norm1(x, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'Norm1' name(x) ## S4 method for signature 'Norm1' to_numeric(object, values) ## S4 method for signature 'Norm1' allow_complex(object) ## S4 method for signature 'Norm1' sign_from_args(object) ## S4 method for signature 'Norm1' is_atom_convex(object) ## S4 method for signature 'Norm1' is_atom_concave(object) ## S4 method for signature 'Norm1' is_incr(object, idx) ## S4 method for signature 'Norm1' is_decr(object, idx) ## S4 method for signature 'Norm1' is_pwl(object) ## S4 method for signature 'Norm1' get_data(object) ## S4 method for signature 'Norm1' .domain(object) ## S4 method for signature 'Norm1' .grad(object, values) ## S4 method for signature 'Norm1' .column_grad(object, value)
x |
An Expression object. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A Norm1 object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value |
name(Norm1)
: The name and arguments of the atom.
to_numeric(Norm1)
: Returns the 1-norm of x along the given axis.
allow_complex(Norm1)
: Does the atom handle complex numbers?
sign_from_args(Norm1)
: The atom is always positive.
is_atom_convex(Norm1)
: The atom is convex.
is_atom_concave(Norm1)
: The atom is not concave.
is_incr(Norm1)
: Is the composition weakly increasing in argument idx
?
is_decr(Norm1)
: Is the composition weakly decreasing in argument idx
?
is_pwl(Norm1)
: Is the atom piecewise linear?
get_data(Norm1)
: Returns the axis.
.domain(Norm1)
: Returns constraints describing the domain of the node
.grad(Norm1)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(Norm1)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
x
An Expression object.
.
norm2(x, axis = NA_real_, keepdims = FALSE)
norm2(x, axis = NA_real_, keepdims = FALSE)
x |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
An Expression representing the Euclidean norm of the input.
a <- Variable() prob <- Problem(Minimize(norm2(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Maximize(-norm2(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm2(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x) result$getValue(z) prob <- Problem(Minimize(norm2(t(x - z)) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x) result$getValue(z)
a <- Variable() prob <- Problem(Minimize(norm2(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) prob <- Problem(Maximize(-norm2(a)), list(a <= -2)) result <- solve(prob) result$value result$getValue(a) x <- Variable(2) z <- Variable(2) prob <- Problem(Minimize(norm2(x - z) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x) result$getValue(z) prob <- Problem(Minimize(norm2(t(x - z)) + 5), list(x >= c(2,3), z <= c(-1,-4))) result <- solve(prob) result$value result$getValue(x) result$getValue(z)
The 2-norm of an expression.
Norm2(x, axis = NA_real_, keepdims = FALSE)
Norm2(x, axis = NA_real_, keepdims = FALSE)
x |
An Expression object. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
Returns the 2-norm of x.
This class represents the infinity-norm.
## S4 method for signature 'NormInf' name(x) ## S4 method for signature 'NormInf' to_numeric(object, values) ## S4 method for signature 'NormInf' allow_complex(object) ## S4 method for signature 'NormInf' sign_from_args(object) ## S4 method for signature 'NormInf' is_atom_convex(object) ## S4 method for signature 'NormInf' is_atom_concave(object) ## S4 method for signature 'NormInf' is_atom_log_log_convex(object) ## S4 method for signature 'NormInf' is_atom_log_log_concave(object) ## S4 method for signature 'NormInf' is_incr(object, idx) ## S4 method for signature 'NormInf' is_decr(object, idx) ## S4 method for signature 'NormInf' is_pwl(object) ## S4 method for signature 'NormInf' get_data(object) ## S4 method for signature 'NormInf' .domain(object) ## S4 method for signature 'NormInf' .grad(object, values) ## S4 method for signature 'NormInf' .column_grad(object, value)
## S4 method for signature 'NormInf' name(x) ## S4 method for signature 'NormInf' to_numeric(object, values) ## S4 method for signature 'NormInf' allow_complex(object) ## S4 method for signature 'NormInf' sign_from_args(object) ## S4 method for signature 'NormInf' is_atom_convex(object) ## S4 method for signature 'NormInf' is_atom_concave(object) ## S4 method for signature 'NormInf' is_atom_log_log_convex(object) ## S4 method for signature 'NormInf' is_atom_log_log_concave(object) ## S4 method for signature 'NormInf' is_incr(object, idx) ## S4 method for signature 'NormInf' is_decr(object, idx) ## S4 method for signature 'NormInf' is_pwl(object) ## S4 method for signature 'NormInf' get_data(object) ## S4 method for signature 'NormInf' .domain(object) ## S4 method for signature 'NormInf' .grad(object, values) ## S4 method for signature 'NormInf' .column_grad(object, value)
x , object
|
A NormInf object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value |
name(NormInf)
: The name and arguments of the atom.
to_numeric(NormInf)
: Returns the infinity norm of x
.
allow_complex(NormInf)
: Does the atom handle complex numbers?
sign_from_args(NormInf)
: The atom is always positive.
is_atom_convex(NormInf)
: The atom is convex.
is_atom_concave(NormInf)
: The atom is not concave.
is_atom_log_log_convex(NormInf)
: Is the atom log-log convex?
is_atom_log_log_concave(NormInf)
: Is the atom log-log concave?
is_incr(NormInf)
: Is the composition weakly increasing in argument idx
?
is_decr(NormInf)
: Is the composition weakly decreasing in argument idx
?
is_pwl(NormInf)
: Is the atom piecewise linear?
get_data(NormInf)
: Returns the axis.
.domain(NormInf)
: Returns constraints describing the domain of the node
.grad(NormInf)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(NormInf)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
The nuclear norm, i.e. sum of the singular values of a matrix.
NormNuc(A) ## S4 method for signature 'NormNuc' to_numeric(object, values) ## S4 method for signature 'NormNuc' allow_complex(object) ## S4 method for signature 'NormNuc' dim_from_args(object) ## S4 method for signature 'NormNuc' sign_from_args(object) ## S4 method for signature 'NormNuc' is_atom_convex(object) ## S4 method for signature 'NormNuc' is_atom_concave(object) ## S4 method for signature 'NormNuc' is_incr(object, idx) ## S4 method for signature 'NormNuc' is_decr(object, idx) ## S4 method for signature 'NormNuc' .grad(object, values)
NormNuc(A) ## S4 method for signature 'NormNuc' to_numeric(object, values) ## S4 method for signature 'NormNuc' allow_complex(object) ## S4 method for signature 'NormNuc' dim_from_args(object) ## S4 method for signature 'NormNuc' sign_from_args(object) ## S4 method for signature 'NormNuc' is_atom_convex(object) ## S4 method for signature 'NormNuc' is_atom_concave(object) ## S4 method for signature 'NormNuc' is_incr(object, idx) ## S4 method for signature 'NormNuc' is_decr(object, idx) ## S4 method for signature 'NormNuc' .grad(object, values)
A |
An Expression or numeric matrix. |
object |
A NormNuc object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(NormNuc)
: The nuclear norm (i.e., the sum of the singular values) of A
.
allow_complex(NormNuc)
: Does the atom handle complex numbers?
dim_from_args(NormNuc)
: The atom is a scalar.
sign_from_args(NormNuc)
: The atom is positive.
is_atom_convex(NormNuc)
: The atom is convex.
is_atom_concave(NormNuc)
: The atom is not concave.
is_incr(NormNuc)
: The atom is not monotonic in any argument.
is_decr(NormNuc)
: The atom is not monotonic in any argument.
.grad(NormNuc)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
A
An Expression or numeric matrix.
Add, subtract, multiply, or divide optimization objectives.
## S4 method for signature 'Objective,numeric' e1 + e2 ## S4 method for signature 'numeric,Objective' e1 + e2 ## S4 method for signature 'Minimize,missing' e1 - e2 ## S4 method for signature 'Minimize,Minimize' e1 + e2 ## S4 method for signature 'Minimize,Maximize' e1 + e2 ## S4 method for signature 'Objective,Minimize' e1 - e2 ## S4 method for signature 'Objective,Maximize' e1 - e2 ## S4 method for signature 'Minimize,Objective' e1 - e2 ## S4 method for signature 'Maximize,Objective' e1 - e2 ## S4 method for signature 'Objective,numeric' e1 - e2 ## S4 method for signature 'numeric,Objective' e1 - e2 ## S4 method for signature 'Minimize,numeric' e1 * e2 ## S4 method for signature 'Maximize,numeric' e1 * e2 ## S4 method for signature 'numeric,Minimize' e1 * e2 ## S4 method for signature 'numeric,Maximize' e1 * e2 ## S4 method for signature 'Objective,numeric' e1 / e2 ## S4 method for signature 'Maximize,missing' e1 - e2 ## S4 method for signature 'Maximize,Maximize' e1 + e2 ## S4 method for signature 'Maximize,Minimize' e1 + e2
## S4 method for signature 'Objective,numeric' e1 + e2 ## S4 method for signature 'numeric,Objective' e1 + e2 ## S4 method for signature 'Minimize,missing' e1 - e2 ## S4 method for signature 'Minimize,Minimize' e1 + e2 ## S4 method for signature 'Minimize,Maximize' e1 + e2 ## S4 method for signature 'Objective,Minimize' e1 - e2 ## S4 method for signature 'Objective,Maximize' e1 - e2 ## S4 method for signature 'Minimize,Objective' e1 - e2 ## S4 method for signature 'Maximize,Objective' e1 - e2 ## S4 method for signature 'Objective,numeric' e1 - e2 ## S4 method for signature 'numeric,Objective' e1 - e2 ## S4 method for signature 'Minimize,numeric' e1 * e2 ## S4 method for signature 'Maximize,numeric' e1 * e2 ## S4 method for signature 'numeric,Minimize' e1 * e2 ## S4 method for signature 'numeric,Maximize' e1 * e2 ## S4 method for signature 'Objective,numeric' e1 / e2 ## S4 method for signature 'Maximize,missing' e1 - e2 ## S4 method for signature 'Maximize,Maximize' e1 + e2 ## S4 method for signature 'Maximize,Minimize' e1 + e2
e1 |
|
e2 |
A Minimize or Maximize object.
This class represents an optimization objective.
Objective(expr) ## S4 method for signature 'Objective' value(object) ## S4 method for signature 'Objective' is_quadratic(object) ## S4 method for signature 'Objective' is_qpwa(object)
Objective(expr) ## S4 method for signature 'Objective' value(object) ## S4 method for signature 'Objective' is_quadratic(object) ## S4 method for signature 'Objective' is_qpwa(object)
expr |
A scalar Expression to optimize. |
object |
An Objective object. |
value(Objective)
: The value of the objective expression.
is_quadratic(Objective)
: Is the objective a quadratic function?
is_qpwa(Objective)
: Is the objective a quadratic of piecewise affine function?
expr
A scalar Expression to optimize.
The difference with domain
.
one_minus_pos(x)
one_minus_pos(x)
x |
An Expression, vector, or matrix. |
This atom is log-log concave.
An Expression representing one minus the input restricted to .
x <- Variable(pos = TRUE) y <- Variable(pos = TRUE) prob <- Problem(Maximize(one_minus_pos(x*y)), list(x <= 2 * y^2, y >= .2)) result <- solve(prob, gp = TRUE) result$value result$getValue(x) result$getValue(y)
x <- Variable(pos = TRUE) y <- Variable(pos = TRUE) prob <- Problem(Maximize(one_minus_pos(x*y)), list(x <= 2 * y^2, y >= .2)) result <- solve(prob, gp = TRUE) result$value result$getValue(x) result$getValue(y)
This class represents the difference with domain
}
OneMinusPos(x) ## S4 method for signature 'OneMinusPos' name(x) ## S4 method for signature 'OneMinusPos' to_numeric(object, values) ## S4 method for signature 'OneMinusPos' dim_from_args(object) ## S4 method for signature 'OneMinusPos' sign_from_args(object) ## S4 method for signature 'OneMinusPos' is_atom_convex(object) ## S4 method for signature 'OneMinusPos' is_atom_concave(object) ## S4 method for signature 'OneMinusPos' is_atom_log_log_convex(object) ## S4 method for signature 'OneMinusPos' is_atom_log_log_concave(object) ## S4 method for signature 'OneMinusPos' is_incr(object, idx) ## S4 method for signature 'OneMinusPos' is_decr(object, idx) ## S4 method for signature 'OneMinusPos' .grad(object, values)
OneMinusPos(x) ## S4 method for signature 'OneMinusPos' name(x) ## S4 method for signature 'OneMinusPos' to_numeric(object, values) ## S4 method for signature 'OneMinusPos' dim_from_args(object) ## S4 method for signature 'OneMinusPos' sign_from_args(object) ## S4 method for signature 'OneMinusPos' is_atom_convex(object) ## S4 method for signature 'OneMinusPos' is_atom_concave(object) ## S4 method for signature 'OneMinusPos' is_atom_log_log_convex(object) ## S4 method for signature 'OneMinusPos' is_atom_log_log_concave(object) ## S4 method for signature 'OneMinusPos' is_incr(object, idx) ## S4 method for signature 'OneMinusPos' is_decr(object, idx) ## S4 method for signature 'OneMinusPos' .grad(object, values)
x |
An Expression or numeric matrix. |
object |
A OneMinusPos object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
name(OneMinusPos)
: The name and arguments of the atom.
to_numeric(OneMinusPos)
: Returns one minus the value.
dim_from_args(OneMinusPos)
: The dimensions of the atom.
sign_from_args(OneMinusPos)
: Returns the sign (is positive, is negative) of the atom.
is_atom_convex(OneMinusPos)
: Is the atom convex?
is_atom_concave(OneMinusPos)
: Is the atom concave?
is_atom_log_log_convex(OneMinusPos)
: Is the atom log-log convex?
is_atom_log_log_concave(OneMinusPos)
: Is the atom log-log concave?
is_incr(OneMinusPos)
: Is the atom weakly increasing in the argument idx
?
is_decr(OneMinusPos)
: Is the atom weakly decreasing in the argument idx
?
.grad(OneMinusPos)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric matrix.
An interface for the OSQP solver.
OSQP() ## S4 method for signature 'OSQP' status_map(solver, status) ## S4 method for signature 'OSQP' name(x) ## S4 method for signature 'OSQP' import_solver(solver) ## S4 method for signature 'OSQP,list,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'OSQP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
OSQP() ## S4 method for signature 'OSQP' status_map(solver, status) ## S4 method for signature 'OSQP' name(x) ## S4 method for signature 'OSQP' import_solver(solver) ## S4 method for signature 'OSQP,list,InverseData' invert(object, solution, inverse_data) ## S4 method for signature 'OSQP' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A OSQP object. |
status |
A status code returned by the solver. |
solution |
The raw solution returned by the solver. |
inverse_data |
A InverseData object containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
status_map(OSQP)
: Converts status returned by the OSQP solver to its respective CVXPY status.
name(OSQP)
: Returns the name of the solver.
import_solver(OSQP)
: Imports the solver.
invert(object = OSQP, solution = list, inverse_data = InverseData)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(OSQP)
: Solve a problem represented by data returned from apply.
The vector p-norm. If given a matrix variable, p_norm
will treat it as a vector and compute the p-norm of the concatenated columns.
p_norm(x, p = 2, axis = NA_real_, keepdims = FALSE, max_denom = 1024)
p_norm(x, p = 2, axis = NA_real_, keepdims = FALSE, max_denom = 1024)
x |
An Expression, vector, or matrix. |
p |
A number greater than or equal to 1, or equal to positive infinity. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
max_denom |
(Optional) The maximum denominator considered in forming a rational approximation for |
For , the p-norm is given by
with domain .
For
, the p-norm is given by
with domain .
Note that the "p-norm" is actually a norm only when or
. For these cases, it is convex.
The expression is undefined when .
Otherwise, when , the expression is concave, but not a true norm.
An Expression representing the p-norm of the input.
x <- Variable(3) prob <- Problem(Minimize(p_norm(x,2))) result <- solve(prob) result$value result$getValue(x) prob <- Problem(Minimize(p_norm(x,Inf))) result <- solve(prob) result$value result$getValue(x) ## Not run: a <- c(1.0, 2, 3) prob <- Problem(Minimize(p_norm(x,1.6)), list(t(x) %*% a >= 1)) result <- solve(prob) result$value result$getValue(x) prob <- Problem(Minimize(sum(abs(x - a))), list(p_norm(x,-1) >= 0)) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
x <- Variable(3) prob <- Problem(Minimize(p_norm(x,2))) result <- solve(prob) result$value result$getValue(x) prob <- Problem(Minimize(p_norm(x,Inf))) result <- solve(prob) result$value result$getValue(x) ## Not run: a <- c(1.0, 2, 3) prob <- Problem(Minimize(p_norm(x,1.6)), list(t(x) %*% a >= 1)) result <- solve(prob) result$value result$getValue(x) prob <- Problem(Minimize(sum(abs(x - a))), list(p_norm(x,-1) >= 0)) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
This class represents a parameter, either scalar or a matrix.
Parameter( rows = NULL, cols = NULL, name = NA_character_, value = NA_real_, ... ) ## S4 method for signature 'Parameter' get_data(object) ## S4 method for signature 'Parameter' name(x) ## S4 method for signature 'Parameter' value(object) ## S4 replacement method for signature 'Parameter' value(object) <- value ## S4 method for signature 'Parameter' grad(object) ## S4 method for signature 'Parameter' parameters(object) ## S4 method for signature 'Parameter' canonicalize(object)
Parameter( rows = NULL, cols = NULL, name = NA_character_, value = NA_real_, ... ) ## S4 method for signature 'Parameter' get_data(object) ## S4 method for signature 'Parameter' name(x) ## S4 method for signature 'Parameter' value(object) ## S4 replacement method for signature 'Parameter' value(object) <- value ## S4 method for signature 'Parameter' grad(object) ## S4 method for signature 'Parameter' parameters(object) ## S4 method for signature 'Parameter' canonicalize(object)
rows |
The number of rows in the parameter. |
cols |
The number of columns in the parameter. |
name |
(Optional) A character string representing the name of the parameter. |
value |
(Optional) A numeric element, vector, matrix, or data.frame. Defaults to |
... |
Additional attribute arguments. See Leaf for details. |
object , x
|
A Parameter object. |
get_data(Parameter)
: Returns list(dim, name, value, attributes)
.
name(Parameter)
: The name of the parameter.
value(Parameter)
: The value of the parameter.
value(Parameter) <- value
: Set the value of the parameter.
grad(Parameter)
: An empty list since the gradient of a parameter is zero.
parameters(Parameter)
: Returns itself as a parameter.
canonicalize(Parameter)
: The canonical form of the parameter.
rows
The number of rows in the parameter.
cols
The number of columns in the parameter.
name
(Optional) A character string representing the name of the parameter.
value
(Optional) A numeric element, vector, matrix, or data.frame. Defaults to NA
and may be changed with value<-
later.
x <- Parameter(3, name = "x0", nonpos = TRUE) ## 3-vec negative is_nonneg(x) is_nonpos(x) size(x)
x <- Parameter(3, name = "x0", nonpos = TRUE) ## 3-vec negative is_nonneg(x) is_nonpos(x) size(x)
Performs the reduction on a problem and returns an equivalent problem.
perform(object, problem)
perform(object, problem)
object |
A Reduction object. |
problem |
A Problem on which the reduction will be performed. |
A list containing
A Problem or list representing the equivalent problem.
A InverseData or list containing the data needed to invert this particular reduction.
The Perron-Frobenius eigenvalue of a positive matrix.
pf_eigenvalue(X)
pf_eigenvalue(X)
X |
An Expression or positive square matrix. |
For an elementwise positive matrix , this atom represents its spectral radius, i.e., the magnitude of its largest eigenvalue.
Because
is positive, the spectral radius equals its largest eigenvalue, which is guaranteed to be positive.
This atom is log-log convex.
An Expression representing the largest eigenvalue of the input.
n <- 3 X <- Variable(n, n, pos=TRUE) objective_fn <- pf_eigenvalue(X) constraints <- list( X[1,1]== 1.0, X[1,3] == 1.9, X[2,2] == .8, X[3,1] == 3.2, X[3,2] == 5.9, X[1, 2] * X[2, 1] * X[2,3] * X[3,3] == 1) problem <- Problem(Minimize(objective_fn), constraints) result <- solve(problem, gp=TRUE) result$value result$getValue(X)
n <- 3 X <- Variable(n, n, pos=TRUE) objective_fn <- pf_eigenvalue(X) constraints <- list( X[1,1]== 1.0, X[1,3] == 1.9, X[2,2] == .8, X[3,1] == 3.2, X[3,2] == 5.9, X[1, 2] * X[2, 1] * X[2,3] * X[3,3] == 1) problem <- Problem(Minimize(objective_fn), constraints) result <- solve(problem, gp=TRUE) result$value result$getValue(X)
This class represents the Perron-Frobenius eigenvalue of a positive matrix.
PfEigenvalue(X) ## S4 method for signature 'PfEigenvalue' name(x) ## S4 method for signature 'PfEigenvalue' to_numeric(object, values) ## S4 method for signature 'PfEigenvalue' dim_from_args(object) ## S4 method for signature 'PfEigenvalue' sign_from_args(object) ## S4 method for signature 'PfEigenvalue' is_atom_convex(object) ## S4 method for signature 'PfEigenvalue' is_atom_concave(object) ## S4 method for signature 'PfEigenvalue' is_atom_log_log_convex(object) ## S4 method for signature 'PfEigenvalue' is_atom_log_log_concave(object) ## S4 method for signature 'PfEigenvalue' is_incr(object, idx) ## S4 method for signature 'PfEigenvalue' is_decr(object, idx) ## S4 method for signature 'PfEigenvalue' .grad(object, values)
PfEigenvalue(X) ## S4 method for signature 'PfEigenvalue' name(x) ## S4 method for signature 'PfEigenvalue' to_numeric(object, values) ## S4 method for signature 'PfEigenvalue' dim_from_args(object) ## S4 method for signature 'PfEigenvalue' sign_from_args(object) ## S4 method for signature 'PfEigenvalue' is_atom_convex(object) ## S4 method for signature 'PfEigenvalue' is_atom_concave(object) ## S4 method for signature 'PfEigenvalue' is_atom_log_log_convex(object) ## S4 method for signature 'PfEigenvalue' is_atom_log_log_concave(object) ## S4 method for signature 'PfEigenvalue' is_incr(object, idx) ## S4 method for signature 'PfEigenvalue' is_decr(object, idx) ## S4 method for signature 'PfEigenvalue' .grad(object, values)
X |
An Expression or numeric matrix. |
x , object
|
A PfEigenvalue object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
name(PfEigenvalue)
: The name and arguments of the atom.
to_numeric(PfEigenvalue)
: Returns the Perron-Frobenius eigenvalue of X
.
dim_from_args(PfEigenvalue)
: The dimensions of the atom.
sign_from_args(PfEigenvalue)
: Returns the sign (is positive, is negative) of the atom.
is_atom_convex(PfEigenvalue)
: Is the atom convex?
is_atom_concave(PfEigenvalue)
: Is the atom concave?
is_atom_log_log_convex(PfEigenvalue)
: Is the atom log-log convex?
is_atom_log_log_concave(PfEigenvalue)
: Is the atom log-log concave?
is_incr(PfEigenvalue)
: Is the atom weakly increasing in the argument idx
?
is_decr(PfEigenvalue)
: Is the atom weakly decreasing in the argument idx
?
.grad(PfEigenvalue)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
X
An Expression or numeric matrix.
This class represents the vector p-norm.
Pnorm(x, p = 2, axis = NA_real_, keepdims = FALSE, max_denom = 1024) ## S4 method for signature 'Pnorm' allow_complex(object) ## S4 method for signature 'Pnorm' to_numeric(object, values) ## S4 method for signature 'Pnorm' validate_args(object) ## S4 method for signature 'Pnorm' sign_from_args(object) ## S4 method for signature 'Pnorm' is_atom_convex(object) ## S4 method for signature 'Pnorm' is_atom_concave(object) ## S4 method for signature 'Pnorm' is_atom_log_log_convex(object) ## S4 method for signature 'Pnorm' is_atom_log_log_concave(object) ## S4 method for signature 'Pnorm' is_incr(object, idx) ## S4 method for signature 'Pnorm' is_decr(object, idx) ## S4 method for signature 'Pnorm' is_pwl(object) ## S4 method for signature 'Pnorm' get_data(object) ## S4 method for signature 'Pnorm' name(x) ## S4 method for signature 'Pnorm' .domain(object) ## S4 method for signature 'Pnorm' .grad(object, values) ## S4 method for signature 'Pnorm' .column_grad(object, value)
Pnorm(x, p = 2, axis = NA_real_, keepdims = FALSE, max_denom = 1024) ## S4 method for signature 'Pnorm' allow_complex(object) ## S4 method for signature 'Pnorm' to_numeric(object, values) ## S4 method for signature 'Pnorm' validate_args(object) ## S4 method for signature 'Pnorm' sign_from_args(object) ## S4 method for signature 'Pnorm' is_atom_convex(object) ## S4 method for signature 'Pnorm' is_atom_concave(object) ## S4 method for signature 'Pnorm' is_atom_log_log_convex(object) ## S4 method for signature 'Pnorm' is_atom_log_log_concave(object) ## S4 method for signature 'Pnorm' is_incr(object, idx) ## S4 method for signature 'Pnorm' is_decr(object, idx) ## S4 method for signature 'Pnorm' is_pwl(object) ## S4 method for signature 'Pnorm' get_data(object) ## S4 method for signature 'Pnorm' name(x) ## S4 method for signature 'Pnorm' .domain(object) ## S4 method for signature 'Pnorm' .grad(object, values) ## S4 method for signature 'Pnorm' .column_grad(object, value)
x |
An Expression representing a vector or matrix. |
p |
A number greater than or equal to 1, or equal to positive infinity. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
max_denom |
(Optional) The maximum denominator considered in forming a rational approximation for |
object |
A Pnorm object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value |
If given a matrix variable, Pnorm
will treat it as a vector and compute the p-norm of the concatenated columns.
For , the p-norm is given by
with domain .
For
, the p-norm is given by
with domain .
Note that the "p-norm" is actually a norm only when or
. For these cases, it is convex.
The expression is undefined when .
Otherwise, when , the expression is concave, but not a true norm.
allow_complex(Pnorm)
: Does the atom handle complex numbers?
to_numeric(Pnorm)
: The p-norm of x
.
validate_args(Pnorm)
: Check that the arguments are valid.
sign_from_args(Pnorm)
: The atom is positive.
is_atom_convex(Pnorm)
: The atom is convex if .
is_atom_concave(Pnorm)
: The atom is concave if .
is_atom_log_log_convex(Pnorm)
: Is the atom log-log convex?
is_atom_log_log_concave(Pnorm)
: Is the atom log-log concave?
is_incr(Pnorm)
: The atom is weakly increasing if or
and
x
is positive.
is_decr(Pnorm)
: The atom is weakly decreasing if and
x
is negative.
is_pwl(Pnorm)
: The atom is not piecewise linear unless or
.
get_data(Pnorm)
: Returns list(p, axis)
.
name(Pnorm)
: The name and arguments of the atom.
.domain(Pnorm)
: Returns constraints describing the domain of the node
.grad(Pnorm)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.column_grad(Pnorm)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
x
An Expression representing a vector or matrix.
p
A number greater than or equal to 1, or equal to positive infinity.
max_denom
The maximum denominator considered in forming a rational approximation for .
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
.approx_error
(Internal) The absolute difference between and its rational approximation.
.original_p
(Internal) The original input .
The elementwise positive portion of an expression, . This is equivalent to
max_elemwise(x,0)
.
pos(x)
pos(x)
x |
An Expression, vector, or matrix. |
An Expression representing the positive portion of the input.
x <- Variable(2) val <- matrix(c(-3,2)) prob <- Problem(Minimize(pos(x)[1]), list(x == val)) result <- solve(prob) result$value
x <- Variable(2) val <- matrix(c(-3,2)) prob <- Problem(Minimize(pos(x)[1]), list(x == val)) result <- solve(prob) result$value
An alias for MaxElemwise(x, 0)
Pos(x)
Pos(x)
x |
An R numeric value or Expression. |
An alias for MaxElemwise(x, 0)
This class represents the elementwise power function .
If
expr
is a CVXR expression, then expr^p
is equivalent to Power(expr, p)
.
Power(x, p, max_denom = 1024) ## S4 method for signature 'Power' to_numeric(object, values) ## S4 method for signature 'Power' sign_from_args(object) ## S4 method for signature 'Power' is_atom_convex(object) ## S4 method for signature 'Power' is_atom_concave(object) ## S4 method for signature 'Power' is_atom_log_log_convex(object) ## S4 method for signature 'Power' is_atom_log_log_concave(object) ## S4 method for signature 'Power' is_constant(object) ## S4 method for signature 'Power' is_incr(object, idx) ## S4 method for signature 'Power' is_decr(object, idx) ## S4 method for signature 'Power' is_quadratic(object) ## S4 method for signature 'Power' is_qpwa(object) ## S4 method for signature 'Power' .grad(object, values) ## S4 method for signature 'Power' .domain(object) ## S4 method for signature 'Power' get_data(object) ## S4 method for signature 'Power' copy(object, args = NULL, id_objects = list()) ## S4 method for signature 'Power' name(x)
Power(x, p, max_denom = 1024) ## S4 method for signature 'Power' to_numeric(object, values) ## S4 method for signature 'Power' sign_from_args(object) ## S4 method for signature 'Power' is_atom_convex(object) ## S4 method for signature 'Power' is_atom_concave(object) ## S4 method for signature 'Power' is_atom_log_log_convex(object) ## S4 method for signature 'Power' is_atom_log_log_concave(object) ## S4 method for signature 'Power' is_constant(object) ## S4 method for signature 'Power' is_incr(object, idx) ## S4 method for signature 'Power' is_decr(object, idx) ## S4 method for signature 'Power' is_quadratic(object) ## S4 method for signature 'Power' is_qpwa(object) ## S4 method for signature 'Power' .grad(object, values) ## S4 method for signature 'Power' .domain(object) ## S4 method for signature 'Power' get_data(object) ## S4 method for signature 'Power' copy(object, args = NULL, id_objects = list()) ## S4 method for signature 'Power' name(x)
x |
The Expression to be raised to a power. |
p |
A numeric value indicating the scalar power. |
max_denom |
The maximum denominator considered in forming a rational approximation of |
object |
A Power object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
args |
A list of arguments to reconstruct the atom. If args=NULL, use the current args of the atom |
id_objects |
Currently unused. |
For ,
, constant, positive.
For ,
, affine, increasing, same sign as
.
For ,
, convex, signed monotonicity, positive.
For and
for
, this function is convex, decreasing, and positive.
For and
for
, this function is concave, increasing, and positive.
For and
for
, this function is convex, increasing, and positive.
to_numeric(Power)
: Throw an error if the power is negative and cannot be handled.
sign_from_args(Power)
: The sign of the atom.
is_atom_convex(Power)
: Is or
?
is_atom_concave(Power)
: Is or
?
is_atom_log_log_convex(Power)
: Is the atom log-log convex?
is_atom_log_log_concave(Power)
: Is the atom log-log concave?
is_constant(Power)
: A logical value indicating whether the atom is constant.
is_incr(Power)
: A logical value indicating whether the atom is weakly increasing.
is_decr(Power)
: A logical value indicating whether the atom is weakly decreasing.
is_quadratic(Power)
: A logical value indicating whether the atom is quadratic.
is_qpwa(Power)
: A logical value indicating whether the atom is quadratic of piecewise affine.
.grad(Power)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
.domain(Power)
: Returns constraints describng the domain of the node
get_data(Power)
: A list containing the output of pow_low, pow_mid
, or pow_high
depending on the input power.
copy(Power)
: Returns a shallow copy of the power atom
name(Power)
: Returns the expression in string form.
x
The Expression to be raised to a power.
p
A numeric value indicating the scalar power.
max_denom
The maximum denominator considered in forming a rational approximation of p
.
Add, subtract, multiply, or divide DCP optimization problems.
## S4 method for signature 'Problem,missing' e1 + e2 ## S4 method for signature 'Problem,missing' e1 - e2 ## S4 method for signature 'Problem,numeric' e1 + e2 ## S4 method for signature 'numeric,Problem' e1 + e2 ## S4 method for signature 'Problem,Problem' e1 + e2 ## S4 method for signature 'Problem,numeric' e1 - e2 ## S4 method for signature 'numeric,Problem' e1 - e2 ## S4 method for signature 'Problem,Problem' e1 - e2 ## S4 method for signature 'Problem,numeric' e1 * e2 ## S4 method for signature 'numeric,Problem' e1 * e2 ## S4 method for signature 'Problem,numeric' e1 / e2
## S4 method for signature 'Problem,missing' e1 + e2 ## S4 method for signature 'Problem,missing' e1 - e2 ## S4 method for signature 'Problem,numeric' e1 + e2 ## S4 method for signature 'numeric,Problem' e1 + e2 ## S4 method for signature 'Problem,Problem' e1 + e2 ## S4 method for signature 'Problem,numeric' e1 - e2 ## S4 method for signature 'numeric,Problem' e1 - e2 ## S4 method for signature 'Problem,Problem' e1 - e2 ## S4 method for signature 'Problem,numeric' e1 * e2 ## S4 method for signature 'numeric,Problem' e1 * e2 ## S4 method for signature 'Problem,numeric' e1 / e2
e1 |
The left-hand Problem object. |
e2 |
The right-hand Problem object. |
A Problem object.
This class represents a convex optimization problem.
Problem(objective, constraints = list()) ## S4 method for signature 'Problem' objective(object) ## S4 replacement method for signature 'Problem' objective(object) <- value ## S4 method for signature 'Problem' constraints(object) ## S4 replacement method for signature 'Problem' constraints(object) <- value ## S4 method for signature 'Problem' value(object) ## S4 replacement method for signature 'Problem' value(object) <- value ## S4 method for signature 'Problem' status(object) ## S4 method for signature 'Problem' is_dcp(object) ## S4 method for signature 'Problem' is_dgp(object) ## S4 method for signature 'Problem' is_qp(object) ## S4 method for signature 'Problem' canonicalize(object) ## S4 method for signature 'Problem' is_mixed_integer(object) ## S4 method for signature 'Problem' variables(object) ## S4 method for signature 'Problem' parameters(object) ## S4 method for signature 'Problem' constants(object) ## S4 method for signature 'Problem' atoms(object) ## S4 method for signature 'Problem' size_metrics(object) ## S4 method for signature 'Problem' solver_stats(object) ## S4 replacement method for signature 'Problem' solver_stats(object) <- value ## S4 method for signature 'Problem,character,logical' get_problem_data(object, solver, gp) ## S4 method for signature 'Problem,character,missing' get_problem_data(object, solver, gp) ## S4 method for signature 'Problem' unpack_results(object, solution, chain, inverse_data)
Problem(objective, constraints = list()) ## S4 method for signature 'Problem' objective(object) ## S4 replacement method for signature 'Problem' objective(object) <- value ## S4 method for signature 'Problem' constraints(object) ## S4 replacement method for signature 'Problem' constraints(object) <- value ## S4 method for signature 'Problem' value(object) ## S4 replacement method for signature 'Problem' value(object) <- value ## S4 method for signature 'Problem' status(object) ## S4 method for signature 'Problem' is_dcp(object) ## S4 method for signature 'Problem' is_dgp(object) ## S4 method for signature 'Problem' is_qp(object) ## S4 method for signature 'Problem' canonicalize(object) ## S4 method for signature 'Problem' is_mixed_integer(object) ## S4 method for signature 'Problem' variables(object) ## S4 method for signature 'Problem' parameters(object) ## S4 method for signature 'Problem' constants(object) ## S4 method for signature 'Problem' atoms(object) ## S4 method for signature 'Problem' size_metrics(object) ## S4 method for signature 'Problem' solver_stats(object) ## S4 replacement method for signature 'Problem' solver_stats(object) <- value ## S4 method for signature 'Problem,character,logical' get_problem_data(object, solver, gp) ## S4 method for signature 'Problem,character,missing' get_problem_data(object, solver, gp) ## S4 method for signature 'Problem' unpack_results(object, solution, chain, inverse_data)
objective |
A Minimize or Maximize object representing the optimization objective. |
constraints |
(Optional) A list of Constraint objects representing constraints on the optimization variables. |
object |
A Problem class. |
value |
A Minimize or Maximize object (objective), list of Constraint objects (constraints), or numeric scalar (value). |
solver |
A string indicating the solver that the problem data is for. Call |
gp |
Is the problem a geometric problem? |
solution |
A Solution object. |
chain |
The corresponding solving Chain. |
inverse_data |
A InverseData object or list containing data necessary for the inversion. |
objective(Problem)
: The objective of the problem.
objective(Problem) <- value
: Set the value of the problem objective.
constraints(Problem)
: A list of the constraints of the problem.
constraints(Problem) <- value
: Set the value of the problem constraints.
value(Problem)
: The value from the last time the problem was solved (or NA if not solved).
value(Problem) <- value
: Set the value of the optimal objective.
status(Problem)
: The status from the last time the problem was solved.
is_dcp(Problem)
: A logical value indicating whether the problem statisfies DCP rules.
is_dgp(Problem)
: A logical value indicating whether the problem statisfies DGP rules.
is_qp(Problem)
: A logical value indicating whether the problem is a quadratic program.
canonicalize(Problem)
: The graph implementation of the problem.
is_mixed_integer(Problem)
: logical value indicating whether the problem is a mixed integer program.
variables(Problem)
: List of Variable objects in the problem.
parameters(Problem)
: List of Parameter objects in the problem.
constants(Problem)
: List of Constant objects in the problem.
atoms(Problem)
: List of Atom objects in the problem.
size_metrics(Problem)
: Information about the size of the problem.
solver_stats(Problem)
: Additional information returned by the solver.
solver_stats(Problem) <- value
: Set the additional information returned by the solver in the problem.
get_problem_data(object = Problem, solver = character, gp = logical)
: Get the problem data passed to the specified solver.
get_problem_data(object = Problem, solver = character, gp = missing)
: Get the problem data passed to the specified solver.
unpack_results(Problem)
: Parses the output from a solver and updates the problem state, including the status,
objective value, and values of the primal and dual variables.
Assumes the results are from the given solver.
objective
A Minimize or Maximize object representing the optimization objective.
constraints
(Optional) A list of constraints on the optimization variables.
value
(Internal) Used internally to hold the value of the optimization objective at the solution.
status
(Internal) Used internally to hold the status of the problem solution.
.cached_data
(Internal) Used internally to hold cached matrix data.
.separable_problems
(Internal) Used internally to hold separable problem data.
.size_metrics
(Internal) Used internally to hold size metrics.
.solver_stats
(Internal) Used internally to hold solver statistics.
x <- Variable(2) p <- Problem(Minimize(p_norm(x, 2)), list(x >= 0)) is_dcp(p) x <- Variable(2) A <- matrix(c(1,-1,-1, 1), nrow = 2) p <- Problem(Minimize(quad_form(x, A)), list(x >= 0)) is_qp(p)
x <- Variable(2) p <- Problem(Minimize(p_norm(x, 2)), list(x >= 0)) is_dcp(p) x <- Variable(2) A <- matrix(c(1,-1,-1, 1), nrow = 2) p <- Problem(Minimize(quad_form(x, A)), list(x >= 0)) is_qp(p)
Get and set the objective, constraints, or size metrics (get only) of a problem.
objective(object) objective(object) <- value constraints(object) constraints(object) <- value size_metrics(object)
objective(object) objective(object) <- value constraints(object) constraints(object) <- value size_metrics(object)
object |
A Problem object. |
value |
The value to assign to the slot. |
For getter functions, the requested slot of the object. x <- Variable() prob <- Problem(Minimize(x^2), list(x >= 5)) objective(prob) constraints(prob) size_metrics(prob)
objective(prob) <- Maximize(sqrt(x)) constraints(prob) <- list(x <= 10) objective(prob) constraints(prob)
The product of entries in a vector or matrix.
prod_entries(..., axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' prod(..., na.rm = FALSE)
prod_entries(..., axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' prod(..., na.rm = FALSE)
... |
Numeric scalar, vector, matrix, or Expression objects. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
na.rm |
(Unimplemented) A logical value indicating whether missing values should be removed. |
This atom is log-log affine, but it is neither convex nor concave.
An Expression representing the product of the entries of the input.
n <- 2 X <- Variable(n, n, pos=TRUE) obj <- sum(X) constraints <- list(prod_entries(X) == 4) prob <- Problem(Minimize(obj), constraints) result <- solve(prob, gp=TRUE) result$value result$getValue(X) n <- 2 X <- Variable(n, n, pos=TRUE) obj <- sum(X) constraints <- list(prod(X) == 4) prob <- Problem(Minimize(obj), constraints) result <- solve(prob, gp=TRUE) result$value
n <- 2 X <- Variable(n, n, pos=TRUE) obj <- sum(X) constraints <- list(prod_entries(X) == 4) prob <- Problem(Minimize(obj), constraints) result <- solve(prob, gp=TRUE) result$value result$getValue(X) n <- 2 X <- Variable(n, n, pos=TRUE) obj <- sum(X) constraints <- list(prod(X) == 4) prob <- Problem(Minimize(obj), constraints) result <- solve(prob, gp=TRUE) result$value
The product of the entries in an expression.
ProdEntries(..., axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'ProdEntries' to_numeric(object, values) ## S4 method for signature 'ProdEntries' sign_from_args(object) ## S4 method for signature 'ProdEntries' is_atom_convex(object) ## S4 method for signature 'ProdEntries' is_atom_concave(object) ## S4 method for signature 'ProdEntries' is_atom_log_log_convex(object) ## S4 method for signature 'ProdEntries' is_atom_log_log_concave(object) ## S4 method for signature 'ProdEntries' is_incr(object, idx) ## S4 method for signature 'ProdEntries' is_decr(object, idx) ## S4 method for signature 'ProdEntries' .column_grad(object, value) ## S4 method for signature 'ProdEntries' .grad(object, values)
ProdEntries(..., axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'ProdEntries' to_numeric(object, values) ## S4 method for signature 'ProdEntries' sign_from_args(object) ## S4 method for signature 'ProdEntries' is_atom_convex(object) ## S4 method for signature 'ProdEntries' is_atom_concave(object) ## S4 method for signature 'ProdEntries' is_atom_log_log_convex(object) ## S4 method for signature 'ProdEntries' is_atom_log_log_concave(object) ## S4 method for signature 'ProdEntries' is_incr(object, idx) ## S4 method for signature 'ProdEntries' is_decr(object, idx) ## S4 method for signature 'ProdEntries' .column_grad(object, value) ## S4 method for signature 'ProdEntries' .grad(object, values)
... |
Expression objects, vectors, or matrices. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A ProdEntries object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
value |
A numeric value. |
to_numeric(ProdEntries)
: The product of all the entries.
sign_from_args(ProdEntries)
: Returns the sign (is positive, is negative) of the atom.
is_atom_convex(ProdEntries)
: Is the atom convex?
is_atom_concave(ProdEntries)
: Is the atom concave?
is_atom_log_log_convex(ProdEntries)
: Is the atom log-log convex?
is_atom_log_log_concave(ProdEntries)
: is the atom log-log concave?
is_incr(ProdEntries)
: Is the atom weakly increasing in the argument idx
?
is_decr(ProdEntries)
: Is the atom weakly decreasing in the argument idx
?
.column_grad(ProdEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each column variable
.grad(ProdEntries)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
expr
An Expression representing a vector or matrix.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
Project a value onto the attribute set of a Leaf.
A sensible idiom is value(leaf) = project(leaf, val)
.
project(object, value) project_and_assign(object, value)
project(object, value) project_and_assign(object, value)
object |
A Leaf object. |
value |
The assigned value. |
The value rounded to the attribute type.
This class represents the promotion of a scalar expression into a vector/matrix.
Promote(expr, promoted_dim) ## S4 method for signature 'Promote' to_numeric(object, values) ## S4 method for signature 'Promote' is_symmetric(object) ## S4 method for signature 'Promote' dim_from_args(object) ## S4 method for signature 'Promote' is_atom_log_log_convex(object) ## S4 method for signature 'Promote' is_atom_log_log_concave(object) ## S4 method for signature 'Promote' get_data(object) ## S4 method for signature 'Promote' graph_implementation(object, arg_objs, dim, data = NA_real_)
Promote(expr, promoted_dim) ## S4 method for signature 'Promote' to_numeric(object, values) ## S4 method for signature 'Promote' is_symmetric(object) ## S4 method for signature 'Promote' dim_from_args(object) ## S4 method for signature 'Promote' is_atom_log_log_convex(object) ## S4 method for signature 'Promote' is_atom_log_log_concave(object) ## S4 method for signature 'Promote' get_data(object) ## S4 method for signature 'Promote' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression or numeric constant. |
promoted_dim |
The desired dimensions. |
object |
A Promote object. |
values |
A list containing the value to promote. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Promote)
: Promotes the value to the new dimensions.
is_symmetric(Promote)
: Is the expression symmetric?
dim_from_args(Promote)
: Returns the (row, col) dimensions of the expression.
is_atom_log_log_convex(Promote)
: Is the atom log-log convex?
is_atom_log_log_concave(Promote)
: Is the atom log-log concave?
get_data(Promote)
: Returns information needed to reconstruct the expression besides the args.
graph_implementation(Promote)
: The graph implementation of the atom.
expr
An Expression or numeric constant.
promoted_dim
The desired dimensions.
Given a problem returns a PSD constraint
psd_coeff_offset(problem, c)
psd_coeff_offset(problem, c)
problem |
A Problem object. |
c |
A vector of coefficients. |
Returns an array G and vector h such that the given constraint is
equivalent to .
A no-op wrapper to assert the input argument is positive semidefinite.
PSDWrap(arg) ## S4 method for signature 'PSDWrap' is_psd(object)
PSDWrap(arg) ## S4 method for signature 'PSDWrap' is_psd(object)
arg |
A Expression object or matrix. |
object |
A PSDWrap object. |
is_psd(PSDWrap)
: Is the atom positive semidefinite?
Solve a DCP compliant optimization problem.
psolve( object, solver = NA, ignore_dcp = FALSE, warm_start = FALSE, verbose = FALSE, parallel = FALSE, gp = FALSE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... ) ## S4 method for signature 'Problem' psolve( object, solver = NA, ignore_dcp = FALSE, warm_start = FALSE, verbose = FALSE, parallel = FALSE, gp = FALSE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... ) ## S4 method for signature 'Problem,ANY' solve(a, b = NA, ...)
psolve( object, solver = NA, ignore_dcp = FALSE, warm_start = FALSE, verbose = FALSE, parallel = FALSE, gp = FALSE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... ) ## S4 method for signature 'Problem' psolve( object, solver = NA, ignore_dcp = FALSE, warm_start = FALSE, verbose = FALSE, parallel = FALSE, gp = FALSE, feastol = NULL, reltol = NULL, abstol = NULL, num_iter = NULL, ... ) ## S4 method for signature 'Problem,ANY' solve(a, b = NA, ...)
object , a
|
A Problem object. |
solver , b
|
(Optional) A string indicating the solver to use. Defaults to "ECOS". |
ignore_dcp |
(Optional) A logical value indicating whether to override the DCP check for a problem. |
warm_start |
(Optional) A logical value indicating whether the previous solver result should be used to warm start. |
verbose |
(Optional) A logical value indicating whether to print additional solver output. |
parallel |
(Optional) A logical value indicating whether to solve in parallel if the problem is separable. |
gp |
(Optional) A logical value indicating whether the problem is a geometric program. Defaults to |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
... |
Additional options that will be passed to the specific solver. In general, these options will override any default settings imposed by CVXR. |
A list containing the solution to the problem:
status
The status of the solution. Can be "optimal", "optimal_inaccurate", "infeasible", "infeasible_inaccurate", "unbounded", "unbounded_inaccurate", or "solver_error".
value
The optimal value of the objective function.
solver
The name of the solver.
solve_time
The time (in seconds) it took for the solver to solve the problem.
setup_time
The time (in seconds) it took for the solver to set up the problem.
num_iters
The number of iterations the solver had to go through to find a solution.
getValue
A function that takes a Variable object and retrieves its primal value.
getDualValue
A function that takes a Constraint object and retrieves its dual value(s).
a <- Variable(name = "a") prob <- Problem(Minimize(norm_inf(a)), list(a >= 2)) result <- psolve(prob, solver = "ECOS", verbose = TRUE) result$status result$value result$getValue(a) result$getDualValue(constraints(prob)[[1]])
a <- Variable(name = "a") prob <- Problem(Minimize(norm_inf(a)), list(a >= 2)) result <- psolve(prob, solver = "ECOS", verbose = TRUE) result$status result$value result$getValue(a) result$getDualValue(constraints(prob)[[1]])
This class reduces a quadratic problem to a problem that consists of affine expressions and symbolic quadratic forms.
This class fills in numeric values for the problem instance and outputs a DCP-compliant minimization problem with an objective of the form
QuadForm(x, p) + t(q)
and Zero/NonPos constraints, both of which exclusively carry affine arguments
A QP solver interface.
## S4 method for signature 'QpSolver,Problem' accepts(object, problem) ## S4 method for signature 'QpSolver,Problem' perform(object, problem)
## S4 method for signature 'QpSolver,Problem' accepts(object, problem) ## S4 method for signature 'QpSolver,Problem' perform(object, problem)
object |
A QpSolver object. |
problem |
A Problem object. |
accepts(object = QpSolver, problem = Problem)
: Is this a QP problem?
perform(object = QpSolver, problem = Problem)
: Constructs a QP problem data stored in a list
The quadratic form, .
quad_form(x, P)
quad_form(x, P)
x |
An Expression or vector. |
P |
An Expression or matrix. |
An Expression representing the quadratic form evaluated at the input.
x <- Variable(2) P <- rbind(c(4,0), c(0,9)) prob <- Problem(Minimize(quad_form(x,P)), list(x >= 1)) result <- solve(prob) result$value result$getValue(x) A <- Variable(2,2) c <- c(1,2) prob <- Problem(Minimize(quad_form(c,A)), list(A >= 1)) result <- solve(prob) result$value result$getValue(A)
x <- Variable(2) P <- rbind(c(4,0), c(0,9)) prob <- Problem(Minimize(quad_form(x,P)), list(x >= 1)) result <- solve(prob) result$value result$getValue(x) A <- Variable(2,2) c <- c(1,2) prob <- Problem(Minimize(quad_form(c,A)), list(A >= 1)) result <- solve(prob) result$value result$getValue(A)
.
quad_over_lin(x, y)
quad_over_lin(x, y)
x |
An Expression, vector, or matrix. |
y |
A scalar Expression or numeric constant. |
An Expression representing the quadratic over linear function value evaluated at the input.
x <- Variable(3,2) y <- Variable() val <- cbind(c(-1,2,-2), c(-1,2,-2)) prob <- Problem(Minimize(quad_over_lin(x,y)), list(x == val, y <= 2)) result <- solve(prob) result$value result$getValue(x) result$getValue(y)
x <- Variable(3,2) y <- Variable() val <- cbind(c(-1,2,-2), c(-1,2,-2)) prob <- Problem(Minimize(quad_over_lin(x,y)), list(x == val, y <= 2)) result <- solve(prob) result$value result$getValue(x) result$getValue(y)
This class represents the quadratic form
QuadForm(x, P) ## S4 method for signature 'QuadForm' name(x) ## S4 method for signature 'QuadForm' allow_complex(object) ## S4 method for signature 'QuadForm' to_numeric(object, values) ## S4 method for signature 'QuadForm' validate_args(object) ## S4 method for signature 'QuadForm' sign_from_args(object) ## S4 method for signature 'QuadForm' dim_from_args(object) ## S4 method for signature 'QuadForm' is_atom_convex(object) ## S4 method for signature 'QuadForm' is_atom_concave(object) ## S4 method for signature 'QuadForm' is_atom_log_log_convex(object) ## S4 method for signature 'QuadForm' is_atom_log_log_concave(object) ## S4 method for signature 'QuadForm' is_incr(object, idx) ## S4 method for signature 'QuadForm' is_decr(object, idx) ## S4 method for signature 'QuadForm' is_quadratic(object) ## S4 method for signature 'QuadForm' is_pwl(object) ## S4 method for signature 'QuadForm' .grad(object, values)
QuadForm(x, P) ## S4 method for signature 'QuadForm' name(x) ## S4 method for signature 'QuadForm' allow_complex(object) ## S4 method for signature 'QuadForm' to_numeric(object, values) ## S4 method for signature 'QuadForm' validate_args(object) ## S4 method for signature 'QuadForm' sign_from_args(object) ## S4 method for signature 'QuadForm' dim_from_args(object) ## S4 method for signature 'QuadForm' is_atom_convex(object) ## S4 method for signature 'QuadForm' is_atom_concave(object) ## S4 method for signature 'QuadForm' is_atom_log_log_convex(object) ## S4 method for signature 'QuadForm' is_atom_log_log_concave(object) ## S4 method for signature 'QuadForm' is_incr(object, idx) ## S4 method for signature 'QuadForm' is_decr(object, idx) ## S4 method for signature 'QuadForm' is_quadratic(object) ## S4 method for signature 'QuadForm' is_pwl(object) ## S4 method for signature 'QuadForm' .grad(object, values)
x |
An Expression or numeric vector. |
P |
An Expression, numeric matrix, or vector. |
object |
A QuadForm object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
name(QuadForm)
: The name and arguments of the atom.
allow_complex(QuadForm)
: Does the atom handle complex numbers?
to_numeric(QuadForm)
: Returns the quadratic form.
validate_args(QuadForm)
: Checks the dimensions of the arguments.
sign_from_args(QuadForm)
: Returns the sign (is positive, is negative) of the atom.
dim_from_args(QuadForm)
: The dimensions of the atom.
is_atom_convex(QuadForm)
: Is the atom convex?
is_atom_concave(QuadForm)
: Is the atom concave?
is_atom_log_log_convex(QuadForm)
: Is the atom log-log convex?
is_atom_log_log_concave(QuadForm)
: Is the atom log-log concave?
is_incr(QuadForm)
: Is the atom weakly increasing in the argument idx
?
is_decr(QuadForm)
: Is the atom weakly decreasing in the argument idx
?
is_quadratic(QuadForm)
: Is the atom quadratic?
is_pwl(QuadForm)
: Is the atom piecewise linear?
.grad(QuadForm)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric vector.
P
An Expression, numeric matrix, or vector.
This class represents the sum of squared entries in X divided by a scalar y, .
QuadOverLin(x, y) ## S4 method for signature 'QuadOverLin' allow_complex(object) ## S4 method for signature 'QuadOverLin' to_numeric(object, values) ## S4 method for signature 'QuadOverLin' validate_args(object) ## S4 method for signature 'QuadOverLin' dim_from_args(object) ## S4 method for signature 'QuadOverLin' sign_from_args(object) ## S4 method for signature 'QuadOverLin' is_atom_convex(object) ## S4 method for signature 'QuadOverLin' is_atom_concave(object) ## S4 method for signature 'QuadOverLin' is_atom_log_log_convex(object) ## S4 method for signature 'QuadOverLin' is_atom_log_log_concave(object) ## S4 method for signature 'QuadOverLin' is_incr(object, idx) ## S4 method for signature 'QuadOverLin' is_decr(object, idx) ## S4 method for signature 'QuadOverLin' is_quadratic(object) ## S4 method for signature 'QuadOverLin' is_qpwa(object) ## S4 method for signature 'QuadOverLin' .domain(object) ## S4 method for signature 'QuadOverLin' .grad(object, values)
QuadOverLin(x, y) ## S4 method for signature 'QuadOverLin' allow_complex(object) ## S4 method for signature 'QuadOverLin' to_numeric(object, values) ## S4 method for signature 'QuadOverLin' validate_args(object) ## S4 method for signature 'QuadOverLin' dim_from_args(object) ## S4 method for signature 'QuadOverLin' sign_from_args(object) ## S4 method for signature 'QuadOverLin' is_atom_convex(object) ## S4 method for signature 'QuadOverLin' is_atom_concave(object) ## S4 method for signature 'QuadOverLin' is_atom_log_log_convex(object) ## S4 method for signature 'QuadOverLin' is_atom_log_log_concave(object) ## S4 method for signature 'QuadOverLin' is_incr(object, idx) ## S4 method for signature 'QuadOverLin' is_decr(object, idx) ## S4 method for signature 'QuadOverLin' is_quadratic(object) ## S4 method for signature 'QuadOverLin' is_qpwa(object) ## S4 method for signature 'QuadOverLin' .domain(object) ## S4 method for signature 'QuadOverLin' .grad(object, values)
x |
An Expression or numeric matrix. |
y |
A scalar Expression or numeric constant. |
object |
A QuadOverLin object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
allow_complex(QuadOverLin)
: Does the atom handle complex numbers?
to_numeric(QuadOverLin)
: The sum of the entries of x
squared over y
.
validate_args(QuadOverLin)
: Check the dimensions of the arguments.
dim_from_args(QuadOverLin)
: The atom is a scalar.
sign_from_args(QuadOverLin)
: The atom is positive.
is_atom_convex(QuadOverLin)
: The atom is convex.
is_atom_concave(QuadOverLin)
: The atom is not concave.
is_atom_log_log_convex(QuadOverLin)
: Is the atom log-log convex?
is_atom_log_log_concave(QuadOverLin)
: Is the atom log-log concave?
is_incr(QuadOverLin)
: A logical value indicating whether the atom is weakly increasing in argument idx
.
is_decr(QuadOverLin)
: A logical value indicating whether the atom is weakly decreasing in argument idx
.
is_quadratic(QuadOverLin)
: Quadratic if x
is affine and y
is constant.
is_qpwa(QuadOverLin)
: Quadratic of piecewise affine if x
is piecewise linear and y
is constant.
.domain(QuadOverLin)
: Returns constraints describing the domain of the node
.grad(QuadOverLin)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric matrix.
y
A scalar Expression or numeric constant.
A simple, internal dictionary composed of a list of keys and a list of values. These keys/values can be any type, including nested lists, S4 objects, etc. Incredibly inefficient hack, but necessary for the geometric mean atom, since it requires mixed numeric/gmp objects.
Rdict(keys = list(), values = list()) ## S4 method for signature 'Rdict' x$name ## S4 method for signature 'Rdict' length(x) ## S4 method for signature 'ANY,Rdict' is.element(el, set) ## S4 method for signature 'Rdict,ANY,ANY,ANY' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'Rdict,ANY,ANY,ANY' x[i, j, ...] <- value
Rdict(keys = list(), values = list()) ## S4 method for signature 'Rdict' x$name ## S4 method for signature 'Rdict' length(x) ## S4 method for signature 'ANY,Rdict' is.element(el, set) ## S4 method for signature 'Rdict,ANY,ANY,ANY' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'Rdict,ANY,ANY,ANY' x[i, j, ...] <- value
keys |
A list of keys. |
values |
A list of values corresponding to the keys. |
x , set
|
A Rdict object. |
name |
Either "keys" for a list of keys, "values" for a list of values, or "items" for a list of lists where each nested list is a (key, value) pair. |
el |
The element to search the dictionary of values for. |
i |
A key into the dictionary. |
j , drop , ...
|
Unused arguments. |
value |
The value to assign to key |
keys
A list of keys.
values
A list of values corresponding to the keys.
This is a subclass of Rdict that contains an additional slot for a default function, which assigns a value to an input key. Only partially implemented, but working well enough for the geometric mean. Will be combined with Rdict later.
Rdictdefault(keys = list(), values = list(), default) ## S4 method for signature 'Rdictdefault,ANY,ANY,ANY' x[i, j, ..., drop = TRUE]
Rdictdefault(keys = list(), values = list(), default) ## S4 method for signature 'Rdictdefault,ANY,ANY,ANY' x[i, j, ..., drop = TRUE]
keys |
A list of keys. |
values |
A list of values corresponding to the keys. |
default |
A function that takes as input a key and outputs a value to assign to that key. |
x |
A Rdictdefault object. |
i |
A key into the dictionary. |
j , drop , ...
|
Unused arguments. |
keys
A list of keys.
values
A list of values corresponding to the keys.
default
A function that takes as input a key and outputs a value to assign to that key.
This class represents the real part of an expression.
Real(expr) ## S4 method for signature 'Real' to_numeric(object, values) ## S4 method for signature 'Real' dim_from_args(object) ## S4 method for signature 'Real' is_imag(object) ## S4 method for signature 'Real' is_complex(object) ## S4 method for signature 'Real' is_symmetric(object)
Real(expr) ## S4 method for signature 'Real' to_numeric(object, values) ## S4 method for signature 'Real' dim_from_args(object) ## S4 method for signature 'Real' is_imag(object) ## S4 method for signature 'Real' is_complex(object) ## S4 method for signature 'Real' is_symmetric(object)
expr |
An Expression representing a vector or matrix. |
object |
An Real object. |
values |
A list of arguments to the atom. |
to_numeric(Real)
: The imaginary part of the given value.
dim_from_args(Real)
: The dimensions of the atom.
is_imag(Real)
: Is the atom imaginary?
is_complex(Real)
: Is the atom complex valued?
is_symmetric(Real)
: Is the atom symmetric?
expr
An Expression representing a vector or matrix.
Reduces the owned problem to an equivalent problem.
reduce(object)
reduce(object)
object |
A Reduction object. |
An equivalent problem, encoded either as a Problem object or a list.
This virtual class represents a reduction, an actor that transforms a problem
into an equivalent problem. By equivalent, we mean that there exists a mapping
between solutions of either problem: if we reduce a problem to another
problem
and then proceed to find a solution to
, we can convert
it to a solution of
with at most a moderate amount of effort.
## S4 method for signature 'Reduction,Problem' accepts(object, problem) ## S4 method for signature 'Reduction' reduce(object) ## S4 method for signature 'Reduction,Solution' retrieve(object, solution) ## S4 method for signature 'Reduction,Problem' perform(object, problem) ## S4 method for signature 'Reduction,Solution,list' invert(object, solution, inverse_data)
## S4 method for signature 'Reduction,Problem' accepts(object, problem) ## S4 method for signature 'Reduction' reduce(object) ## S4 method for signature 'Reduction,Solution' retrieve(object, solution) ## S4 method for signature 'Reduction,Problem' perform(object, problem) ## S4 method for signature 'Reduction,Solution,list' invert(object, solution, inverse_data)
object |
A Reduction object. |
problem |
A Problem object. |
solution |
A Solution to a problem that generated the inverse data. |
inverse_data |
The data encoding the original problem. |
Every reduction supports three methods: accepts, perform, and invert. The accepts method of a particular reduction codifies the types of problems that it is applicable to, the perform method takes a problem and reduces it to a (new) equivalent form, and the invert method maps solutions from reduced-to problems to their problems of provenance.
accepts(object = Reduction, problem = Problem)
: States whether the reduction accepts a problem.
reduce(Reduction)
: Reduces the owned problem to an equivalent problem.
retrieve(object = Reduction, solution = Solution)
: Retrieves a solution to the owned problem.
perform(object = Reduction, problem = Problem)
: Performs the reduction on a problem and returns an equivalent problem.
invert(object = Reduction, solution = Solution, inverse_data = list)
: Returns a solution to the original problem given the inverse data.
The ReductionSolver class.
## S4 method for signature 'ReductionSolver' mip_capable(solver) ## S4 method for signature 'ReductionSolver' name(x) ## S4 method for signature 'ReductionSolver' import_solver(solver) ## S4 method for signature 'ReductionSolver' is_installed(solver) ## S4 method for signature 'ReductionSolver' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'ReductionSolver,ANY' reduction_solve( object, problem, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts ) ## S4 method for signature 'ECOS' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
## S4 method for signature 'ReductionSolver' mip_capable(solver) ## S4 method for signature 'ReductionSolver' name(x) ## S4 method for signature 'ReductionSolver' import_solver(solver) ## S4 method for signature 'ReductionSolver' is_installed(solver) ## S4 method for signature 'ReductionSolver' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache ) ## S4 method for signature 'ReductionSolver,ANY' reduction_solve( object, problem, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts ) ## S4 method for signature 'ECOS' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A ReductionSolver object. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
An integer number indicating level of solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
problem |
A Problem object. |
mip_capable(ReductionSolver)
: Can the solver handle mixed-integer programs?
name(ReductionSolver)
: Returns the name of the solver
import_solver(ReductionSolver)
: Imports the solver
is_installed(ReductionSolver)
: Is the solver installed?
solve_via_data(ReductionSolver)
: Solve a problem represented by data returned from apply.
reduction_solve(object = ReductionSolver, problem = ANY)
: Solve a problem represented by data returned from apply.
solve_via_data(ECOS)
: Solve a problem represented by data returned from apply.
Reset the global package variable .CVXR.options
.
resetOptions()
resetOptions()
The default value of CVXR package global .CVXR.options
.
## Not run: resetOptions() ## End(Not run)
## Not run: resetOptions() ## End(Not run)
This function vectorizes an expression, then unvectorizes it into a new shape. Entries are stored in column-major order.
reshape_expr(expr, new_dim)
reshape_expr(expr, new_dim)
expr |
An Expression, vector, or matrix. |
new_dim |
The new dimensions. |
An Expression representing the reshaped input.
x <- Variable(4) mat <- cbind(c(1,-1), c(2,-2)) vec <- matrix(1:4) expr <- reshape_expr(x,c(2,2)) obj <- Minimize(sum(mat %*% expr)) prob <- Problem(obj, list(x == vec)) result <- solve(prob) result$value A <- Variable(2,2) c <- 1:4 expr <- reshape_expr(A,c(4,1)) obj <- Minimize(t(expr) %*% c) constraints <- list(A == cbind(c(-1,-2), c(3,4))) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(expr) result$getValue(reshape_expr(expr,c(2,2))) C <- Variable(3,2) expr <- reshape_expr(C,c(2,3)) mat <- rbind(c(1,-1), c(2,-2)) C_mat <- rbind(c(1,4), c(2,5), c(3,6)) obj <- Minimize(sum(mat %*% expr)) prob <- Problem(obj, list(C == C_mat)) result <- solve(prob) result$value result$getValue(expr) a <- Variable() c <- cbind(c(1,-1), c(2,-2)) expr <- reshape_expr(c * a,c(1,4)) obj <- Minimize(expr %*% (1:4)) prob <- Problem(obj, list(a == 2)) result <- solve(prob) result$value result$getValue(expr) expr <- reshape_expr(c * a,c(4,1)) obj <- Minimize(t(expr) %*% (1:4)) prob <- Problem(obj, list(a == 2)) result <- solve(prob) result$value result$getValue(expr)
x <- Variable(4) mat <- cbind(c(1,-1), c(2,-2)) vec <- matrix(1:4) expr <- reshape_expr(x,c(2,2)) obj <- Minimize(sum(mat %*% expr)) prob <- Problem(obj, list(x == vec)) result <- solve(prob) result$value A <- Variable(2,2) c <- 1:4 expr <- reshape_expr(A,c(4,1)) obj <- Minimize(t(expr) %*% c) constraints <- list(A == cbind(c(-1,-2), c(3,4))) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(expr) result$getValue(reshape_expr(expr,c(2,2))) C <- Variable(3,2) expr <- reshape_expr(C,c(2,3)) mat <- rbind(c(1,-1), c(2,-2)) C_mat <- rbind(c(1,4), c(2,5), c(3,6)) obj <- Minimize(sum(mat %*% expr)) prob <- Problem(obj, list(C == C_mat)) result <- solve(prob) result$value result$getValue(expr) a <- Variable() c <- cbind(c(1,-1), c(2,-2)) expr <- reshape_expr(c * a,c(1,4)) obj <- Minimize(expr %*% (1:4)) prob <- Problem(obj, list(a == 2)) result <- solve(prob) result$value result$getValue(expr) expr <- reshape_expr(c * a,c(4,1)) obj <- Minimize(t(expr) %*% (1:4)) prob <- Problem(obj, list(a == 2)) result <- solve(prob) result$value result$getValue(expr)
This class represents the reshaping of an expression. The operator vectorizes the expression, then unvectorizes it into the new dimensions. Entries are stored in column-major order.
Reshape(expr, new_dim) ## S4 method for signature 'Reshape' to_numeric(object, values) ## S4 method for signature 'Reshape' validate_args(object) ## S4 method for signature 'Reshape' dim_from_args(object) ## S4 method for signature 'Reshape' is_atom_log_log_convex(object) ## S4 method for signature 'Reshape' is_atom_log_log_concave(object) ## S4 method for signature 'Reshape' get_data(object) ## S4 method for signature 'Reshape' graph_implementation(object, arg_objs, dim, data = NA_real_)
Reshape(expr, new_dim) ## S4 method for signature 'Reshape' to_numeric(object, values) ## S4 method for signature 'Reshape' validate_args(object) ## S4 method for signature 'Reshape' dim_from_args(object) ## S4 method for signature 'Reshape' is_atom_log_log_convex(object) ## S4 method for signature 'Reshape' is_atom_log_log_concave(object) ## S4 method for signature 'Reshape' get_data(object) ## S4 method for signature 'Reshape' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression or numeric matrix. |
new_dim |
The new dimensions. |
object |
A Reshape object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Reshape)
: Reshape the value into the specified dimensions.
validate_args(Reshape)
: Check the new shape has the same number of entries as the old.
dim_from_args(Reshape)
: The c(rows, cols)
dimensions of the new expression.
is_atom_log_log_convex(Reshape)
: Is the atom log-log convex?
is_atom_log_log_concave(Reshape)
: Is the atom log-log concave?
get_data(Reshape)
: Returns a list containing the new shape.
graph_implementation(Reshape)
: The graph implementation of the atom.
expr
An Expression or numeric matrix.
new_dim
The new dimensions.
The residual expression of a constraint, i.e. the amount by which it is violated, and the value of that violation.
For instance, if our constraint is , the residual is
applied elementwise.
residual(object) violation(object)
residual(object) violation(object)
object |
A Constraint object. |
A Expression representing the residual, or the value of this expression.
Retrieves a solution to the owned problem.
retrieve(object, solution)
retrieve(object, solution)
object |
A Reduction object. |
solution |
A Solution object. |
A Solution to the problem emitted by reduce
.
Utility methods for special handling of semidefinite constraints.
scaled_lower_tri(matrix)
scaled_lower_tri(matrix)
matrix |
The matrix to get the lower triangular matrix for |
The lower triangular part of the matrix, stacked in column-major order
Utility methods for special handling of semidefinite constraints.
scaled_upper_tri(matrix)
scaled_upper_tri(matrix)
matrix |
The matrix to get the upper triangular matrix for |
The upper triangular part of the matrix, stacked in column-major order
The elementwise weighted sum of the positive and negative portions of an expression, .
This is equivalent to
alpha*pos(x) + beta*neg(x)
.
scalene(x, alpha, beta)
scalene(x, alpha, beta)
x |
An Expression, vector, or matrix. |
alpha |
The weight on the positive portion of |
beta |
The weight on othe negative portion of |
An Expression representing the scalene function evaluated at the input.
## Not run: A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(scalene(A,2,3)[1,1]), list(A == val)) result <- solve(prob) result$value result$getValue(scalene(A, 0.7, 0.3)) ## End(Not run)
## Not run: A <- Variable(2,2) val <- cbind(c(-5,2), c(-3,1)) prob <- Problem(Minimize(scalene(A,2,3)[1,1]), list(A == val)) result <- solve(prob) result$value result$getValue(scalene(A, 0.7, 0.3)) ## End(Not run)
An interface for the SCS solver
SCS() ## S4 method for signature 'SCS' mip_capable(solver) ## S4 method for signature 'SCS' status_map(solver, status) ## S4 method for signature 'SCS' name(x) ## S4 method for signature 'SCS' import_solver(solver) ## S4 method for signature 'SCS' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'SCS,Problem' perform(object, problem) ## S4 method for signature 'SCS,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'SCS' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
SCS() ## S4 method for signature 'SCS' mip_capable(solver) ## S4 method for signature 'SCS' status_map(solver, status) ## S4 method for signature 'SCS' name(x) ## S4 method for signature 'SCS' import_solver(solver) ## S4 method for signature 'SCS' reduction_format_constr(object, problem, constr, exp_cone_order) ## S4 method for signature 'SCS,Problem' perform(object, problem) ## S4 method for signature 'SCS,list,list' invert(object, solution, inverse_data) ## S4 method for signature 'SCS' solve_via_data( object, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts, solver_cache )
solver , object , x
|
A SCS object. |
status |
A status code returned by the solver. |
problem |
A Problem object. |
constr |
A Constraint to format. |
exp_cone_order |
A list indicating how the exponential cone arguments are ordered. |
solution |
The raw solution returned by the solver. |
inverse_data |
A list containing data necessary for the inversion. |
data |
Data generated via an apply call. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance on the primal and dual residual. |
reltol |
The relative tolerance on the duality gap. |
abstol |
The absolute tolerance on the duality gap. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
solver_cache |
Cache for the solver. |
mip_capable(SCS)
: Can the solver handle mixed-integer programs?
status_map(SCS)
: Converts status returned by SCS solver to its respective CVXPY status.
name(SCS)
: Returns the name of the solver
import_solver(SCS)
: Imports the solver
reduction_format_constr(SCS)
: Return a linear operator to multiply by PSD constraint coefficients.
perform(object = SCS, problem = Problem)
: Returns a new problem and data for inverting the new solution
invert(object = SCS, solution = list, inverse_data = list)
: Returns the solution to the original problem given the inverse_data.
solve_via_data(SCS)
: Solve a problem represented by data returned from apply.
Utility method for formatting a ConeDims instance into a dictionary that can be supplied to SCS.
SCS.dims_to_solver_dict(cone_dims)
SCS.dims_to_solver_dict(cone_dims)
cone_dims |
A ConeDims instance. |
The dimensions of the cones.
Special cases PSD constraints, as per the SCS specification.
SCS.extract_dual_value(result_vec, offset, constraint)
SCS.extract_dual_value(result_vec, offset, constraint)
result_vec |
The vector to extract dual values from. |
offset |
The starting point of the vector to extract from. |
constraint |
A Constraint object. |
The dual values for the corresponding PSD constraints
Set the CVXR variable/constraint identification number counter.
setIdCounter(value = 0L)
setIdCounter(value = 0L)
value |
The value to assign as ID. |
the changed value of the package global .CVXR.options
.
## Not run: setIdCounter(value = 0L) ## End(Not run)
## Not run: setIdCounter(value = 0L) ## End(Not run)
The maximum singular value of a matrix.
sigma_max(A = A)
sigma_max(A = A)
A |
An Expression or matrix. |
An Expression representing the maximum singular value.
C <- Variable(3,2) val <- rbind(c(1,2), c(3,4), c(5,6)) obj <- sigma_max(C) constr <- list(C == val) prob <- Problem(Minimize(obj), constr) result <- solve(prob, solver = "SCS") result$value result$getValue(C)
C <- Variable(3,2) val <- rbind(c(1,2), c(3,4), c(5,6)) obj <- sigma_max(C) constr <- list(C == val) prob <- Problem(Minimize(obj), constr) result <- solve(prob, solver = "SCS") result$value result$getValue(C)
The maximum singular value of a matrix.
SigmaMax(A = A) ## S4 method for signature 'SigmaMax' to_numeric(object, values) ## S4 method for signature 'SigmaMax' allow_complex(object) ## S4 method for signature 'SigmaMax' dim_from_args(object) ## S4 method for signature 'SigmaMax' sign_from_args(object) ## S4 method for signature 'SigmaMax' is_atom_convex(object) ## S4 method for signature 'SigmaMax' is_atom_concave(object) ## S4 method for signature 'SigmaMax' is_incr(object, idx) ## S4 method for signature 'SigmaMax' is_decr(object, idx) ## S4 method for signature 'SigmaMax' .grad(object, values)
SigmaMax(A = A) ## S4 method for signature 'SigmaMax' to_numeric(object, values) ## S4 method for signature 'SigmaMax' allow_complex(object) ## S4 method for signature 'SigmaMax' dim_from_args(object) ## S4 method for signature 'SigmaMax' sign_from_args(object) ## S4 method for signature 'SigmaMax' is_atom_convex(object) ## S4 method for signature 'SigmaMax' is_atom_concave(object) ## S4 method for signature 'SigmaMax' is_incr(object, idx) ## S4 method for signature 'SigmaMax' is_decr(object, idx) ## S4 method for signature 'SigmaMax' .grad(object, values)
A |
An Expression or matrix. |
object |
A SigmaMax object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(SigmaMax)
: The largest singular value of A
.
allow_complex(SigmaMax)
: Does the atom handle complex numbers?
dim_from_args(SigmaMax)
: The atom is a scalar.
sign_from_args(SigmaMax)
: The atom is positive.
is_atom_convex(SigmaMax)
: The atom is convex.
is_atom_concave(SigmaMax)
: The atom is concave.
is_incr(SigmaMax)
: The atom is not monotonic in any argument.
is_decr(SigmaMax)
: The atom is not monotonic in any argument.
.grad(SigmaMax)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
A
An Expression or numeric matrix.
Determine the sign of an atom based on its arguments.
sign_from_args(object) ## S4 method for signature 'Atom' sign_from_args(object)
sign_from_args(object) ## S4 method for signature 'Atom' sign_from_args(object)
object |
An Atom object. |
A logical vector c(is positive, is negative)
indicating the sign of the atom.
Determine if an expression is positive, negative, or zero.
is_zero(object) is_nonneg(object) is_nonpos(object)
is_zero(object) is_nonneg(object) is_nonpos(object)
object |
An Expression object. |
A logical value.
pos <- Constant(1) neg <- Constant(-1) zero <- Constant(0) unknown <- Variable() is_zero(pos) is_zero(-zero) is_zero(unknown) is_zero(pos + neg) is_nonneg(pos + zero) is_nonneg(pos * neg) is_nonneg(pos - neg) is_nonneg(unknown) is_nonpos(-pos) is_nonpos(pos + neg) is_nonpos(neg * zero) is_nonpos(neg - pos)
pos <- Constant(1) neg <- Constant(-1) zero <- Constant(0) unknown <- Variable() is_zero(pos) is_zero(-zero) is_zero(unknown) is_zero(pos + neg) is_nonneg(pos + zero) is_nonneg(pos * neg) is_nonneg(pos - neg) is_nonneg(unknown) is_nonpos(-pos) is_nonpos(pos + neg) is_nonpos(neg * zero) is_nonpos(neg - pos)
The sign of an expression.
## S4 method for signature 'Expression' sign(x)
## S4 method for signature 'Expression' sign(x)
x |
An Expression object. |
A string indicating the sign of the expression, either "ZERO", "NONNEGATIVE", "NONPOSITIVE", or "UNKNOWN".
The size of an expression.
size(object) ## S4 method for signature 'ListORExpr' size(object)
size(object) ## S4 method for signature 'ListORExpr' size(object)
object |
An Expression object. |
A vector with two elements c(row, col)
representing the dimensions of the expression.
x <- Variable() y <- Variable(3) z <- Variable(3,2) size(x) size(y) size(z) size(x + y) size(z - x)
x <- Variable() y <- Variable(3) z <- Variable(3,2) size(x) size(y) size(z) size(x + y) size(z - x)
Determine if an expression is a scalar, vector, or matrix.
is_scalar(object) is_vector(object) is_matrix(object)
is_scalar(object) is_vector(object) is_matrix(object)
object |
An Expression object. |
A logical value.
x <- Variable() y <- Variable(3) z <- Variable(3,2) is_scalar(x) is_scalar(y) is_scalar(x + y) is_vector(x) is_vector(y) is_vector(2*z) is_matrix(x) is_matrix(y) is_matrix(z) is_matrix(z - x)
x <- Variable() y <- Variable(3) z <- Variable(3,2) is_scalar(x) is_scalar(y) is_scalar(x + y) is_vector(x) is_vector(y) is_vector(2*z) is_matrix(x) is_matrix(y) is_matrix(z) is_matrix(z - x)
This class contains various metrics regarding the problem size.
SizeMetrics(problem)
SizeMetrics(problem)
problem |
A Problem object. |
num_scalar_variables
The number of scalar variables in the problem.
num_scalar_data
The number of constants used across all matrices and vectors in the problem. Some constants are not apparent when the problem is constructed. For example, the sum_squares
expression is a wrapper for a quad_over_lin
expression with a constant 1
in the denominator.
num_scalar_eq_constr
The number of scalar equality constraints in the problem.
num_scalar_leq_constr
The number of scalar inequality constraints in the problem.
max_data_dimension
The longest dimension of any data block constraint or parameter.
max_big_small_squared
The maximum value of (big)(small)^2 over all data blocks of the problem, where (big) is the larger dimension and (small) is the smaller dimension for each data block.
This class represents a second-order cone constraint, i.e. .
SOC(t, X, axis = 2, id = NA_integer_) ## S4 method for signature 'SOC' as.character(x) ## S4 method for signature 'SOC' residual(object) ## S4 method for signature 'SOC' get_data(object) ## S4 method for signature 'SOC' format_constr(object, eq_constr, leq_constr, dims, solver) ## S4 method for signature 'SOC' num_cones(object) ## S4 method for signature 'SOC' size(object) ## S4 method for signature 'SOC' cone_sizes(object) ## S4 method for signature 'SOC' is_dcp(object) ## S4 method for signature 'SOC' is_dgp(object) ## S4 method for signature 'SOC' canonicalize(object)
SOC(t, X, axis = 2, id = NA_integer_) ## S4 method for signature 'SOC' as.character(x) ## S4 method for signature 'SOC' residual(object) ## S4 method for signature 'SOC' get_data(object) ## S4 method for signature 'SOC' format_constr(object, eq_constr, leq_constr, dims, solver) ## S4 method for signature 'SOC' num_cones(object) ## S4 method for signature 'SOC' size(object) ## S4 method for signature 'SOC' cone_sizes(object) ## S4 method for signature 'SOC' is_dcp(object) ## S4 method for signature 'SOC' is_dgp(object) ## S4 method for signature 'SOC' canonicalize(object)
t |
The scalar part of the second-order constraint. |
X |
A matrix whose rows/columns are each a cone. |
axis |
The dimension along which to slice: |
id |
(Optional) A numeric value representing the constraint ID. |
x , object
|
A SOC object. |
eq_constr |
A list of the equality constraints in the canonical problem. |
leq_constr |
A list of the inequality constraints in the canonical problem. |
dims |
A list with the dimensions of the conic constraints. |
solver |
A string representing the solver to be called. |
residual(SOC)
: The residual of the second-order constraint.
get_data(SOC)
: Information needed to reconstruct the object aside from the args.
format_constr(SOC)
: Format SOC constraints as inequalities for the solver.
num_cones(SOC)
: The number of elementwise cones.
size(SOC)
: The number of entries in the combined cones.
cone_sizes(SOC)
: The dimensions of the second-order cones.
is_dcp(SOC)
: An SOC constraint is DCP if each of its arguments is affine.
is_dgp(SOC)
: Is the constraint DGP?
canonicalize(SOC)
: The canonicalization of the constraint.
t
The scalar part of the second-order constraint.
X
A matrix whose rows/columns are each a cone.
axis
The dimension along which to slice: 1
indicates rows, and 2
indicates columns. The default is 2
.
This class represents a second-order cone constraint for each row/column.
It Assumes is a vector the same length as
's rows (columns) for axis == 1 (2).
SOCAxis(t, X, axis, id = NA_integer_) ## S4 method for signature 'SOCAxis' as.character(x) ## S4 method for signature 'SOCAxis' format_constr(object, eq_constr, leq_constr, dims, solver) ## S4 method for signature 'SOCAxis' num_cones(object) ## S4 method for signature 'SOCAxis' cone_sizes(object) ## S4 method for signature 'SOCAxis' size(object)
SOCAxis(t, X, axis, id = NA_integer_) ## S4 method for signature 'SOCAxis' as.character(x) ## S4 method for signature 'SOCAxis' format_constr(object, eq_constr, leq_constr, dims, solver) ## S4 method for signature 'SOCAxis' num_cones(object) ## S4 method for signature 'SOCAxis' cone_sizes(object) ## S4 method for signature 'SOCAxis' size(object)
t |
The scalar part of the second-order constraint. |
X |
A matrix whose rows/columns are each a cone. |
axis |
The dimension across which to take the slice: |
id |
(Optional) A numeric value representing the constraint ID. |
x , object
|
A SOCAxis object. |
eq_constr |
A list of the equality constraints in the canonical problem. |
leq_constr |
A list of the inequality constraints in the canonical problem. |
dims |
A list with the dimensions of the conic constraints. |
solver |
A string representing the solver to be called. |
format_constr(SOCAxis)
: Format SOC constraints as inequalities for the solver.
num_cones(SOCAxis)
: The number of elementwise cones.
cone_sizes(SOCAxis)
: The dimensions of a single cone.
size(SOCAxis)
: The dimensions of the (elementwise) second-order cones.
t
The scalar part of the second-order constraint.
x_elems
A list containing X
, a matrix whose rows/columns are each a cone.
axis
The dimension across which to take the slice: 1
indicates rows, and 2
indicates columns.
This class represents a solution to an optimization problem.
## S4 method for signature 'Solution' as.character(x)
## S4 method for signature 'Solution' as.character(x)
x |
A Solution object. |
This class contains the miscellaneous information that is returned by a solver after solving, but that is not captured directly by the Problem object.
SolverStats(results_dict = list(), solver_name = NA_character_)
SolverStats(results_dict = list(), solver_name = NA_character_)
results_dict |
A list containing the results returned by the solver. |
solver_name |
The name of the solver. |
A list containing
solver_name
The name of the solver.
solve_time
The time (in seconds) it took for the solver to solve the problem.
setup_time
The time (in seconds) it took for the solver to set up the problem.
num_iters
The number of iterations the solver had to go through to find a solution.
solver_name
The name of the solver.
solve_time
The time (in seconds) it took for the solver to solve the problem.
setup_time
The time (in seconds) it took for the solver to set up the problem.
num_iters
The number of iterations the solver had to go through to find a solution.
This class represents a reduction chain that ends with a solver.
## S4 method for signature 'SolvingChain,Chain' prepend(object, chain) ## S4 method for signature 'SolvingChain,Problem' reduction_solve( object, problem, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts ) ## S4 method for signature 'SolvingChain' reduction_solve_via_data( object, problem, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts )
## S4 method for signature 'SolvingChain,Chain' prepend(object, chain) ## S4 method for signature 'SolvingChain,Problem' reduction_solve( object, problem, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts ) ## S4 method for signature 'SolvingChain' reduction_solve_via_data( object, problem, data, warm_start, verbose, feastol, reltol, abstol, num_iter, solver_opts )
object |
A SolvingChain object. |
chain |
A Chain to prepend. |
problem |
The problem to solve. |
warm_start |
A boolean of whether to warm start the solver. |
verbose |
A boolean of whether to enable solver verbosity. |
feastol |
The feasible tolerance. |
reltol |
The relative tolerance. |
abstol |
The absolute tolerance. |
num_iter |
The maximum number of iterations. |
solver_opts |
A list of Solver specific options |
data |
Data for the solver. |
prepend(object = SolvingChain, chain = Chain)
: Create and return a new SolvingChain by concatenating chain with this instance.
reduction_solve(object = SolvingChain, problem = Problem)
: Applies each reduction in the chain to the problem, solves it,
and then inverts the chain to return a solution of the supplied problem.
reduction_solve_via_data(SolvingChain)
: Solves the problem using the data output by the an apply invocation.
The elementwise square root.
## S4 method for signature 'Expression' sqrt(x)
## S4 method for signature 'Expression' sqrt(x)
x |
An Expression. |
An Expression representing the square root of the input. A <- Variable(2,2) val <- cbind(c(2,4), c(16,1)) prob <- Problem(Maximize(sqrt(A)[1,2]), list(A == val)) result <- solve(prob) result$value
The elementwise square.
## S4 method for signature 'Expression' square(x)
## S4 method for signature 'Expression' square(x)
x |
An Expression. |
An Expression representing the square of the input. A <- Variable(2,2) val <- cbind(c(2,4), c(16,1)) prob <- Problem(Minimize(square(A)[1,2]), list(A == val)) result <- solve(prob) result$value
The sum of entries in a vector or matrix.
sum_entries(expr, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' sum(..., na.rm = FALSE)
sum_entries(expr, axis = NA_real_, keepdims = FALSE) ## S3 method for class 'Expression' sum(..., na.rm = FALSE)
expr |
An Expression, vector, or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
... |
Numeric scalar, vector, matrix, or Expression objects. |
na.rm |
(Unimplemented) A logical value indicating whether missing values should be removed. |
An Expression representing the sum of the entries of the input.
x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(t(x) >= matrix(c(1,2), nrow = 1, ncol = 2))) result <- solve(prob) result$value result$getValue(x) C <- Variable(3,2) prob <- Problem(Maximize(sum_entries(C)), list(C[2:3,] <= 2, C[1,] == 1)) result <- solve(prob) result$value result$getValue(C) x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(t(x) >= matrix(c(1,2), nrow = 1, ncol = 2))) result <- solve(prob) result$value result$getValue(x) C <- Variable(3,2) prob <- Problem(Maximize(sum_entries(C)), list(C[2:3,] <= 2, C[1,] == 1)) result <- solve(prob) result$value result$getValue(C)
x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(t(x) >= matrix(c(1,2), nrow = 1, ncol = 2))) result <- solve(prob) result$value result$getValue(x) C <- Variable(3,2) prob <- Problem(Maximize(sum_entries(C)), list(C[2:3,] <= 2, C[1,] == 1)) result <- solve(prob) result$value result$getValue(C) x <- Variable(2) prob <- Problem(Minimize(sum_entries(x)), list(t(x) >= matrix(c(1,2), nrow = 1, ncol = 2))) result <- solve(prob) result$value result$getValue(x) C <- Variable(3,2) prob <- Problem(Maximize(sum_entries(C)), list(C[2:3,] <= 2, C[1,] == 1)) result <- solve(prob) result$value result$getValue(C)
The sum of the largest values of a vector or matrix.
sum_largest(x, k)
sum_largest(x, k)
x |
An Expression, vector, or matrix. |
k |
The number of largest values to sum over. |
An Expression representing the sum of the largest k
values of the input.
set.seed(122) m <- 300 n <- 9 X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) X <- cbind(rep(1,m), X) b <- c(0, 0.8, 0, 1, 0.2, 0, 0.4, 1, 0, 0.7) y <- X %*% b + stats::rnorm(m) beta <- Variable(n+1) obj <- sum_largest((y - X %*% beta)^2, 100) prob <- Problem(Minimize(obj)) result <- solve(prob) result$getValue(beta)
set.seed(122) m <- 300 n <- 9 X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) X <- cbind(rep(1,m), X) b <- c(0, 0.8, 0, 1, 0.2, 0, 0.4, 1, 0, 0.7) y <- X %*% b + stats::rnorm(m) beta <- Variable(n+1) obj <- sum_largest((y - X %*% beta)^2, 100) prob <- Problem(Minimize(obj)) result <- solve(prob) result$getValue(beta)
The sum of the smallest k values of a vector or matrix.
sum_smallest(x, k)
sum_smallest(x, k)
x |
An Expression, vector, or matrix. |
k |
The number of smallest values to sum over. |
An Expression representing the sum of the smallest k values of the input.
set.seed(1323) m <- 300 n <- 9 X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) X <- cbind(rep(1,m), X) b <- c(0, 0.8, 0, 1, 0.2, 0, 0.4, 1, 0, 0.7) factor <- 2*rbinom(m, size = 1, prob = 0.8) - 1 y <- factor * (X %*% b) + stats::rnorm(m) beta <- Variable(n+1) obj <- sum_smallest(y - X %*% beta, 200) prob <- Problem(Maximize(obj), list(0 <= beta, beta <= 1)) result <- solve(prob) result$getValue(beta)
set.seed(1323) m <- 300 n <- 9 X <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) X <- cbind(rep(1,m), X) b <- c(0, 0.8, 0, 1, 0.2, 0, 0.4, 1, 0, 0.7) factor <- 2*rbinom(m, size = 1, prob = 0.8) - 1 y <- factor * (X %*% b) + stats::rnorm(m) beta <- Variable(n+1) obj <- sum_smallest(y - X %*% beta, 200) prob <- Problem(Maximize(obj), list(0 <= beta, beta <= 1)) result <- solve(prob) result$getValue(beta)
The sum of the squared entries in a vector or matrix.
sum_squares(expr)
sum_squares(expr)
expr |
An Expression, vector, or matrix. |
An Expression representing the sum of squares of the input.
set.seed(212) m <- 30 n <- 20 A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) b <- matrix(stats::rnorm(m), nrow = m, ncol = 1) x <- Variable(n) obj <- Minimize(sum_squares(A %*% x - b)) constr <- list(0 <= x, x <= 1) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) result$getDualValue(constr[[1]])
set.seed(212) m <- 30 n <- 20 A <- matrix(stats::rnorm(m*n), nrow = m, ncol = n) b <- matrix(stats::rnorm(m), nrow = m, ncol = 1) x <- Variable(n) obj <- Minimize(sum_squares(A %*% x - b)) constr <- list(0 <= x, x <= 1) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) result$getDualValue(constr[[1]])
This class represents the sum of all entries in a vector or matrix.
SumEntries(expr, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'SumEntries' to_numeric(object, values) ## S4 method for signature 'SumEntries' is_atom_log_log_convex(object) ## S4 method for signature 'SumEntries' is_atom_log_log_concave(object) ## S4 method for signature 'SumEntries' graph_implementation(object, arg_objs, dim, data = NA_real_)
SumEntries(expr, axis = NA_real_, keepdims = FALSE) ## S4 method for signature 'SumEntries' to_numeric(object, values) ## S4 method for signature 'SumEntries' is_atom_log_log_convex(object) ## S4 method for signature 'SumEntries' is_atom_log_log_concave(object) ## S4 method for signature 'SumEntries' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression representing a vector or matrix. |
axis |
(Optional) The dimension across which to apply the function: |
keepdims |
(Optional) Should dimensions be maintained when applying the atom along an axis? If |
object |
A SumEntries object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(SumEntries)
: Sum the entries along the specified axis.
is_atom_log_log_convex(SumEntries)
: Is the atom log-log convex?
is_atom_log_log_concave(SumEntries)
: Is the atom log-log concave?
graph_implementation(SumEntries)
: The graph implementation of the atom.
expr
An Expression representing a vector or matrix.
axis
(Optional) The dimension across which to apply the function: 1
indicates rows, 2
indicates columns, and NA
indicates rows and columns. The default is NA
.
keepdims
(Optional) Should dimensions be maintained when applying the atom along an axis? If FALSE
, result will be collapsed into an column vector. The default is
FALSE
.
The sum of the largest k values of a matrix.
SumLargest(x, k) ## S4 method for signature 'SumLargest' to_numeric(object, values) ## S4 method for signature 'SumLargest' validate_args(object) ## S4 method for signature 'SumLargest' dim_from_args(object) ## S4 method for signature 'SumLargest' sign_from_args(object) ## S4 method for signature 'SumLargest' is_atom_convex(object) ## S4 method for signature 'SumLargest' is_atom_concave(object) ## S4 method for signature 'SumLargest' is_incr(object, idx) ## S4 method for signature 'SumLargest' is_decr(object, idx) ## S4 method for signature 'SumLargest' get_data(object) ## S4 method for signature 'SumLargest' .grad(object, values)
SumLargest(x, k) ## S4 method for signature 'SumLargest' to_numeric(object, values) ## S4 method for signature 'SumLargest' validate_args(object) ## S4 method for signature 'SumLargest' dim_from_args(object) ## S4 method for signature 'SumLargest' sign_from_args(object) ## S4 method for signature 'SumLargest' is_atom_convex(object) ## S4 method for signature 'SumLargest' is_atom_concave(object) ## S4 method for signature 'SumLargest' is_incr(object, idx) ## S4 method for signature 'SumLargest' is_decr(object, idx) ## S4 method for signature 'SumLargest' get_data(object) ## S4 method for signature 'SumLargest' .grad(object, values)
x |
An Expression or numeric matrix. |
k |
The number of largest values to sum over. |
object |
A SumLargest object. |
values |
A list of numeric values for the arguments |
idx |
An index into the atom. |
to_numeric(SumLargest)
: The sum of the k
largest entries of the vector or matrix.
validate_args(SumLargest)
: Check that k
is a positive integer.
dim_from_args(SumLargest)
: The atom is a scalar.
sign_from_args(SumLargest)
: The sign of the atom.
is_atom_convex(SumLargest)
: The atom is convex.
is_atom_concave(SumLargest)
: The atom is not concave.
is_incr(SumLargest)
: The atom is weakly increasing in every argument.
is_decr(SumLargest)
: The atom is not weakly decreasing in any argument.
get_data(SumLargest)
: A list containing k
.
.grad(SumLargest)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric matrix.
k
The number of largest values to sum over.
The sum of the smallest k values of a matrix.
SumSmallest(x, k)
SumSmallest(x, k)
x |
An Expression or numeric matrix. |
k |
The number of smallest values to sum over. |
Sum of the smlalest k values
The sum of the squares of the entries.
SumSquares(expr)
SumSquares(expr)
expr |
An Expression or numeric matrix. |
Sum of the squares of the entries in the expression.
The SymbolicQuadForm class.
SymbolicQuadForm(x, P, expr) ## S4 method for signature 'SymbolicQuadForm' dim_from_args(object) ## S4 method for signature 'SymbolicQuadForm' sign_from_args(object) ## S4 method for signature 'SymbolicQuadForm' get_data(object) ## S4 method for signature 'SymbolicQuadForm' is_atom_convex(object) ## S4 method for signature 'SymbolicQuadForm' is_atom_concave(object) ## S4 method for signature 'SymbolicQuadForm' is_incr(object, idx) ## S4 method for signature 'SymbolicQuadForm' is_decr(object, idx) ## S4 method for signature 'SymbolicQuadForm' is_quadratic(object) ## S4 method for signature 'SymbolicQuadForm' .grad(object, values)
SymbolicQuadForm(x, P, expr) ## S4 method for signature 'SymbolicQuadForm' dim_from_args(object) ## S4 method for signature 'SymbolicQuadForm' sign_from_args(object) ## S4 method for signature 'SymbolicQuadForm' get_data(object) ## S4 method for signature 'SymbolicQuadForm' is_atom_convex(object) ## S4 method for signature 'SymbolicQuadForm' is_atom_concave(object) ## S4 method for signature 'SymbolicQuadForm' is_incr(object, idx) ## S4 method for signature 'SymbolicQuadForm' is_decr(object, idx) ## S4 method for signature 'SymbolicQuadForm' is_quadratic(object) ## S4 method for signature 'SymbolicQuadForm' .grad(object, values)
x |
An Expression or numeric vector. |
P |
An Expression, numeric matrix, or vector. |
expr |
The original Expression. |
object |
A SymbolicQuadForm object. |
idx |
An index into the atom. |
values |
A list of numeric values for the arguments |
dim_from_args(SymbolicQuadForm)
: The dimensions of the atom.
sign_from_args(SymbolicQuadForm)
: The sign (is positive, is negative) of the atom.
get_data(SymbolicQuadForm)
: The original expression.
is_atom_convex(SymbolicQuadForm)
: Is the original expression convex?
is_atom_concave(SymbolicQuadForm)
: Is the original expression concave?
is_incr(SymbolicQuadForm)
: Is the original expression weakly increasing in argument idx
?
is_decr(SymbolicQuadForm)
: Is the original expression weakly decreasing in argument idx
?
is_quadratic(SymbolicQuadForm)
: The atom is quadratic.
.grad(SymbolicQuadForm)
: Gives the (sub/super)gradient of the atom w.r.t. each variable
x
An Expression or numeric vector.
P
An Expression, numeric matrix, or vector.
original_expression
The original Expression.
The transpose of a matrix.
## S3 method for class 'Expression' t(x) ## S4 method for signature 'Expression' t(x)
## S3 method for class 'Expression' t(x) ## S4 method for signature 'Expression' t(x)
x |
An Expression representing a matrix. |
An Expression representing the transposed matrix.
x <- Variable(3, 4) t(x)
x <- Variable(3, 4) t(x)
Returns the numeric value of the atom evaluated on the specified arguments.
to_numeric(object, values)
to_numeric(object, values)
object |
An Atom object. |
values |
A list of arguments to the atom. |
A numeric scalar, vector, or matrix.
The total variation of a vector, matrix, or list of matrices. Uses L1 norm of discrete gradients for vectors and L2 norm of discrete gradients for matrices.
TotalVariation(value, ...)
TotalVariation(value, ...)
value |
An Expression representing the value to take the total variation of. |
... |
Additional matrices extending the third dimension of value. |
An expression representing the total variation.
This class represents the sum of the diagonal entries in a matrix.
Trace(expr) ## S4 method for signature 'Trace' to_numeric(object, values) ## S4 method for signature 'Trace' validate_args(object) ## S4 method for signature 'Trace' dim_from_args(object) ## S4 method for signature 'Trace' is_atom_log_log_convex(object) ## S4 method for signature 'Trace' is_atom_log_log_concave(object) ## S4 method for signature 'Trace' graph_implementation(object, arg_objs, dim, data = NA_real_)
Trace(expr) ## S4 method for signature 'Trace' to_numeric(object, values) ## S4 method for signature 'Trace' validate_args(object) ## S4 method for signature 'Trace' dim_from_args(object) ## S4 method for signature 'Trace' is_atom_log_log_convex(object) ## S4 method for signature 'Trace' is_atom_log_log_concave(object) ## S4 method for signature 'Trace' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression representing a matrix. |
object |
A Trace object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Trace)
: Sum the diagonal entries.
validate_args(Trace)
: Check the argument is a square matrix.
dim_from_args(Trace)
: The atom is a scalar.
is_atom_log_log_convex(Trace)
: Is the atom log-log convex?
is_atom_log_log_concave(Trace)
: Is the atom log-log concave?
graph_implementation(Trace)
: The graph implementation of the atom.
expr
An Expression representing a matrix.
This class represents the matrix transpose.
## S4 method for signature 'Transpose' to_numeric(object, values) ## S4 method for signature 'Transpose' is_symmetric(object) ## S4 method for signature 'Transpose' is_hermitian(object) ## S4 method for signature 'Transpose' dim_from_args(object) ## S4 method for signature 'Transpose' is_atom_log_log_convex(object) ## S4 method for signature 'Transpose' is_atom_log_log_concave(object) ## S4 method for signature 'Transpose' get_data(object) ## S4 method for signature 'Transpose' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Transpose' to_numeric(object, values) ## S4 method for signature 'Transpose' is_symmetric(object) ## S4 method for signature 'Transpose' is_hermitian(object) ## S4 method for signature 'Transpose' dim_from_args(object) ## S4 method for signature 'Transpose' is_atom_log_log_convex(object) ## S4 method for signature 'Transpose' is_atom_log_log_concave(object) ## S4 method for signature 'Transpose' get_data(object) ## S4 method for signature 'Transpose' graph_implementation(object, arg_objs, dim, data = NA_real_)
object |
A Transpose object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Transpose)
: The transpose of the given value.
is_symmetric(Transpose)
: Is the expression symmetric?
is_hermitian(Transpose)
: Is the expression hermitian?
dim_from_args(Transpose)
: The dimensions of the atom.
is_atom_log_log_convex(Transpose)
: Is the atom log-log convex?
is_atom_log_log_concave(Transpose)
: Is the atom log-log concave?
get_data(Transpose)
: Returns the axes for transposition.
graph_implementation(Transpose)
: The graph implementation of the atom.
Expands lower triangular to full matrix.
tri_to_full(lower_tri, n)
tri_to_full(lower_tri, n)
lower_tri |
A matrix representing the lower triangular part of the matrix, stacked in column-major order |
n |
The number of rows (columns) in the full square matrix. |
A matrix that is the scaled expansion of the lower triangular matrix.
Expands upper triangular to full matrix.
triu_to_full(upper_tri, n)
triu_to_full(upper_tri, n)
upper_tri |
A matrix representing the uppertriangular part of the matrix, stacked in column-major order |
n |
The number of rows (columns) in the full square matrix. |
A matrix that is the scaled expansion of the upper triangular matrix.
The total variation of a vector, matrix, or list of matrices. Uses L1 norm of discrete gradients for vectors and L2 norm of discrete gradients for matrices.
tv(value, ...)
tv(value, ...)
value |
An Expression, vector, or matrix. |
... |
(Optional) Expression objects or numeric constants that extend the third dimension of value. |
An Expression representing the total variation of the input.
rows <- 10 cols <- 10 Uorig <- matrix(sample(0:255, size = rows * cols, replace = TRUE), nrow = rows, ncol = cols) # Known is 1 if the pixel is known, 0 if the pixel was corrupted Known <- matrix(0, nrow = rows, ncol = cols) for(i in 1:rows) { for(j in 1:cols) { if(stats::runif(1) > 0.7) Known[i,j] <- 1 } } Ucorr <- Known %*% Uorig # Recover the original image using total variation in-painting U <- Variable(rows, cols) obj <- Minimize(tv(U)) constraints <- list(Known * U == Known * Ucorr) prob <- Problem(obj, constraints) result <- solve(prob, solver = "SCS") result$getValue(U)
rows <- 10 cols <- 10 Uorig <- matrix(sample(0:255, size = rows * cols, replace = TRUE), nrow = rows, ncol = cols) # Known is 1 if the pixel is known, 0 if the pixel was corrupted Known <- matrix(0, nrow = rows, ncol = cols) for(i in 1:rows) { for(j in 1:cols) { if(stats::runif(1) > 0.7) Known[i,j] <- 1 } } Ucorr <- Known %*% Uorig # Recover the original image using total variation in-painting U <- Variable(rows, cols) obj <- Minimize(tv(U)) constraints <- list(Known * U == Known * Ucorr) prob <- Problem(obj, constraints) result <- solve(prob, solver = "SCS") result$getValue(U)
This base class represents expressions involving unary operators.
## S4 method for signature 'UnaryOperator' name(x) ## S4 method for signature 'UnaryOperator' to_numeric(object, values)
## S4 method for signature 'UnaryOperator' name(x) ## S4 method for signature 'UnaryOperator' to_numeric(object, values)
x , object
|
A UnaryOperator object. |
values |
A list of arguments to the atom. |
name(UnaryOperator)
: Returns the expression in string form.
to_numeric(UnaryOperator)
: Applies the unary operator to the value.
expr
The Expression that is being operated upon.
op_name
A character
string indicating the unary operation.
Updates problem status, problem value, and primal and dual variable values
unpack_results(object, solution, chain, inverse_data)
unpack_results(object, solution, chain, inverse_data)
object |
A Problem object. |
solution |
A Solution object. |
chain |
The corresponding solving Chain. |
inverse_data |
A InverseData object or list containing data necessary for the inversion. |
A list containing the solution to the problem:
status
The status of the solution. Can be "optimal", "optimal_inaccurate", "infeasible", "infeasible_inaccurate", "unbounded", "unbounded_inaccurate", or "solver_error".
value
The optimal value of the objective function.
solver
The name of the solver.
solve_time
The time (in seconds) it took for the solver to solve the problem.
setup_time
The time (in seconds) it took for the solver to set up the problem.
num_iters
The number of iterations the solver had to go through to find a solution.
getValue
A function that takes a Variable object and retrieves its primal value.
getDualValue
A function that takes a Constraint object and retrieves its dual value(s).
## Not run: x <- Variable(2) obj <- Minimize(x[1] + cvxr_norm(x, 1)) constraints <- list(x >= 2) prob1 <- Problem(obj, constraints) # Solve with ECOS. ecos_data <- get_problem_data(prob1, "ECOS") # Call ECOS solver interface directly ecos_output <- ECOSolveR::ECOS_csolve( c = ecos_data[["c"]], G = ecos_data[["G"]], h = ecos_data[["h"]], dims = ecos_data[["dims"]], A = ecos_data[["A"]], b = ecos_data[["b"]] ) # Unpack raw solver output. res1 <- unpack_results(prob1, "ECOS", ecos_output) # Without DCP validation (so be sure of your math), above is equivalent to: # res1 <- solve(prob1, solver = "ECOS") X <- Variable(2,2, PSD = TRUE) Fmat <- rbind(c(1,0), c(0,-1)) obj <- Minimize(sum_squares(X - Fmat)) prob2 <- Problem(obj) scs_data <- get_problem_data(prob2, "SCS") scs_output <- scs::scs( A = scs_data[['A']], b = scs_data[['b']], obj = scs_data[['c']], cone = scs_data[['dims']] ) res2 <- unpack_results(prob2, "SCS", scs_output) # Without DCP validation (so be sure of your math), above is equivalent to: # res2 <- solve(prob2, solver = "SCS") ## End(Not run)
## Not run: x <- Variable(2) obj <- Minimize(x[1] + cvxr_norm(x, 1)) constraints <- list(x >= 2) prob1 <- Problem(obj, constraints) # Solve with ECOS. ecos_data <- get_problem_data(prob1, "ECOS") # Call ECOS solver interface directly ecos_output <- ECOSolveR::ECOS_csolve( c = ecos_data[["c"]], G = ecos_data[["G"]], h = ecos_data[["h"]], dims = ecos_data[["dims"]], A = ecos_data[["A"]], b = ecos_data[["b"]] ) # Unpack raw solver output. res1 <- unpack_results(prob1, "ECOS", ecos_output) # Without DCP validation (so be sure of your math), above is equivalent to: # res1 <- solve(prob1, solver = "ECOS") X <- Variable(2,2, PSD = TRUE) Fmat <- rbind(c(1,0), c(0,-1)) obj <- Minimize(sum_squares(X - Fmat)) prob2 <- Problem(obj) scs_data <- get_problem_data(prob2, "SCS") scs_output <- scs::scs( A = scs_data[['A']], b = scs_data[['b']], obj = scs_data[['c']], cone = scs_data[['dims']] ) res2 <- unpack_results(prob2, "SCS", scs_output) # Without DCP validation (so be sure of your math), above is equivalent to: # res2 <- solve(prob2, solver = "SCS") ## End(Not run)
Utility methods for special handling of semidefinite constraints.
updated_scaled_lower_tri(matrix)
updated_scaled_lower_tri(matrix)
matrix |
The matrix to get the lower triangular matrix for |
The lower triangular part of the matrix, stacked in column-major order
The vectorized strictly upper triangular entries of a matrix.
upper_tri(expr)
upper_tri(expr)
expr |
An Expression or matrix. |
An Expression representing the upper triangle of the input.
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Maximize(upper_tri(C)[3,1]), list(C == val)) result <- solve(prob) result$value result$getValue(upper_tri(C))
C <- Variable(3,3) val <- cbind(3:5, 6:8, 9:11) prob <- Problem(Maximize(upper_tri(C)[3,1]), list(C == val)) result <- solve(prob) result$value result$getValue(upper_tri(C))
The vectorized strictly upper triagonal entries of a matrix.
UpperTri(expr) ## S4 method for signature 'UpperTri' to_numeric(object, values) ## S4 method for signature 'UpperTri' validate_args(object) ## S4 method for signature 'UpperTri' dim_from_args(object) ## S4 method for signature 'UpperTri' is_atom_log_log_convex(object) ## S4 method for signature 'UpperTri' is_atom_log_log_concave(object) ## S4 method for signature 'UpperTri' graph_implementation(object, arg_objs, dim, data = NA_real_)
UpperTri(expr) ## S4 method for signature 'UpperTri' to_numeric(object, values) ## S4 method for signature 'UpperTri' validate_args(object) ## S4 method for signature 'UpperTri' dim_from_args(object) ## S4 method for signature 'UpperTri' is_atom_log_log_convex(object) ## S4 method for signature 'UpperTri' is_atom_log_log_concave(object) ## S4 method for signature 'UpperTri' graph_implementation(object, arg_objs, dim, data = NA_real_)
expr |
An Expression or numeric matrix. |
object |
An UpperTri object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(UpperTri)
: Vectorize the upper triagonal entries.
validate_args(UpperTri)
: Check the argument is a square matrix.
dim_from_args(UpperTri)
: The dimensions of the atom.
is_atom_log_log_convex(UpperTri)
: Is the atom log-log convex?
is_atom_log_log_concave(UpperTri)
: Is the atom log-log concave?
graph_implementation(UpperTri)
: The graph implementation of the atom.
expr
An Expression or numeric matrix.
Validate an atom's arguments, returning an error if any are invalid.
validate_args(object)
validate_args(object)
object |
An Atom object. |
Check that the value satisfies a Leaf's symbolic attributes.
validate_val(object, val)
validate_val(object, val)
object |
A Leaf object. |
val |
The assigned value. |
The value converted to proper matrix type.
Get or set the value of a variable, parameter, expression, or problem.
value(object) value(object) <- value
value(object) value(object) <- value
object |
A Variable, Parameter, Expression, or Problem object. |
value |
A numeric scalar, vector, or matrix to assign to the object. |
The numeric value of the variable, parameter, or expression. If any part of the mathematical object is unknown, return NA
.
lambda <- Parameter() value(lambda) value(lambda) <- 5 value(lambda)
lambda <- Parameter() value(lambda) value(lambda) <- 5 value(lambda)
This class represents an optimization variable.
Variable(rows = NULL, cols = NULL, name = NA_character_, ...) ## S4 method for signature 'Variable' as.character(x) ## S4 method for signature 'Variable' name(x) ## S4 method for signature 'Variable' value(object) ## S4 method for signature 'Variable' grad(object) ## S4 method for signature 'Variable' variables(object) ## S4 method for signature 'Variable' canonicalize(object)
Variable(rows = NULL, cols = NULL, name = NA_character_, ...) ## S4 method for signature 'Variable' as.character(x) ## S4 method for signature 'Variable' name(x) ## S4 method for signature 'Variable' value(object) ## S4 method for signature 'Variable' grad(object) ## S4 method for signature 'Variable' variables(object) ## S4 method for signature 'Variable' canonicalize(object)
rows |
The number of rows in the variable. |
cols |
The number of columns in the variable. |
name |
(Optional) A character string representing the name of the variable. |
... |
(Optional) Additional attribute arguments. See Leaf for details. |
x , object
|
A Variable object. |
name(Variable)
: The name of the variable.
value(Variable)
: Get the value of the variable.
grad(Variable)
: The sub/super-gradient of the variable represented as a sparse matrix.
variables(Variable)
: Returns itself as a variable.
canonicalize(Variable)
: The canonical form of the variable.
dim
The dimensions of the variable.
name
(Optional) A character string representing the name of the variable.
x <- Variable(3, name = "x0") ## 3-int variable y <- Variable(3, 3, name = "y0") # Matrix variable as.character(y) id(y) is_nonneg(x) is_nonpos(x) size(y) name(y) value(y) <- matrix(1:9, nrow = 3) value(y) grad(y) variables(y) canonicalize(y)
x <- Variable(3, name = "x0") ## 3-int variable y <- Variable(3, 3, name = "y0") # Matrix variable as.character(y) id(y) is_nonneg(x) is_nonpos(x) size(y) name(y) value(y) <- matrix(1:9, nrow = 3) value(y) grad(y) variables(y) canonicalize(y)
Flattens a matrix into a vector in column-major order.
vec(X)
vec(X)
X |
An Expression or matrix. |
An Expression representing the vectorized matrix.
A <- Variable(2,2) c <- 1:4 expr <- vec(A) obj <- Minimize(t(expr) %*% c) constraints <- list(A == cbind(c(-1,-2), c(3,4))) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(expr)
A <- Variable(2,2) c <- 1:4 expr <- vec(A) obj <- Minimize(t(expr) %*% c) constraints <- list(A == cbind(c(-1,-2), c(3,4))) prob <- Problem(obj, constraints) result <- solve(prob) result$value result$getValue(expr)
Turns symmetric 2D array into a lower triangular matrix
vectorized_lower_tri_to_mat(v, dim)
vectorized_lower_tri_to_mat(v, dim)
v |
A list of length (dim * (dim + 1) / 2). |
dim |
The number of rows (equivalently, columns) in the output array. |
Return the symmetric 2D array defined by taking "v" to specify its lower triangular matrix.
The vertical concatenation of expressions. This is equivalent to rbind
when applied to objects with the same number of columns.
vstack(...)
vstack(...)
... |
Expression objects, vectors, or matrices. All arguments must have the same number of columns. |
An Expression representing the concatenated inputs.
x <- Variable(2) y <- Variable(3) c <- matrix(1, nrow = 1, ncol = 5) prob <- Problem(Minimize(c %*% vstack(x, y)), list(x == c(1,2), y == c(3,4,5))) result <- solve(prob) result$value c <- matrix(1, nrow = 1, ncol = 4) prob <- Problem(Minimize(c %*% vstack(x, x)), list(x == c(1,2))) result <- solve(prob) result$value A <- Variable(2,2) C <- Variable(3,2) c <- matrix(1, nrow = 2, ncol = 2) prob <- Problem(Minimize(sum(vstack(A, C))), list(A >= 2*c, C == -2)) result <- solve(prob) result$value B <- Variable(2,2) c <- matrix(1, nrow = 1, ncol = 2) prob <- Problem(Minimize(sum(vstack(c %*% A, c %*% B))), list(A >= 2, B == -2)) result <- solve(prob) result$value
x <- Variable(2) y <- Variable(3) c <- matrix(1, nrow = 1, ncol = 5) prob <- Problem(Minimize(c %*% vstack(x, y)), list(x == c(1,2), y == c(3,4,5))) result <- solve(prob) result$value c <- matrix(1, nrow = 1, ncol = 4) prob <- Problem(Minimize(c %*% vstack(x, x)), list(x == c(1,2))) result <- solve(prob) result$value A <- Variable(2,2) C <- Variable(3,2) c <- matrix(1, nrow = 2, ncol = 2) prob <- Problem(Minimize(sum(vstack(A, C))), list(A >= 2*c, C == -2)) result <- solve(prob) result$value B <- Variable(2,2) c <- matrix(1, nrow = 1, ncol = 2) prob <- Problem(Minimize(sum(vstack(c %*% A, c %*% B))), list(A >= 2, B == -2)) result <- solve(prob) result$value
Vertical concatenation of values.
VStack(...) ## S4 method for signature 'VStack' to_numeric(object, values) ## S4 method for signature 'VStack' validate_args(object) ## S4 method for signature 'VStack' dim_from_args(object) ## S4 method for signature 'VStack' is_atom_log_log_convex(object) ## S4 method for signature 'VStack' is_atom_log_log_concave(object) ## S4 method for signature 'VStack' graph_implementation(object, arg_objs, dim, data = NA_real_)
VStack(...) ## S4 method for signature 'VStack' to_numeric(object, values) ## S4 method for signature 'VStack' validate_args(object) ## S4 method for signature 'VStack' dim_from_args(object) ## S4 method for signature 'VStack' is_atom_log_log_convex(object) ## S4 method for signature 'VStack' is_atom_log_log_concave(object) ## S4 method for signature 'VStack' graph_implementation(object, arg_objs, dim, data = NA_real_)
... |
Expression objects or matrices. All arguments must have the same number of columns. |
object |
A VStack object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(VStack)
: Vertically concatenate the values using rbind
.
validate_args(VStack)
: Check all arguments have the same width.
dim_from_args(VStack)
: The dimensions of the atom.
is_atom_log_log_convex(VStack)
: Is the atom log-log convex?
is_atom_log_log_concave(VStack)
: Is the atom log-log concave?
graph_implementation(VStack)
: The graph implementation of the atom.
...
Expression objects or matrices. All arguments must have the same number of columns.
This virtual class represents a no-op wrapper to assert properties.
## S4 method for signature 'Wrap' to_numeric(object, values) ## S4 method for signature 'Wrap' dim_from_args(object) ## S4 method for signature 'Wrap' is_atom_log_log_convex(object) ## S4 method for signature 'Wrap' is_atom_log_log_concave(object) ## S4 method for signature 'Wrap' graph_implementation(object, arg_objs, dim, data = NA_real_)
## S4 method for signature 'Wrap' to_numeric(object, values) ## S4 method for signature 'Wrap' dim_from_args(object) ## S4 method for signature 'Wrap' is_atom_log_log_convex(object) ## S4 method for signature 'Wrap' is_atom_log_log_concave(object) ## S4 method for signature 'Wrap' graph_implementation(object, arg_objs, dim, data = NA_real_)
object |
A Wrap object. |
values |
A list of arguments to the atom. |
arg_objs |
A list of linear expressions for each argument. |
dim |
A vector representing the dimensions of the resulting expression. |
data |
A list of additional data required by the atom. |
to_numeric(Wrap)
: Returns the input value.
dim_from_args(Wrap)
: The dimensions of the atom.
is_atom_log_log_convex(Wrap)
: Is the atom log-log convex?
is_atom_log_log_concave(Wrap)
: Is the atom log-log concave?
graph_implementation(Wrap)
: The graph implementation of the atom.
The ZeroConstraint class
## S4 method for signature 'ZeroConstraint' name(x) ## S4 method for signature 'ZeroConstraint' dim(x) ## S4 method for signature 'ZeroConstraint' is_dcp(object) ## S4 method for signature 'ZeroConstraint' is_dgp(object) ## S4 method for signature 'ZeroConstraint' residual(object) ## S4 method for signature 'ZeroConstraint' canonicalize(object)
## S4 method for signature 'ZeroConstraint' name(x) ## S4 method for signature 'ZeroConstraint' dim(x) ## S4 method for signature 'ZeroConstraint' is_dcp(object) ## S4 method for signature 'ZeroConstraint' is_dgp(object) ## S4 method for signature 'ZeroConstraint' residual(object) ## S4 method for signature 'ZeroConstraint' canonicalize(object)
x , object
|
A ZeroConstraint object. |
name(ZeroConstraint)
: The string representation of the constraint.
dim(ZeroConstraint)
: The dimensions of the constrained expression.
is_dcp(ZeroConstraint)
: Is the constraint DCP?
is_dgp(ZeroConstraint)
: Is the constraint DGP?
residual(ZeroConstraint)
: The residual of a constraint
canonicalize(ZeroConstraint)
: The graph implementation of the object.