Skip to contents

Core classes

Variables, parameters, constants, problems, and constraints

Variable()
Create an Optimization Variable
Parameter()
Create a Parameter
Constant()
Create a Constant Expression
Problem()
Create an Optimization Problem
Minimize()
Create a Minimization Objective
Maximize()
Create a Maximization Objective
Equality()
Create an Equality Constraint
Inequality()
Create an Inequality Constraint
NonNeg()
Create a Non-Negative Constraint
NonPos()
Create a Non-Positive Constraint
Zero()
Create a Zero Constraint
PSD()
Create a Positive Semidefinite Constraint
ExpCone()
Create an Exponential Cone Constraint
SOC()
Create a Second-Order Cone Constraint
PowCone3D()
Create a 3D Power Cone Constraint
PowConeND()
Create an N-Dimensional Power Cone Constraint
FiniteSet()
FiniteSet Constraint

Solve interface

Solving problems and extracting results

psolve()
Solve a Convex Optimization Problem
value()
Get the Numeric Value of an Expression
`value<-`()
Set the Value of a Leaf Expression
dual_value()
Get the Dual Value of a Constraint
status()
Get the Solution Status of a Problem
solution()
Get the Raw Solution Object
problem_data()
Get Problem Data for a Solver
solve_via_data()
Solve via Raw Data
problem_unpack_results()
Unpack Solver Results into a Problem
unpack_results() deprecated
Unpack Results (backward-compatible alias)
solver_stats()
Get Solver Statistics
solver_opts()
Create Solver Options
solver_default_param()
Standard Solver Parameter Mappings
installed_solvers()
List installed solvers
available_solvers() exclude_solvers() include_solvers() set_excluded_solvers()
List available solvers
residual()
Get the Residual of a Constraint
violation()
Get the Violation of a Constraint

Solvers

Solver name constants

Status constants

Solution status values

Math and standard function dispatch

Standard R functions that work directly on CVXR expressions. abs, exp, log, sqrt, sum, max, min (group generics); norm, mean, diff (S4 generics); sd, var, outer (masking wrappers).

norm() sd() var() outer() diag()
Standard R Functions for CVXR Expressions

Elementwise atoms

Functions applied element-by-element

entr()
Create an entropy atom -x * log(x)
huber()
Create a Huber loss atom
inv_pos()
Inverse position: \(x^{-1}\) (for x > 0)
kl_div()
KL Divergence: x*log(x/y) - x + y
log1p_atom() log1p_expr()
Log(1 + x) – elementwise
logistic()
Logistic function: log(1 + exp(x)) – elementwise
loggamma()
Elementwise log of the gamma function
log_normcdf()
Elementwise log of the standard normal CDF
neg()
Negative part: -min(x, 0)
pos()
Positive part: max(x, 0)
power()
Create a Power atom
scalene()
Scalene penalty: alpha * pos(x) + beta * neg(x)
square()
Square of an expression: x^2
xexp()
x * exp(x) – elementwise

Aggregation atoms

Functions that reduce or summarize entries

sum_entries()
Sum the entries of an expression
max_entries()
Maximum entry of an expression
min_entries()
Minimum entry of an expression
max_elemwise()
Elementwise maximum of expressions
min_elemwise()
Elementwise minimum of expressions
cumsum_axis()
Cumulative sum along an axis
cummax_expr()
Cumulative maximum along an axis
prod_entries()
Product of entries along an axis
log_sum_exp()
Log-sum-exp: log(sum(exp(x)))
sum_squares()
Sum of squares (= quad_over_lin(x, 1))
sum_largest()
Sum of k largest entries
sum_smallest()
Sum of k smallest entries
geo_mean()
(Weighted) geometric mean of a vector
harmonic_mean()
Harmonic mean: n / sum(1/x_i)
ptp()
Peak-to-peak (range): max(x) - min(x)
cvxr_mean()
Mean of an expression
cvxr_std() std()
Standard deviation of an expression
cvxr_var()
Variance of an expression
cvar()
Conditional Value at Risk (CVaR)

Norm and distance atoms

Norm functions and related atoms

cvxr_norm()
Compute a norm of an expression
p_norm()
General p-norm of an expression
norm1()
L1 norm of an expression
norm2() deprecated
Euclidean norm (deprecated alias)
norm_inf()
L-infinity norm of an expression
norm_nuc()
Nuclear norm (sum of singular values)
mixed_norm()
Mixed norm (\(L_{p,q}\) norm): column-wise p-norm, then q-norm
quad_form()
Quadratic form x^T P x
quad_over_lin()
Sum of squares divided by a scalar
matrix_frac()
Matrix fractional function

Linear algebra atoms

Matrix operations and structural atoms

bmat()
Construct a Block Matrix
conv()
1D discrete convolution
DiagMat()
Extract Diagonal from a Matrix
DiagVec()
Vector to Diagonal Matrix
hstack()
Horizontal concatenation of expressions
vstack()
Vertical concatenation of expressions
kron()
Kronecker product of two expressions
lambda_max()
Maximum eigenvalue
lambda_min()
Minimum eigenvalue
lambda_sum_largest()
Sum of largest k eigenvalues
lambda_sum_smallest()
Sum of smallest k eigenvalues
log_det()
Log-determinant
matrix_trace()
Trace of a square matrix expression
partial_trace()
Partial trace of a tensor product expression
partial_transpose()
Partial transpose of a tensor product expression
reshape_expr()
Reshape an expression to a new shape
sigma_max()
Maximum singular value
upper_tri()
Extract strict upper triangle of a square matrix
vec()
Vectorize an expression (column vector)
vec_to_upper_tri()
Reshape a vector into an upper triangular matrix

Arithmetic and product atoms

Multiplication, dot products, and related

multiply() deprecated
Elementwise multiplication (deprecated)
vdot()
Vector dot product (inner product)
scalar_product()
Scalar product (alias for vdot)
cvxr_outer()
Outer product of two vectors
dotsort()
Weighted sorted dot product
inv_prod()
Reciprocal of product of entries
tr_inv()
Trace of matrix inverse
total_variation()
Total variation of a vector or matrix
tv() deprecated
Total variation (deprecated alias)
cvxr_diff()
Compute kth Order Differences of an Expression

Special atoms

Perspective, DGP, DQCP, and other specialized atoms

perspective()
Perspective Transform
diff_pos()
The difference x - y with domain x > y > 0
resolvent()
Resolvent inverse(sI - X)
one_minus_pos()
The difference 1 - x with domain (0, 1)
eye_minus_inv()
Unity resolvent (I - X) inverse for positive square matrix X
pf_eigenvalue()
Perron-Frobenius eigenvalue of a positive matrix
gmatmul()
Geometric matrix multiplication A diamond X
ceil_expr()
Elementwise Ceiling
floor_expr()
Elementwise Floor
condition_number()
Condition number of a PSD matrix
gen_lambda_max()
Maximum generalized eigenvalue
dist_ratio()
Distance ratio
indicator()
Indicator function for constraints

Logic atoms

Boolean logic operations for mixed-integer problems

And()
Logical AND
Or()
Logical OR
Not()
Logical NOT
Xor()
Logical XOR
implies()
Logical Implication
iff()
Logical Biconditional

Constraint operators

Operators for creating constraints

`%>>%`
Positive Semidefinite Constraint Operator
`%<<%`
Negative Semidefinite Constraint Operator

Expression properties

Query properties of CVXR expressions

curvature()
Get Expression Curvature
expr_sign()
Get the DCP Sign of an Expression
is_affine()
Check if an Expression is Affine
is_concave()
Check if an Expression is Concave
is_constant()
Check if an Expression is Constant
is_convex()
Check if an Expression is Convex
is_dcp()
Check if an Expression is DCP-Compliant
is_dgp()
Check if a Constraint is DGP-Compliant
is_dpp()
Check DPP Compliance
is_dqcp()
Check if Expression is DQCP-Compliant
is_log_log_affine()
Check if Expression is Log-Log Affine
is_log_log_concave()
Check if Expression is Log-Log Concave
is_log_log_convex()
Check if Expression is Log-Log Convex
is_lp()
Check if a Problem is a Linear Program
is_matrix()
Is the Expression a Matrix?
is_mixed_integer()
Check if a Problem is Mixed-Integer
is_nonneg()
Check if Expression is Non-Negative
is_nonpos()
Check if Expression is Non-Positive
is_nsd()
Check if Expression is Negative Semidefinite
is_psd()
Check if Expression is Positive Semidefinite
is_pwl()
Check if Expression is Piecewise Linear
is_qp()
Check if a Problem is a Quadratic Program
is_quadratic()
Check if an Expression is Quadratic
is_quasiconcave()
Check if Expression is Quasiconcave
is_quasiconvex()
Check if Expression is Quasiconvex
is_quasilinear()
Check if Expression is Quasilinear
is_scalar()
Is the Expression a Scalar?
is_symmetric()
Check if Expression is Symmetric
is_vector()
Is the Expression a Vector?
is_zero()
Check if Expression is Zero
length_expr()
Length of a Vector (Last Nonzero Index)
size()
Get Expression Size
name()
Get Expression Name
id()
Get Expression ID
set_label()
Set a Label on a Constraint

Problem properties

Extract components from a Problem object

objective()
Get Problem Objective (read-only)
constraints()
Get Problem Constraints (read-only)
variables()
Get the Variables in an Expression
parameters()
Get the Parameters in an Expression
constants()
Get the Constants in an Expression

Utilities

Helpers and introspection

as_cvxr_expr()
Convert a value to a CVXR Expression
visualize()
Visualize the Canonicalization Pipeline of a CVXR Problem
to_latex()
Convert CVXR Object to LaTeX
expr_H()
Conjugate-Transpose of an Expression
make_sparse_diagonal_matrix()
Make a CSC sparse diagonal matrix
rel_entr()
Relative Entropy: x*log(x/y)

Data

Example datasets

cdiac
Global Monthly and Annual Temperature Anomalies (degrees C), 1850-2015 (Relative to the 1961-1990 Mean) (May 2016)
dspop
Direct Standardization: Population
dssamp
Direct Standardization: Sample

Deprecated

Backward-compatible aliases (use the new names instead)

get_problem_data() deprecated
Get Problem Data for a Solver (deprecated)
problem_status() deprecated
Get the Solution Status of a Problem (deprecated)
problem_solution() deprecated
Get the Raw Solution Object (deprecated)