Learn R Programming

⚠️There's a newer version (1.0-14) of this package.Take me there.

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,278

Version

1.0-12

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

February 2nd, 2024

Functions in CVXR (1.0-12)

AxisAtom-class

The AxisAtom class.
BinaryOperator-class

The BinaryOperator class.
Atom-class

The Atom class.
Abs-class

The Abs class.
+,Expression,missing-method

The AddExpression class.
CBC_CONIC-class

An interface to the CBC solver
CPLEX_QP-class

An interface for the CPLEX solver.
CVXOPT-class

An interface for the CVXOPT solver.
AffAtom-class

The AffAtom class.
Complex2Real.at_least_2D

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

Complex canonicalizer for the absolute value atom
CPLEX_CONIC-class

An interface for the CPLEX solver
Chain-class

The Chain class.
Complex2Real-class

Lifts complex numbers to a real representation.
Canonical-class

The Canonical class.
CVXR-package

CVXR: Disciplined Convex Optimization in R
CallbackParam-class

The CallbackParam class.
Canonicalization-class

The Canonicalization class.
Complex2Real.add

Helper function to sum arguments.
Complex2Real.matrix_frac_canon

Complex canonicalizer for the matrix fraction atom
Complex2Real.canonicalize_expr

Canonicalizes a Complex Expression
Complex2Real.canonicalize_tree

Recursively Canonicalizes a Complex Expression.
Complex2Real.constant_canon

Complex canonicalizer for the constant atom
Complex2Real.binary_canon

Complex canonicalizer for the binary atom
Complex2Real.pnorm_canon

Complex canonicalizer for the p norm atom
Complex2Real.psd_canon

Complex canonicalizer for the positive semidefinite atom
Complex2Real.conj_canon

Complex canonicalizer for the conjugate atom
Complex2Real.nonpos_canon

Complex canonicalizer for the non-positive atom
Complex2Real.real_canon

Complex canonicalizer for the real atom
Complex2Real.hermitian_canon

Complex canonicalizer for the hermitian atom
ConicSolver-class

The ConicSolver class.
Complex2Real.imag_canon

Complex canonicalizer for the imaginary atom
Complex2Real.quad_canon

Complex canonicalizer for the quadratic atom
Complex2Real.soc_canon

Complex canonicalizer for the SOC atom
Dcp2Cone.entr_canon

Dcp2Cone canonicalizer for the entropy atom
Complex2Real.lambda_sum_largest_canon

Complex canonicalizer for the largest sum atom
Complex2Real.join

Helper function to combine arguments.
ConeMatrixStuffing-class

Construct Matrices for Linear Cone Problems
Complex2Real.variable_canon

Complex canonicalizer for the variable atom
Complex2Real.norm_nuc_canon

Complex canonicalizer for the nuclear norm atom
ConstantSolver-class

The ConstantSolver class.
Dcp2Cone.log_det_canon

Dcp2Cone canonicalizer for the log determinant atom
Conjugate-class

The Conjugate class.
Complex2Real.param_canon

Complex canonicalizer for the parameter matrix atom
Dcp2Cone.log_canon

Dcp2Cone canonicalizer for the log atom
Dcp2Cone-class

Reduce DCP Problem to Conic Form
Complex2Real.quad_over_lin_canon

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

Complex canonicalizer for the separable atom
Constant-class

The Constant class.
CvxAttr2Constr-class

The CvxAttr2Constr class.
Complex2Real.zero_canon

Complex canonicalizer for the zero atom
Dcp2Cone.exp_canon

Dcp2Cone canonicalizer for the exponential atom
Dgp2Dcp.div_canon

Dgp2Dcp canonicalizer for the division atom
Dgp2Dcp.norm_inf_canon

Dgp2Dcp canonicalizer for the infinite norm atom
Dcp2Cone.log_sum_exp_canon

Dcp2Cone canonicalizer for the log sum of the exp atom
Dcp2Cone.geo_mean_canon

Dcp2Cone canonicalizer for the geometric mean atom
Dgp2Dcp.one_minus_pos_canon

Dgp2Dcp canonicalizer for the 1-x atom
Dgp2Dcp.parameter_canon

Dgp2Dcp canonicalizer for the parameter atom
ConeDims-class

Summary of cone dimensions present in constraints.
Dcp2Cone.logistic_canon

Dcp2Cone canonicalizer for the logistic function atom
Dgp2Dcp.exp_canon

Dgp2Dcp canonicalizer for the exp atom
Dgp2Dcp.pf_eigenvalue_canon

Dgp2Dcp canonicalizer for the spectral radius atom
Conv-class

The Conv class.
Dcp2Cone.indicator_canon

Dcp2Cone canonicalizer for the indicator atom
Dcp2Cone.huber_canon

Dcp2Cone canonicalizer for the huber atom
ConicSolver.get_coeff_offset

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

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

Dgp2Dcp canonicalizer for the log atom
CumMax-class

The CumMax class.
Dgp2Dcp.mulexpression_canon

Dgp2Dcp canonicalizer for the multiplication expression atom
Dcp2Cone.quad_form_canon

Dcp2Cone canonicalizer for the quadratic form atom
Dcp2Cone.lambda_max_canon

Dcp2Cone canonicalizer for the lambda maximization atom
Dcp2Cone.kl_div_canon

Dcp2Cone canonicalizer for the KL Divergence atom
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
Dgp2Dcp.prod_canon

Dgp2Dcp canonicalizer for the product atom
Constraint-class

The Constraint class.
Dcp2Cone.matrix_frac_canon

Dcp2Cone canonicalizer for the matrix fraction atom
Dcp2Cone.sigma_max_canon

Dcp2Cone canonicalizer for the sigma max atom
Dcp2Cone.normNuc_canon

Dcp2Cone canonicalizer for the nuclear norm atom
ECOS_BB-class

An interface for the ECOS BB solver.
Dcp2Cone.pnorm_canon

Dcp2Cone canonicalizer for the p norm atom
Dgp2Dcp.mul_canon

Dgp2Dcp canonicalizer for the multiplication atom
Dcp2Cone.power_canon

Dcp2Cone canonicalizer for the power atom
CumSum-class

The CumSum class.
Dgp2Dcp-class

Reduce DGP problems to DCP problems.
DiagMat-class

The DiagMat class.
EliminatePwl.min_elemwise_canon

EliminatePwl canonicalizer for the elementwise minimum atom
Dgp2Dcp.sum_canon

Dgp2Dcp canonicalizer for the sum atom
Diag

Turns an expression into a DiagVec object
Dgp2Dcp.trace_canon

Dgp2Dcp canonicalizer for the trace atom
Dgp2Dcp.norm1_canon

Dgp2Dcp canonicalizer for the 1 norm atom
DiagVec-class

The DiagVec class.
EliminatePwl.max_elemwise_canon

EliminatePwl canonicalizer for the elementwise maximum atom
EliminatePwl.cummax_canon

EliminatePwl canonicalizer for the cumulative max atom
Dgp2Dcp.pnorm_canon

Dgp2Dcp canonicalizer for the p norm atom
Dgp2Dcp.zero_constr_canon

Dgp2Dcp canonicalizer for the zero constraint atom
DgpCanonMethods-class

DGP canonical methods class.
GUROBI_CONIC-class

An interface for the GUROBI conic solver.
Dgp2Dcp.eye_minus_inv_canon

Dgp2Dcp canonicalizer for the \((I - X)^{-1}\) atom
Exp-class

The Exp class.
EliminatePwl.cumsum_canon

EliminatePwl canonicalizer for the cumulative sum atom
==,Expression,Expression-method

The EqConstraint class
GLPK_MI-class

An interface for the GLPK MI solver.
MaxElemwise-class

The MaxElemwise class.
EvalParams-class

The EvalParams class.
EliminatePwl.max_entries_canon

EliminatePwl canonicalizer for the max entries atom
Minimize-class

The Minimize class.
LambdaMax-class

The LambdaMax class.
Kron-class

The Kron class.
MatrixStuffing-class

The MatrixStuffing class.
GUROBI_QP-class

An interface for the GUROBI_QP solver.
MixedNorm

The MixedNorm atom.
EliminatePwl.min_entries_canon

EliminatePwl canonicalizer for the minimum entries atom
LogSumExp-class

The LogSumExp class.
EliminatePwl-class

The EliminatePwl class.
Elementwise-class

The Elementwise class.
FlipObjective-class

The FlipObjective class.
NormInf-class

The NormInf class.
Diff

Takes the k-th order differences
MaxEntries-class

The MaxEntries class.
Problem-class

The Problem class.
GLPK-class

An interface for the GLPK solver.
Norm2

The Norm2 atom.
Problem-arith

Arithmetic Operations on Problems
LogDet-class

The LogDet class.
Dgp2Dcp.constant_canon

Dgp2Dcp canonicalizer for the constant atom
Dcp2Cone.lambda_sum_largest_canon

Dcp2Cone canonicalizer for the largest lambda sum atom
EliminatePwl.abs_canon

EliminatePwl canonicalizer for the absolute atom
Dgp2Dcp.add_canon

Dgp2Dcp canonicalizer for the addition atom
Dcp2Cone.log1p_canon

Dcp2Cone canonicalizer for the log 1p atom
InverseData-class

The InverseData class.
ProdEntries-class

The ProdEntries class.
Promote-class

The Promote class.
HStack-class

The HStack class.
SOC-class

The SOC class.
Dgp2Dcp.power_canon

Dgp2Dcp canonicalizer for the power atom
SOCAxis-class

The SOCAxis class.
ExpCone-class

The ExpCone class.
Imag-class

The Imag class.
SumSquares

The SumSquares atom.
Maximize-class

The Maximize class.
Log1p-class

The Log1p class.
HarmonicMean

The HarmonicMean atom.
SymbolicQuadForm-class

The SymbolicQuadForm class.
KLDiv-class

The KLDiv class.
Transpose-class

The Transpose class.
Objective-class

The Objective class.
SigmaMax-class

The SigmaMax class.
Objective-arith

Arithmetic Operations on Objectives
Power-class

The Power class.
Pos

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

The SumEntries class.
MinElemwise-class

The MinElemwise class.
MinEntries-class

The MinEntries class.
GeoMean-class

The GeoMean class.
construct_intermediate_chain,Problem,list-method

Builds a chain that rewrites a problem into an intermediate representation suitable for numeric reductions.
Wrap-class

The Wrap class.
ZeroConstraint-class

The ZeroConstraint class
conv

Discrete Convolution
/,Expression,Expression-method

The DivExpression class.
DiffPos

The DiffPos atom.
TotalVariation

The TotalVariation atom.
SizeMetrics-class

The SizeMetrics class.
MOSEK-class

An interface for the MOSEK solver.
SumLargest-class

The SumLargest class.
EliminatePwl.sum_largest_canon

EliminatePwl canonicalizer for the largest sum atom
Dgp2Dcp.geo_mean_canon

Dgp2Dcp canonicalizer for the geometric mean atom
EliminatePwl.norm1_canon

EliminatePwl canonicalizer for the 1 norm atom
Huber-class

The Huber class.
.LinOp__args_push_back

Perform a push back operation on the args field of LinOp
cone-methods

Second-Order Cone Methods
ReductionSolver-class

The ReductionSolver class.
LambdaMin

The LambdaMin atom.
LambdaSumLargest-class

The LambdaSumLargest class.
OSQP-class

An interface for the OSQP solver.
canonicalize

Canonicalize
Reduction-class

The Reduction class.
cummax_axis

Cumulative Maximum
construct_solving_chain

Build a reduction chain from a problem to an installed solver.
LambdaSumSmallest

The LambdaSumSmallest atom.
UpperTri-class

The UpperTri class.
Pnorm-class

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

The Index class.
[,Expression,index,missing,ANY-method

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

The IneqConstraint class
Entr-class

The Entr class.
.LinOp__get_id

Get the id field of the LinOp Object
.LinOp__set_sparse

Set the flag sparse of the LinOp object
NormNuc-class

The NormNuc class.
QuadForm-class

The QuadForm class.
Log-class

The Log class.
.LinOp__get_size

Get the field size for the LinOp object
.LinOpVector__push_back

Perform a push back operation on the args field of LinOp
.LinOpVector__new

Create a new LinOpVector object.
QpSolver-class

A QP solver interface.
accepts

Reduction Acceptance
Dgp2Dcp.quad_form_canon

Dgp2Dcp canonicalizer for the quadratic form atom
complex-methods

Complex Properties
Dgp2Dcp.quad_over_lin_canon

Dgp2Dcp canonicalizer for the quadratic over linear term atom
Expression-class

The Expression class.
SumSmallest

The SumSmallest atom.
cdiac

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

Absolute Value
.ProblemData__new

Create a new ProblemData object.
get_sp

Get scipy handle
log,Expression-method

Logarithms
diff,Expression-method

Lagged and Iterated Differences
diag,Expression-method

Matrix Diagonal
Leaf-class

The Leaf class.
dual_value-methods

Get and Set Dual Value
dssamp

Direct Standardization: Sample
.ProblemData__set_I

Set the I field in the ProblemData Object
.ProblemData__set_const_to_row

Set the const_to_row map of the ProblemData Object
id

Identification Number
.ProblemData__set_const_vec

Set the const_vec field in the ProblemData Object
group_constraints

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

Harmonic Mean
lambda_max

Maximum Eigenvalue
.LinOp__set_sparse_data

Set the field named sparse_data of the LinOp object
import_solver

Import Solver
.ProblemData__get_V

Get the V field of the ProblemData Object
MOSEK.parse_dual_vars

Parses MOSEK dual variables into corresponding CVXR constraints and dual values
SolvingChain-class

The SolvingChain class.
PSDWrap-class

The PSDWrap class.
ECOS-class

An interface for the ECOS solver
ECOS.dims_to_solver_dict

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

Get Expression Data
.ProblemData__set_V

Set the V field in the ProblemData Object
.ProblemData__set_J

Set the J field in the ProblemData Object
quad_form

Quadratic Form
.LinOp__set_dense_data

Set the field dense_data of the LinOp object
.LinOp__get_dense_data

Get the field dense_data for the LinOp object
.LinOp__new

Create a new LinOp object.
constr_value

Is Constraint Violated?
invert

Return Original Solution
sigma_max

Maximum Singular Value
EliminatePwl.norm_inf_canon

EliminatePwl canonicalizer for the infinite norm atom
extract_mip_idx

Coalesces bool, int indices for variables.
lambda_min

Minimum Eigenvalue
%*%,Expression,Expression-method

The MulExpression class.
SCS-class

An interface for the SCS solver
MOSEK.recover_dual_variables

Recovers MOSEK solutions dual variables
Neg

An alias for -MinElemwise(x, 0)
-,Expression,missing-method

The NegExpression class.
are_args_affine

Are the arguments affine?
log_det

Log-Determinant
sign,Expression-method

Sign of Expression
mixed_norm

Mixed Norm
.LinOp_at_index

Return the LinOp element at index i (0-based)
.ProblemData__get_const_to_row

Get the const_to_row field of the ProblemData Object
EyeMinusInv-class

The EyeMinusInv class.
is_dcp

DCP Compliance
get_dual_values

Gets the values of the dual variables.
leaf-attr

Attributes of an Expression Leaf
eye_minus_inv

Unity Resolvent
QuadOverLin-class

The QuadOverLin class.
Norm

The Norm atom.
Norm1-class

The Norm1 class.
MatrixFrac-class

The MatrixFrac class.
dim_from_args

Atom Dimensions
upper_tri

Upper Triangle of a Matrix
Parameter-class

The Parameter class.
PfEigenvalue-class

The PfEigenvalue class.
curvature-comp

Curvature of Composition
ListORConstr-class

A Class Union of List and Constraint
Reshape-class

The Reshape class.
Rdict-class

The Rdict class.
size

Size of Expression
kl_div

Kullback-Leibler Divergence
%>>%

The PSDConstraint class.
curvature

Curvature of Expression
Logistic-class

The Logistic class.
.p_norm

Internal method for calculating the p-norm
Multiply-class

The Multiply class.
validate_val

Validate Value
*,Expression,Expression-method

Elementwise multiplication operator
sign-methods

Sign Properties
value-methods

Get or Set Value
Trace-class

The Trace class.
OneMinusPos-class

The OneMinusPos class.
cvxr_norm

Matrix Norm (Alternative)
vstack

Vertical Concatenation
kronecker,Expression,ANY-method

Kronecker Product
linearize

Affine Approximation to an Expression
domain

Domain
SCS.dims_to_solver_dict

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

Block Matrix
project-methods

Project Value
SCS.extract_dual_value

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

The UnaryOperator class.
.LinOp__get_sparse_data

Get the field named sparse_data from the LinOp object
expression-parts

Parts of an Expression Leaf
setIdCounter

Set ID Counter
p_norm

P-Norm
one_minus_pos

Difference on Restricted Domain
sqrt,Expression-method

Square Root
psolve

Solve a DCP Problem
QpMatrixStuffing-class

The QpMatrixStuffing class.
NonPosConstraint-class

The NonPosConstraint class
NonlinearConstraint-class

The NonlinearConstraint class.
curvature-methods

Curvature Properties
Real-class

The Real class.
Rdictdefault-class

The Rdictdefault class.
format_constr

Format Constraints
.LinOp__get_slice

Get the slice field of the LinOp Object
.LinOp__set_type

Set the field named type for the LinOp object
.build_matrix_1

Get the sparse flag field for the LinOp object
Qp2SymbolicQp-class

The Qp2SymbolicQp class.
curvature-atom

Curvature of an Atom
grad

Sub/Super-Gradient
graph_implementation

Graph Implementation
hstack

Horizontal Concatenation
.LinOp__get_type

Get the field named type for the LinOp object
.ProblemData__get_const_vec

Get the const_vec field from the ProblemData Object
tv

Total Variation
.ProblemData__get_id_to_col

Get the id_to_col field of the ProblemData Object
problem-parts

Parts of a Problem
is_stuffed_qp_objective

Is the QP objective stuffed?
.ProblemData__set_id_to_col

Set the id_to_col field of the ProblemData Object
residual-methods

Constraint Residual
.build_matrix_0

Get the sparse flag field for the LinOp object
.LinOp__set_size

Set the field size of the LinOp object
VStack-class

The VStack class.
dspop

Direct Standardization: Population
get_problem_data

Get Problem Data
log_log_curvature

Log-Log Curvature of Expression
extract_dual_value

Gets a specified value of a dual variable.
huber

Huber Function
min_entries

Minimum
norm_nuc

Nuclear Norm
complex-atoms

Complex Numbers
Variable-class

The Variable class.
exp,Expression-method

Natural Exponential
SolverStats-class

The SolverStats class.
.LinOp__slice_push_back

Perform a push back operation on the slice field of LinOp
Solution-class

The Solution class.
.LinOp__get_sparse

Get the sparse flag field for the LinOp object
lambda_sum_largest

Sum of Largest Eigenvalues
psd_coeff_offset

Given a problem returns a PSD constraint
unpack_results

Parse output from a solver and updates problem state
mip_capable

Solver Capabilities
scalene

Scalene Function
norm_inf

Infinity-Norm
log_sum_exp

Log-Sum-Exponential
scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
neg

Elementwise Negative
.ProblemData__get_I

Get the I field of the ProblemData Object
.LinOp__size_push_back

Perform a push back operation on the size field of LinOp
quad_over_lin

Quadratic over Linear
cumsum_axis

Cumulative Sum
logistic

Logistic Function
pos

Elementwise Positive
get_np

Get numpy handle
.ProblemData__get_J

Get the J field of the ProblemData Object
.decomp_quad

Compute a Matrix Decomposition.
installed_solvers

List installed solvers
inv_pos

Reciprocal Function
is_stuffed_cone_objective

Is the objective a stuffed cone objective?
get_id

Get ID
geo_mean

Geometric Mean
matrix_prop-methods

Matrix Properties
multiply

Elementwise Multiplication
.LinOp__set_slice

Set the slice field of the LinOp Object
square,Expression-method

Square
is_qp

Is Problem a QP?
is_stuffed_cone_constraint

Is the constraint a stuffed cone constraint?
t.Expression

Matrix Transpose
matrix_frac

Matrix Fraction
matrix_trace

Matrix Trace
name

Variable, Parameter, or Expression Name
entr

Entropy Function
sum_largest

Sum of Largest Values
is_mixed_integer

Is Problem Mixed Integer?
is_dgp

DGP Compliance
log_log_curvature-atom

Log-Log Curvature of an Atom
^,Expression,numeric-method

Elementwise Power
norm1

1-Norm
log_log_curvature-methods

Log-Log Curvature Properties
max_elemwise

Elementwise Maximum
max_entries

Maximum
pf_eigenvalue

Perron-Frobenius Eigenvalue
lambda_sum_smallest

Sum of Smallest Eigenvalues
min_elemwise

Elementwise Minimum
sum_squares

Sum of Squares
sign_from_args

Atom Sign
norm,Expression,character-method

Matrix Norm
mean.Expression

Arithmetic Mean
size-methods

Size Properties
perform

Perform Reduction
prod_entries

Product of Entries
norm2

Euclidean Norm
resetOptions

Reset Options
reshape_expr

Reshape an Expression
validate_args

Validate Arguments
retrieve

Retrieve Solution
to_numeric

Numeric Value of Atom
vec

Vectorization of a Matrix
sum_smallest

Sum of Smallest Values
reduce

Reduce a Problem
tri_to_full

Expands lower triangular to full matrix.
vectorized_lower_tri_to_mat

Turns symmetric 2D array into a lower triangular matrix
sum_entries

Sum of Entries