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-11

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

October 30th, 2022

Functions in CVXR (1.0-11)

CPLEX_QP-class

An interface for the CPLEX solver.
CVXOPT-class

An interface for the CVXOPT solver.
Canonical-class

The Canonical class.
Canonicalization-class

The Canonicalization class.
Complex2Real.canonicalize_expr

Canonicalizes a Complex Expression
Complex2Real.canonicalize_tree

Recursively Canonicalizes a Complex Expression.
CBC_CONIC-class

An interface to the CBC solver
Dcp2Cone-class

Reduce DCP Problem to Conic Form
Dcp2Cone.entr_canon

Dcp2Cone canonicalizer for the entropy atom
AffAtom-class

The AffAtom class.
Dcp2Cone.kl_div_canon

Dcp2Cone canonicalizer for the KL Divergence atom
Complex2Real.hermitian_canon

Complex canonicalizer for the hermitian atom
Abs-class

The Abs class.
+,Expression,missing-method

The AddExpression class.
Complex2Real.imag_canon

Complex canonicalizer for the imaginary atom
Atom-class

The Atom class.
Complex2Real.real_canon

Complex canonicalizer for the real atom
Complex2Real.at_least_2D

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

Complex canonicalizer for the separable atom
Dcp2Cone.lambda_max_canon

Dcp2Cone canonicalizer for the lambda maximization atom
CVXR-package

CVXR: Disciplined Convex Optimization in R
Complex2Real.binary_canon

Complex canonicalizer for the binary atom
Conjugate-class

The Conjugate class.
CPLEX_CONIC-class

An interface for the CPLEX solver
Complex2Real.matrix_frac_canon

Complex canonicalizer for the matrix fraction atom
Dcp2Cone.pnorm_canon

Dcp2Cone canonicalizer for the p norm atom
Complex2Real.nonpos_canon

Complex canonicalizer for the non-positive atom
CallbackParam-class

The CallbackParam class.
Complex2Real.abs_canon

Complex canonicalizer for the absolute value atom
Complex2Real.conj_canon

Complex canonicalizer for the conjugate atom
Dcp2Cone.power_canon

Dcp2Cone canonicalizer for the power atom
Complex2Real.add

Helper function to sum arguments.
Complex2Real.constant_canon

Complex canonicalizer for the constant atom
Complex2Real.soc_canon

Complex canonicalizer for the SOC atom
Dgp2Dcp.zero_constr_canon

Dgp2Dcp canonicalizer for the zero constraint atom
Complex2Real.variable_canon

Complex canonicalizer for the variable atom
Complex2Real.join

Helper function to combine arguments.
Constant-class

The Constant class.
Complex2Real.quad_canon

Complex canonicalizer for the quadratic atom
Complex2Real.lambda_sum_largest_canon

Complex canonicalizer for the largest sum atom
Complex2Real.norm_nuc_canon

Complex canonicalizer for the nuclear norm atom
Complex2Real.quad_over_lin_canon

Complex canonicalizer for the quadratic over linear term atom
DgpCanonMethods-class

DGP canonical methods class.
Dcp2Cone.exp_canon

Dcp2Cone canonicalizer for the exponential atom
ECOS_BB-class

An interface for the ECOS BB solver.
Elementwise-class

The Elementwise class.
Dcp2Cone.geo_mean_canon

Dcp2Cone canonicalizer for the geometric mean atom
Complex2Real.param_canon

Complex canonicalizer for the parameter matrix atom
Complex2Real.zero_canon

Complex canonicalizer for the zero atom
EliminatePwl.norm1_canon

EliminatePwl canonicalizer for the 1 norm atom
EliminatePwl.norm_inf_canon

EliminatePwl canonicalizer for the infinite norm atom
ConeDims-class

Summary of cone dimensions present in constraints.
==,Expression,Expression-method

The EqConstraint class
ConicSolver.get_coeff_offset

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

The EvalParams class.
ConicSolver.get_spacing_matrix

Returns a sparse matrix that spaces out an expression.
ConeMatrixStuffing-class

Construct Matrices for Linear Cone Problems
Dgp2Dcp.norm1_canon

Dgp2Dcp canonicalizer for the 1 norm atom
Conv-class

The Conv class.
Huber-class

The Huber class.
ConicSolver-class

The ConicSolver class.
Imag-class

The Imag class.
CumMax-class

The CumMax class.
Dcp2Cone.log_sum_exp_canon

Dcp2Cone canonicalizer for the log sum of the exp atom
AxisAtom-class

The AxisAtom class.
CumSum-class

The CumSum class.
CvxAttr2Constr-class

The CvxAttr2Constr class.
Dcp2Cone.logistic_canon

Dcp2Cone canonicalizer for the logistic function atom
Dcp2Cone.lambda_sum_largest_canon

Dcp2Cone canonicalizer for the largest lambda sum atom
LambdaMin

The LambdaMin atom.
Dgp2Dcp.norm_inf_canon

Dgp2Dcp canonicalizer for the infinite norm atom
BinaryOperator-class

The BinaryOperator class.
Dcp2Cone.log_canon

Dcp2Cone canonicalizer for the log atom
Chain-class

The Chain class.
Dgp2Dcp.div_canon

Dgp2Dcp canonicalizer for the division atom
Dcp2Cone.log_det_canon

Dcp2Cone canonicalizer for the log determinant atom
Dcp2Cone.log1p_canon

Dcp2Cone canonicalizer for the log 1p atom
Complex2Real-class

Lifts complex numbers to a real representation.
Dgp2Dcp.add_canon

Dgp2Dcp canonicalizer for the addition atom
Dgp2Dcp.exp_canon

Dgp2Dcp canonicalizer for the exp atom
Dgp2Dcp.constant_canon

Dgp2Dcp canonicalizer for the constant atom
Complex2Real.pnorm_canon

Complex canonicalizer for the p norm atom
Complex2Real.psd_canon

Complex canonicalizer for the positive semidefinite atom
LambdaSumLargest-class

The LambdaSumLargest class.
Dcp2Cone.quad_form_canon

Dcp2Cone canonicalizer for the quadratic form atom
Dgp2Dcp.log_canon

Dgp2Dcp canonicalizer for the log atom
MOSEK.recover_dual_variables

Recovers MOSEK solutions dual variables
MatrixFrac-class

The MatrixFrac class.
Dgp2Dcp.mulexpression_canon

Dgp2Dcp canonicalizer for the multiplication expression atom
Dgp2Dcp.quad_form_canon

Dgp2Dcp canonicalizer for the quadratic form atom
Dgp2Dcp.nonpos_constr_canon

Dgp2Dcp canonicalizer for the non-positive constraint atom
Dgp2Dcp.mul_canon

Dgp2Dcp canonicalizer for the multiplication atom
Dgp2Dcp.quad_over_lin_canon

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

Dgp2Dcp canonicalizer for the power atom
DiffPos

The DiffPos atom.
Dgp2Dcp.prod_canon

Dgp2Dcp canonicalizer for the product atom
ConstantSolver-class

The ConstantSolver class.
Dgp2Dcp.pf_eigenvalue_canon

Dgp2Dcp canonicalizer for the spectral radius atom
Dgp2Dcp.pnorm_canon

Dgp2Dcp canonicalizer for the p norm atom
ECOS-class

An interface for the ECOS solver
Neg

An alias for -MinElemwise(x, 0)
Dcp2Cone.quad_over_lin_canon

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

The Constraint class.
ECOS.dims_to_solver_dict

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

The DiagVec class.
-,Expression,missing-method

The NegExpression class.
EliminatePwl.max_elemwise_canon

EliminatePwl canonicalizer for the elementwise maximum atom
Dgp2Dcp.one_minus_pos_canon

Dgp2Dcp canonicalizer for the 1-x atom
Dgp2Dcp.parameter_canon

Dgp2Dcp canonicalizer for the parameter atom
Diff

Takes the k-th order differences
NonPosConstraint-class

The NonPosConstraint class
EliminatePwl.cummax_canon

EliminatePwl canonicalizer for the cumulative max atom
EliminatePwl.max_entries_canon

EliminatePwl canonicalizer for the max entries atom
/,Expression,Expression-method

The DivExpression class.
EliminatePwl.cumsum_canon

EliminatePwl canonicalizer for the cumulative sum atom
EliminatePwl.sum_largest_canon

EliminatePwl canonicalizer for the largest sum atom
Dcp2Cone.huber_canon

Dcp2Cone canonicalizer for the huber atom
Entr-class

The Entr class.
HStack-class

The HStack class.
NonlinearConstraint-class

The NonlinearConstraint class.
Dcp2Cone.indicator_canon

Dcp2Cone canonicalizer for the indicator atom
Dcp2Cone.matrix_frac_canon

Dcp2Cone canonicalizer for the matrix fraction atom
FlipObjective-class

The FlipObjective class.
Kron-class

The Kron class.
QuadOverLin-class

The QuadOverLin class.
Rdict-class

The Rdict class.
Dcp2Cone.normNuc_canon

Dcp2Cone canonicalizer for the nuclear norm atom
GLPK-class

An interface for the GLPK solver.
GLPK_MI-class

An interface for the GLPK MI solver.
Dgp2Dcp.sum_canon

Dgp2Dcp canonicalizer for the sum atom
Dgp2Dcp.trace_canon

Dgp2Dcp canonicalizer for the trace atom
GUROBI_CONIC-class

An interface for the GUROBI conic solver.
SCS.dims_to_solver_dict

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

The HarmonicMean atom.
LambdaMax-class

The LambdaMax class.
ListORConstr-class

A Class Union of List and Constraint
Log-class

The Log class.
MatrixStuffing-class

The MatrixStuffing class.
MaxElemwise-class

The MaxElemwise class.
SCS.extract_dual_value

Extracts the dual value for constraint starting at offset.
Dcp2Cone.sigma_max_canon

Dcp2Cone canonicalizer for the sigma max atom
SymbolicQuadForm-class

The SymbolicQuadForm class.
InverseData-class

The InverseData class.
KLDiv-class

The KLDiv class.
%*%,Expression,Expression-method

The MulExpression class.
MaxEntries-class

The MaxEntries class.
TotalVariation

The TotalVariation atom.
Multiply-class

The Multiply class.
LogSumExp-class

The LogSumExp class.
Dgp2Dcp-class

Reduce DGP problems to DCP problems.
Norm

The Norm atom.
Dgp2Dcp.eye_minus_inv_canon

Dgp2Dcp canonicalizer for the (I - X)^-1 atom
Dgp2Dcp.geo_mean_canon

Dgp2Dcp canonicalizer for the geometric mean atom
Logistic-class

The Logistic class.
Maximize-class

The Maximize class.
Norm1-class

The Norm1 class.
Diag

Turns an expression into a DiagVec object
PfEigenvalue-class

The PfEigenvalue class.
MinElemwise-class

The MinElemwise class.
DiagMat-class

The DiagMat class.
EliminatePwl-class

The EliminatePwl class.
EliminatePwl.min_elemwise_canon

EliminatePwl canonicalizer for the elementwise minimum atom
UnaryOperator-class

The UnaryOperator class.
UpperTri-class

The UpperTri class.
EliminatePwl.abs_canon

EliminatePwl canonicalizer for the absolute atom
Pos

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

The Pnorm class.
MinEntries-class

The MinEntries class.
Norm2

The Norm2 atom.
construct_intermediate_chain,Problem,list-method

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

The Rdictdefault class.
EliminatePwl.min_entries_canon

EliminatePwl canonicalizer for the minimum entries atom
NormInf-class

The NormInf class.
Expression-class

The Expression class.
construct_solving_chain

Build a reduction chain from a problem to an installed solver.
Exp-class

The Exp class.
Real-class

The Real class.
diag,Expression-method

Matrix Diagonal
Reshape-class

The Reshape class.
EyeMinusInv-class

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

The Index class.
OneMinusPos-class

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

The IneqConstraint class
Power-class

The Power class.
diff,Expression-method

Lagged and Iterated Differences
ExpCone-class

The ExpCone class.
GUROBI_QP-class

An interface for the GUROBI_QP solver.
GeoMean-class

The GeoMean class.
SCS-class

An interface for the SCS solver
SolvingChain-class

The SolvingChain class.
LambdaSumSmallest

The LambdaSumSmallest atom.
.LinOp__set_type

Set the field named type for the LinOp object
%>>%

The PSDConstraint class.
Leaf-class

The Leaf class.
SOC-class

The SOC class.
SOCAxis-class

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

The SpecialIndex class.
.LinOp__size_push_back

Perform a push back operation on the size field of LinOp
VStack-class

The VStack class.
.ProblemData__get_const_vec

Get the const_vec field from the ProblemData Object
Log1p-class

The Log1p class.
MOSEK-class

An interface for the MOSEK solver.
.ProblemData__get_id_to_col

Get the id_to_col field of the ProblemData Object
.ProblemData__set_const_to_row

Set the const_to_row map of the ProblemData Object
MOSEK.parse_dual_vars

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

The Minimize class.
Variable-class

The Variable class.
LogDet-class

The LogDet class.
Objective-arith

Arithmetic Operations on Objectives
ProdEntries-class

The ProdEntries class.
.ProblemData__set_const_vec

Set the const_vec field in the ProblemData Object
cone-methods

Second-Order Cone Methods
extract_mip_idx

Coalesces bool, int indices for variables.
eye_minus_inv

Unity Resolvent
Wrap-class

The Wrap class.
ZeroConstraint-class

The ZeroConstraint class
psd_coeff_offset

Given a problem returns a PSD constrain
Objective-class

The Objective class.
Promote-class

The Promote class.
constr_value

Is Constraint Violated?
is_qp

Is Problem a QP?
complex-atoms

Complex Numbers
PSDWrap-class

The PSDWrap class.
SigmaMax-class

The SigmaMax class.
complex-methods

Complex Properties
.LinOp__get_slice

Get the slice field of the LinOp Object
.LinOp__get_sparse

Get the sparse flag field for the LinOp object
.LinOp__set_sparse

Set the flag sparse of the LinOp object
MixedNorm

The MixedNorm atom.
SizeMetrics-class

The SizeMetrics class.
.LinOp__set_sparse_data

Set the field named sparse_data of the LinOp object
SumEntries-class

The SumEntries class.
.ProblemData__set_J

Set the J field in the ProblemData Object
SumLargest-class

The SumLargest class.
NormNuc-class

The NormNuc class.
.ProblemData__set_V

Set the V field in the ProblemData Object
curvature-comp

Curvature of Composition
curvature

Curvature of Expression
cvxr_norm

Matrix Norm (Alternative)
format_constr

Format Constraints
geo_mean

Geometric Mean
dim_from_args

Atom Dimensions
is_stuffed_cone_constraint

Is the constraint a stuffed cone constraint?
OSQP-class

An interface for the OSQP solver.
group_constraints

Organize the constraints into a dictionary keyed by constraint names.
Problem-arith

Arithmetic Operations on Problems
curvature-methods

Curvature Properties
Problem-class

The Problem class.
QpSolver-class

A QP solver interface.
.LinOp__args_push_back

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

Atom Sign
harmonic_mean

Harmonic Mean
log_log_curvature

Log-Log Curvature of Expression
one_minus_pos

Difference on Restricted Domain
QuadForm-class

The QuadForm class.
id

Identification Number
domain

Domain
.LinOp__get_dense_data

Get the field dense_data for the LinOp object
.ProblemData__get_I

Get the I field of the ProblemData Object
vec

Vectorization of a Matrix
Parameter-class

The Parameter class.
Solution-class

The Solution class.
log_sum_exp

Log-Sum-Exponential
.ProblemData__get_J

Get the J field of the ProblemData Object
.LinOp__new

Create a new LinOp object.
Qp2SymbolicQp-class

The Qp2SymbolicQp class.
.ProblemData__set_id_to_col

Set the id_to_col field of the ProblemData Object
.LinOp__set_dense_data

Set the field dense_data of the LinOp object
QpMatrixStuffing-class

The QpMatrixStuffing class.
get_problem_data

Get Problem Data
import_solver

Import Solver
scalene

Scalene Function
Reduction-class

The Reduction class.
.build_matrix_0

Get the sparse flag field for the LinOp object
get_id

Get ID
norm_inf

Infinity-Norm
.ProblemData__get_V

Get the V field of the ProblemData Object
get_np

Get numpy handle
log_log_curvature-atom

Log-Log Curvature of an Atom
ReductionSolver-class

The ReductionSolver class.
SumSmallest

The SumSmallest atom.
SolverStats-class

The SolverStats class.
is_dgp

DGP Compliance
SumSquares

The SumSquares atom.
Trace-class

The Trace class.
Transpose-class

The Transpose class.
canonicalize

Canonicalize
cdiac

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

Absolute Value
scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
.ProblemData__get_const_to_row

Get the const_to_row field of the ProblemData Object
accepts

Reduction Acceptance
is_mixed_integer

Is Problem Mixed Integer?
lambda_sum_largest

Sum of Largest Eigenvalues
log_log_curvature-methods

Log-Log Curvature Properties
sum_smallest

Sum of Smallest Values
are_args_affine

Are the arguments affine?
entr

Entropy Function
is_stuffed_cone_objective

Is the objective a stuffed cone objective?
exp,Expression-method

Natural Exponential
matrix_prop-methods

Matrix Properties
lambda_sum_smallest

Sum of Smallest Eigenvalues
min_entries

Minimum
norm_nuc

Nuclear Norm
bmat

Block Matrix
tv

Total Variation
project-methods

Project Value
size-methods

Size Properties
unpack_results

Parse output from a solver and updates problem state
linearize

Affine Approximation to an Expression
mip_capable

Solver Capabilities
get_sp

Get scipy handle
sqrt,Expression-method

Square Root
matrix_trace

Matrix Trace
p_norm

P-Norm
is_stuffed_qp_objective

Is the QP objective stuffed?
huber

Huber Function
hstack

Horizontal Concatenation
vectorized_lower_tri_to_mat

Turns symmetric 2D array into a lower triangular matrix
size

Size of Expression
leaf-attr

Attributes of an Expression Leaf
mixed_norm

Mixed Norm
^,Expression,numeric-method

Elementwise Power
*,Expression,Expression-method

Elementwise multiplication operator
resetOptions

Reset Options
sum_largest

Sum of Largest Values
reshape_expr

Reshape an Expression
value-methods

Get or Set Value
name

Variable, Parameter, or Expression Name
multiply

Elementwise Multiplication
perform

Perform Reduction
conv

Discrete Convolution
dssamp

Direct Standardization: Sample
validate_val

Validate Value
.LinOp__get_id

Get the id field of the LinOp Object
.ProblemData__new

Create a new ProblemData object.
.LinOp__get_type

Get the field named type for the LinOp object
cummax_axis

Cumulative Maximum
cumsum_axis

Cumulative Sum
pf_eigenvalue

Perron-Frobenius Eigenvalue
.LinOp__get_size

Get the field size for the LinOp object
.LinOp__get_sparse_data

Get the field named sparse_data from the LinOp object
quad_over_lin

Quadratic over Linear
residual-methods

Constraint Residual
installed_solvers

List installed solvers
.ProblemData__set_I

Set the I field in the ProblemData Object
min_elemwise

Elementwise Minimum
.build_matrix_1

Get the sparse flag field for the LinOp object
reduce

Reduce a Problem
.decomp_quad

Compute a Matrix Decomposition.
.LinOpVector__push_back

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

Create a new LinOpVector object.
curvature-atom

Curvature of an Atom
.LinOp__set_slice

Set the slice field of the LinOp Object
.LinOp__set_size

Set the field size of the LinOp object
.LinOp__slice_push_back

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

Elementwise Positive
setIdCounter

Set ID Counter
sigma_max

Maximum Singular Value
vstack

Vertical Concatenation
kronecker,Expression,ANY-method

Kronecker Product
dual_value-methods

Get and Set Dual Value
grad

Sub/Super-Gradient
graph_implementation

Graph Implementation
inv_pos

Reciprocal Function
t.Expression

Matrix Transpose
prod_entries

Product of Entries
.p_norm

Internal method for calculating the p-norm
.LinOp_at_index

Return the LinOp element at index i (0-based)
expression-parts

Parts of an Expression Leaf
dspop

Direct Standardization: Population
neg

Elementwise Negative
sign-methods

Sign Properties
kl_div

Kullback-Leibler Divergence
sign,Expression-method

Sign of Expression
extract_dual_value

Gets a specified value of a dual variable.
tri_to_full

Expands lower triangular to full matrix.
get_data

Get Expression Data
problem-parts

Parts of a Problem
matrix_frac

Matrix Fraction
mean.Expression

Arithmetic Mean
logistic

Logistic Function
norm,Expression,character-method

Matrix Norm
sum_squares

Sum of Squares
is_dcp

DCP Compliance
retrieve

Retrieve Solution
get_dual_values

Gets the values of the dual variables.
invert

Return Original Solution
lambda_min

Minimum Eigenvalue
log_det

Log-Determinant
norm1

1-Norm
lambda_max

Maximum Eigenvalue
log,Expression-method

Logarithms
max_elemwise

Elementwise Maximum
to_numeric

Numeric Value of Atom
upper_tri

Upper Triangle of a Matrix
max_entries

Maximum
norm2

Euclidean Norm
psolve

Solve a DCP Problem
sum_entries

Sum of Entries
quad_form

Quadratic Form
square,Expression-method

Square
validate_args

Validate Arguments