Learn R Programming

CVXR

CVXR provides an object-oriented modeling language for convex optimization, similar to CVX, CVXPY, YALMIP, and Convex.jl. It allows the user to formulate convex optimization problems in a natural mathematical syntax rather than the restrictive standard form required by most solvers. The user specifies an objective and set of constraints by combining constants, variables, and parameters using a library of functions with known mathematical properties. CVXR then applies signed disciplined convex programming (DCP) to verify the problem’s convexity. Once verified, the problem is converted into standard conic form using graph implementations and passed to a cone solver such as ECOS or SCS.

CVXR includes several open source solvers in addition to the default OSQP, ECOS and SCS. Recent (1.x+) versions also include support for commercial solvers such as MOSEK, GUROBI and CPLEX.

For details and examples, we refer you to Fu, Narasimhan, Boyd (2020). If you use CVXR in your work, please cite this reference. (The R command citation("CVXR", bibtex = TRUE) will also give you a bibtex-formatted entry.)

Installation

This package is now released on CRAN, so you can install the current released version as you would any other package for R, version 3.4 and higher. (CVXR is known to work with earlier versions of R too, but we don't check our releases against older versions of R.)

install.packages('CVXR', repos = "https://CRAN.R-project.org")

Development versions can be installed from the Github repository assuming you have the development tools for R available, including the C compilers etc. Execute:

library(devtools)
install_github("cvxgrp/CVXR")

Tutorial

A number of tutorial examples are available on the CVXR website along with links to our useR! 2019 short-course.

Copy Link

Version

Install

install.packages('CVXR')

Monthly Downloads

8,918

Version

1.0-14

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

June 27th, 2024

Functions in CVXR (1.0-14)

AffAtom-class

The AffAtom class.
CLARABEL.extract_dual_value

Extracts the dual value for constraint starting at offset.
BinaryOperator-class

The BinaryOperator class.
Atom-class

The Atom class.
+,Expression,missing-method

The AddExpression class.
CLARABEL.dims_to_solver_dict

Utility method for formatting a ConeDims instance into a dictionary that can be supplied to Clarabel
CBC_CONIC-class

An interface to the CBC solver
Abs-class

The Abs class.
CLARABEL-class

An interface for the CLARABEL solver
AxisAtom-class

The AxisAtom class.
Chain-class

The Chain class.
CPLEX_CONIC-class

An interface for the CPLEX solver
Canonicalization-class

The Canonicalization class.
Canonical-class

The Canonical class.
Complex2Real.abs_canon

Complex canonicalizer for the absolute value atom
CVXOPT-class

An interface for the CVXOPT solver.
CPLEX_QP-class

An interface for the CPLEX solver.
Complex2Real-class

Lifts complex numbers to a real representation.
CVXR-package

CVXR: Disciplined Convex Optimization in R
CallbackParam-class

The CallbackParam class.
Complex2Real.conj_canon

Complex canonicalizer for the conjugate atom
Complex2Real.canonicalize_tree

Recursively Canonicalizes a Complex Expression.
Complex2Real.norm_nuc_canon

Complex canonicalizer for the nuclear norm atom
Complex2Real.at_least_2D

Upcast 0D and 1D to 2D.
Complex2Real.add

Helper function to sum arguments.
Complex2Real.nonpos_canon

Complex canonicalizer for the non-positive atom
Complex2Real.constant_canon

Complex canonicalizer for the constant atom
Complex2Real.hermitian_canon

Complex canonicalizer for the hermitian atom
Complex2Real.psd_canon

Complex canonicalizer for the positive semidefinite atom
Complex2Real.canonicalize_expr

Canonicalizes a Complex Expression
Complex2Real.binary_canon

Complex canonicalizer for the binary atom
Complex2Real.quad_over_lin_canon

Complex canonicalizer for the quadratic over linear term atom
Complex2Real.imag_canon

Complex canonicalizer for the imaginary atom
Complex2Real.quad_canon

Complex canonicalizer for the quadratic atom
Complex2Real.variable_canon

Complex canonicalizer for the variable atom
Complex2Real.zero_canon

Complex canonicalizer for the zero atom
Complex2Real.real_canon

Complex canonicalizer for the real atom
ConicSolver.get_coeff_offset

Return the coefficient and offset in \(Ax + b\).
ConicSolver-class

The ConicSolver class.
Dcp2Cone-class

Reduce DCP Problem to Conic Form
CvxAttr2Constr-class

The CvxAttr2Constr class.
Complex2Real.join

Helper function to combine arguments.
Constant-class

The Constant class.
ConstantSolver-class

The ConstantSolver class.
Complex2Real.matrix_frac_canon

Complex canonicalizer for the matrix fraction atom
Complex2Real.lambda_sum_largest_canon

Complex canonicalizer for the largest sum atom
Dcp2Cone.log1p_canon

Dcp2Cone canonicalizer for the log 1p atom
Constraint-class

The Constraint class.
Complex2Real.param_canon

Complex canonicalizer for the parameter matrix atom
Complex2Real.pnorm_canon

Complex canonicalizer for the p norm atom
Dcp2Cone.geo_mean_canon

Dcp2Cone canonicalizer for the geometric mean atom
Dcp2Cone.log_canon

Dcp2Cone canonicalizer for the log atom
Dcp2Cone.huber_canon

Dcp2Cone canonicalizer for the huber atom
Complex2Real.separable_canon

Complex canonicalizer for the separable atom
Complex2Real.soc_canon

Complex canonicalizer for the SOC atom
Dcp2Cone.quad_form_canon

Dcp2Cone canonicalizer for the quadratic form atom
Dcp2Cone.sigma_max_canon

Dcp2Cone canonicalizer for the sigma max atom
ConicSolver.get_spacing_matrix

Returns a sparse matrix that spaces out an expression.
Dgp2Dcp.add_canon

Dgp2Dcp canonicalizer for the addition atom
ConeDims-class

Summary of cone dimensions present in constraints.
Dcp2Cone.entr_canon

Dcp2Cone canonicalizer for the entropy atom
Dcp2Cone.exp_canon

Dcp2Cone canonicalizer for the exponential atom
ConeMatrixStuffing-class

Construct Matrices for Linear Cone Problems
Dcp2Cone.log_det_canon

Dcp2Cone canonicalizer for the log determinant atom
Conv-class

The Conv class.
Dcp2Cone.power_canon

Dcp2Cone canonicalizer for the power atom
Dcp2Cone.lambda_sum_largest_canon

Dcp2Cone canonicalizer for the largest lambda sum atom
Dcp2Cone.lambda_max_canon

Dcp2Cone canonicalizer for the lambda maximization atom
Dgp2Dcp.geo_mean_canon

Dgp2Dcp canonicalizer for the geometric mean atom
Dgp2Dcp.log_canon

Dgp2Dcp canonicalizer for the log atom
Dgp2Dcp.pf_eigenvalue_canon

Dgp2Dcp canonicalizer for the spectral radius atom
Dgp2Dcp.parameter_canon

Dgp2Dcp canonicalizer for the parameter atom
Dgp2Dcp.constant_canon

Dgp2Dcp canonicalizer for the constant atom
Dcp2Cone.log_sum_exp_canon

Dcp2Cone canonicalizer for the log sum of the exp atom
Dgp2Dcp.mul_canon

Dgp2Dcp canonicalizer for the multiplication atom
Conjugate-class

The Conjugate class.
CumMax-class

The CumMax class.
Dcp2Cone.normNuc_canon

Dcp2Cone canonicalizer for the nuclear norm atom
Dgp2Dcp.exp_canon

Dgp2Dcp canonicalizer for the exp atom
Dgp2Dcp.power_canon

Dgp2Dcp canonicalizer for the power atom
Dcp2Cone.pnorm_canon

Dcp2Cone canonicalizer for the p norm atom
EliminatePwl.min_elemwise_canon

EliminatePwl canonicalizer for the elementwise minimum atom
DiffPos

The DiffPos atom.
EliminatePwl.max_entries_canon

EliminatePwl canonicalizer for the max entries atom
Diff

Takes the k-th order differences
Dgp2Dcp.nonpos_constr_canon

Dgp2Dcp canonicalizer for the non-positive constraint atom
Dcp2Cone.quad_over_lin_canon

Dcp2Cone canonicalizer for the quadratic over linear term atom
DiagVec-class

The DiagVec class.
Dgp2Dcp.norm1_canon

Dgp2Dcp canonicalizer for the 1 norm atom
Dgp2Dcp.quad_over_lin_canon

Dgp2Dcp canonicalizer for the quadratic over linear term atom
Dgp2Dcp.sum_canon

Dgp2Dcp canonicalizer for the sum atom
Dcp2Cone.logistic_canon

Dcp2Cone canonicalizer for the logistic function atom
Dcp2Cone.matrix_frac_canon

Dcp2Cone canonicalizer for the matrix fraction atom
EliminatePwl-class

The EliminatePwl class.
DiagMat-class

The DiagMat class.
Expression-class

The Expression class.
LambdaMax-class

The LambdaMax class.
ExpCone-class

The ExpCone class.
HarmonicMean

The HarmonicMean atom.
Elementwise-class

The Elementwise class.
Dgp2Dcp.quad_form_canon

Dgp2Dcp canonicalizer for the quadratic form atom
Dgp2Dcp.div_canon

Dgp2Dcp canonicalizer for the division atom
MatrixFrac-class

The MatrixFrac class.
MOSEK.recover_dual_variables

Recovers MOSEK solutions dual variables
LambdaMin

The LambdaMin atom.
InverseData-class

The InverseData class.
Dgp2Dcp.one_minus_pos_canon

Dgp2Dcp canonicalizer for the 1-x atom
Dgp2Dcp.norm_inf_canon

Dgp2Dcp canonicalizer for the infinite norm atom
Maximize-class

The Maximize class.
Dgp2Dcp.prod_canon

Dgp2Dcp canonicalizer for the product atom
MOSEK.parse_dual_vars

Parses MOSEK dual variables into corresponding CVXR constraints and dual values
Dgp2Dcp.trace_canon

Dgp2Dcp canonicalizer for the trace atom
Huber-class

The Huber class.
<=,Expression,Expression-method

The IneqConstraint class
DgpCanonMethods-class

DGP canonical methods class.
Dgp2Dcp.zero_constr_canon

Dgp2Dcp canonicalizer for the zero constraint atom
Dgp2Dcp.pnorm_canon

Dgp2Dcp canonicalizer for the p norm atom
MatrixStuffing-class

The MatrixStuffing class.
CumSum-class

The CumSum class.
Dgp2Dcp.eye_minus_inv_canon

Dgp2Dcp canonicalizer for the \((I - X)^{-1}\) atom
EliminatePwl.abs_canon

EliminatePwl canonicalizer for the absolute atom
GeoMean-class

The GeoMean class.
Diag

Turns an expression into a DiagVec object
EliminatePwl.cummax_canon

EliminatePwl canonicalizer for the cumulative max atom
EliminatePwl.min_entries_canon

EliminatePwl canonicalizer for the minimum entries atom
Entr-class

The Entr class.
Imag-class

The Imag class.
MaxEntries-class

The MaxEntries class.
EliminatePwl.sum_largest_canon

EliminatePwl canonicalizer for the largest sum atom
GLPK-class

An interface for the GLPK solver.
EliminatePwl.norm_inf_canon

EliminatePwl canonicalizer for the infinite norm atom
GUROBI_CONIC-class

An interface for the GUROBI conic solver.
/,Expression,Expression-method

The DivExpression class.
Parameter-class

The Parameter class.
ECOS-class

An interface for the ECOS solver
PfEigenvalue-class

The PfEigenvalue class.
GUROBI_QP-class

An interface for the GUROBI_QP solver.
ECOS_BB-class

An interface for the ECOS BB solver.
LambdaSumSmallest

The LambdaSumSmallest atom.
LambdaSumLargest-class

The LambdaSumLargest class.
ECOS.dims_to_solver_dict

Utility method for formatting a ConeDims instance into a dictionary that can be supplied to ECOS.
EliminatePwl.norm1_canon

EliminatePwl canonicalizer for the 1 norm atom
GLPK_MI-class

An interface for the GLPK MI solver.
==,Expression,Expression-method

The EqConstraint class
Kron-class

The Kron class.
MixedNorm

The MixedNorm atom.
%*%,Expression,Expression-method

The MulExpression class.
ListORConstr-class

A Class Union of List and Constraint
NonlinearConstraint-class

The NonlinearConstraint class.
Leaf-class

The Leaf class.
Problem-class

The Problem class.
Norm

The Norm atom.
Pnorm-class

The Pnorm class.
Rdictdefault-class

The Rdictdefault class.
[,Expression,missing,missing,ANY-method

The Index class.
Logistic-class

The Logistic class.
MaxElemwise-class

The MaxElemwise class.
MOSEK-class

An interface for the MOSEK solver.
Multiply-class

The Multiply class.
Neg

An alias for -MinElemwise(x, 0)
Pos

An alias for MaxElemwise(x, 0)
MinElemwise-class

The MinElemwise class.
%>>%

The PSDConstraint class.
ProdEntries-class

The ProdEntries class.
HStack-class

The HStack class.
SumLargest-class

The SumLargest class.
KLDiv-class

The KLDiv class.
LogDet-class

The LogDet class.
LogSumExp-class

The LogSumExp class.
QuadForm-class

The QuadForm class.
MinEntries-class

The MinEntries class.
SCS.extract_dual_value

Extracts the dual value for constraint starting at offset.
QpSolver-class

A QP solver interface.
QpMatrixStuffing-class

The QpMatrixStuffing class.
Minimize-class

The Minimize class.
NonPosConstraint-class

The NonPosConstraint class
SCS.dims_to_solver_dict

Utility method for formatting a ConeDims instance into a dictionary that can be supplied to SCS.
OSQP-class

An interface for the OSQP solver.
NormNuc-class

The NormNuc class.
NormInf-class

The NormInf class.
SCS-class

An interface for the SCS solver
UpperTri-class

The UpperTri class.
Reduction-class

The Reduction class.
-,Expression,missing-method

The NegExpression class.
Objective-class

The Objective class.
OneMinusPos-class

The OneMinusPos class.
SizeMetrics-class

The SizeMetrics class.
SOC-class

The SOC class.
PSDWrap-class

The PSDWrap class.
EliminatePwl.cumsum_canon

EliminatePwl canonicalizer for the cumulative sum atom
Solution-class

The Solution class.
Real-class

The Real class.
Dcp2Cone.kl_div_canon

Dcp2Cone canonicalizer for the KL Divergence atom
Dcp2Cone.indicator_canon

Dcp2Cone canonicalizer for the indicator atom
ZeroConstraint-class

The ZeroConstraint class
VStack-class

The VStack class.
SumSmallest

The SumSmallest atom.
diff,Expression-method

Lagged and Iterated Differences
Dgp2Dcp-class

Reduce DGP problems to DCP problems.
EyeMinusInv-class

The EyeMinusInv class.
bmat

Block Matrix
Rdict-class

The Rdict class.
Qp2SymbolicQp-class

The Qp2SymbolicQp class.
Objective-arith

Arithmetic Operations on Objectives
Promote-class

The Promote class.
QuadOverLin-class

The QuadOverLin class.
SolverStats-class

The SolverStats class.
Variable-class

The Variable class.
TotalVariation

The TotalVariation atom.
Norm1-class

The Norm1 class.
curvature

Curvature of Expression
EliminatePwl.max_elemwise_canon

EliminatePwl canonicalizer for the elementwise maximum atom
Dgp2Dcp.mulexpression_canon

Dgp2Dcp canonicalizer for the multiplication expression atom
canonicalize

Canonicalize
Trace-class

The Trace class.
abs,Expression-method

Absolute Value
EvalParams-class

The EvalParams class.
Norm2

The Norm2 atom.
SumEntries-class

The SumEntries class.
UnaryOperator-class

The UnaryOperator class.
.LinOp__set_dense_data

Set the field dense_data of the LinOp object
Transpose-class

The Transpose class.
complex-methods

Complex Properties
cone-methods

Second-Order Cone Methods
SolvingChain-class

The SolvingChain class.
are_args_affine

Are the arguments affine?
curvature-methods

Curvature Properties
domain

Domain
.LinOp_at_index

Return the LinOp element at index i (0-based)
Wrap-class

The Wrap class.
diag,Expression-method

Matrix Diagonal
dim_from_args

Atom Dimensions
.LinOp__get_sparse_data

Get the field named sparse_data from the LinOp object
constr_value

Is Constraint Violated?
.LinOp__get_sparse

Get the sparse flag field for the LinOp object
.LinOp__size_push_back

Perform a push back operation on the size field of LinOp
.LinOp__get_type

Get the field named type for the LinOp object
Exp-class

The Exp class.
Log-class

The Log class.
FlipObjective-class

The FlipObjective class.
.LinOp__get_dense_data

Get the field dense_data for the LinOp object
construct_intermediate_chain,Problem,list-method

Builds a chain that rewrites a problem into an intermediate representation suitable for numeric reductions.
.LinOp__get_id

Get the id field of the LinOp Object
.ProblemData__new

Create a new ProblemData object.
.LinOp__get_size

Get the field size for the LinOp object
Log1p-class

The Log1p class.
.LinOp__slice_push_back

Perform a push back operation on the slice field of LinOp
eye_minus_inv

Unity Resolvent
SigmaMax-class

The SigmaMax class.
format_constr

Format Constraints
lambda_sum_largest

Sum of Largest Eigenvalues
.LinOp__set_size

Set the field size of the LinOp object
lambda_min

Minimum Eigenvalue
SumSquares

The SumSquares atom.
get_problem_data

Get Problem Data
conv

Discrete Convolution
ReductionSolver-class

The ReductionSolver class.
.ProblemData__get_const_to_row

Get the const_to_row field of the ProblemData Object
import_solver

Import Solver
installed_solvers

List installed solvers
[,Expression,index,missing,ANY-method

The SpecialIndex class.
Power-class

The Power class.
SOCAxis-class

The SOCAxis class.
Reshape-class

The Reshape class.
.LinOp__set_sparse

Set the flag sparse of the LinOp object
.build_matrix_0

Get the sparse flag field for the LinOp object
.LinOpVector__new

Create a new LinOpVector object.
.build_matrix_1

Get the sparse flag field for the LinOp object
problem-parts

Parts of a Problem
.LinOp__new

Create a new LinOp object.
.LinOp__set_slice

Set the slice field of the LinOp Object
cdiac

Global Monthly and Annual Temperature Anomalies (degrees C), 1850-2015 (Relative to the 1961-1990 Mean) (May 2016)
accepts

Reduction Acceptance
.LinOp__set_sparse_data

Set the field named sparse_data of the LinOp object
curvature-atom

Curvature of an Atom
cvxr_norm

Matrix Norm (Alternative)
get_data

Get Expression Data
make_sparse_diagonal_matrix

Make a CSC sparse diagonal matrix
.ProblemData__get_I

Get the I field of the ProblemData Object
.LinOp__args_push_back

Perform a push back operation on the args field of LinOp
mip_capable

Solver Capabilities
is_qp

Is Problem a QP?
is_mixed_integer

Is Problem Mixed Integer?
norm1

1-Norm
huber

Huber Function
log,Expression-method

Logarithms
extract_dual_value

Gets a specified value of a dual variable.
extract_mip_idx

Coalesces bool, int indices for variables.
mean.Expression

Arithmetic Mean
scalene

Scalene Function
min_elemwise

Elementwise Minimum
.ProblemData__get_const_vec

Get the const_vec field from the ProblemData Object
.ProblemData__get_id_to_col

Get the id_to_col field of the ProblemData Object
graph_implementation

Graph Implementation
Problem-arith

Arithmetic Operations on Problems
harmonic_mean

Harmonic Mean
get_id

Get ID
geo_mean

Geometric Mean
linearize

Affine Approximation to an Expression
id

Identification Number
project-methods

Project Value
is_stuffed_cone_constraint

Is the constraint a stuffed cone constraint?
curvature-comp

Curvature of Composition
dual_value-methods

Get and Set Dual Value
.ProblemData__get_J

Get the J field of the ProblemData Object
construct_solving_chain

Build a reduction chain from a problem to an installed solver.
complex-atoms

Complex Numbers
min_entries

Minimum
.ProblemData__set_const_to_row

Set the const_to_row map of the ProblemData Object
cummax_axis

Cumulative Maximum
SymbolicQuadForm-class

The SymbolicQuadForm class.
norm2

Euclidean Norm
matrix_frac

Matrix Fraction
psd_coeff_offset

Given a problem returns a PSD constraint
is_stuffed_cone_objective

Is the objective a stuffed cone objective?
tv

Total Variation
.LinOp__set_type

Set the field named type for the LinOp object
p_norm

P-Norm
quad_over_lin

Quadratic over Linear
sign,Expression-method

Sign of Expression
one_minus_pos

Difference on Restricted Domain
get_sp

Get scipy handle
log_sum_exp

Log-Sum-Exponential
scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
sum_entries

Sum of Entries
prod_entries

Product of Entries
.ProblemData__set_id_to_col

Set the id_to_col field of the ProblemData Object
cumsum_axis

Cumulative Sum
log_det

Log-Determinant
scaled_upper_tri

Utility methods for special handling of semidefinite constraints.
.ProblemData__set_I

Set the I field in the ProblemData Object
sum_smallest

Sum of Smallest Values
reduce

Reduce a Problem
sum_squares

Sum of Squares
setIdCounter

Set ID Counter
to_numeric

Numeric Value of Atom
size-methods

Size Properties
.LinOp__get_slice

Get the slice field of the LinOp Object
unpack_results

Parse output from a solver and updates problem state
hstack

Horizontal Concatenation
sum_largest

Sum of Largest Values
.ProblemData__set_J

Set the J field in the ProblemData Object
sigma_max

Maximum Singular Value
.ProblemData__set_const_vec

Set the const_vec field in the ProblemData Object
.LinOpVector__push_back

Perform a push back operation on the args field of LinOp
neg

Elementwise Negative
.ProblemData__get_V

Get the V field of the ProblemData Object
max_entries

Maximum
.ProblemData__set_V

Set the V field in the ProblemData Object
max_elemwise

Elementwise Maximum
dspop

Direct Standardization: Population
entr

Entropy Function
validate_args

Validate Arguments
validate_val

Validate Value
get_dual_values

Gets the values of the dual variables.
resetOptions

Reset Options
dssamp

Direct Standardization: Sample
tri_to_full

Expands lower triangular to full matrix.
norm,Expression,character-method

Matrix Norm
perform

Perform Reduction
exp,Expression-method

Natural Exponential
log_log_curvature-atom

Log-Log Curvature of an Atom
invert

Return Original Solution
expression-parts

Parts of an Expression Leaf
norm_nuc

Nuclear Norm
norm_inf

Infinity-Norm
is_dgp

DGP Compliance
is_dcp

DCP Compliance
.decomp_quad

Compute a Matrix Decomposition.
pf_eigenvalue

Perron-Frobenius Eigenvalue
matrix_prop-methods

Matrix Properties
matrix_trace

Matrix Trace
grad

Sub/Super-Gradient
sign-methods

Sign Properties
t.Expression

Matrix Transpose
size

Size of Expression
upper_tri

Upper Triangle of a Matrix
updated_scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
get_np

Get numpy handle
vectorized_lower_tri_to_mat

Turns symmetric 2D array into a lower triangular matrix
.p_norm

Internal method for calculating the p-norm
reshape_expr

Reshape an Expression
inv_pos

Reciprocal Function
pos

Elementwise Positive
kl_div

Kullback-Leibler Divergence
leaf-attr

Attributes of an Expression Leaf
group_constraints

Organize the constraints into a dictionary keyed by constraint names.
lambda_sum_smallest

Sum of Smallest Eigenvalues
multiply

Elementwise Multiplication
mixed_norm

Mixed Norm
is_stuffed_qp_objective

Is the QP objective stuffed?
triu_to_full

Expands upper triangular to full matrix.
value-methods

Get or Set Value
residual-methods

Constraint Residual
square,Expression-method

Square
^,Expression,numeric-method

Elementwise Power
*,Expression,Expression-method

Elementwise multiplication operator
kronecker,Expression,ANY-method

Kronecker Product
lambda_max

Maximum Eigenvalue
retrieve

Retrieve Solution
log_log_curvature

Log-Log Curvature of Expression
log_log_curvature-methods

Log-Log Curvature Properties
sqrt,Expression-method

Square Root
vec

Vectorization of a Matrix
sign_from_args

Atom Sign
quad_form

Quadratic Form
vstack

Vertical Concatenation
psolve

Solve a DCP Problem
logistic

Logistic Function
name

Variable, Parameter, or Expression Name