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

37,475

Version

1.0-9

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

January 19th, 2021

Functions in CVXR (1.0-9)

BinaryOperator-class

The BinaryOperator class.
Atom-class

The Atom class.
CBC_CONIC-class

An interface to the CBC solver
+,Expression,missing-method

The AddExpression class.
AffAtom-class

The AffAtom class.
CPLEX_QP-class

An interface for the CPLEX solver.
AxisAtom-class

The AxisAtom class.
Abs-class

The Abs class.
CVXOPT-class

An interface for the CVXOPT solver.
CPLEX_CONIC-class

An interface for the CPLEX solver
Complex2Real.conj_canon

Complex canonicalizer for the conjugate atom
Complex2Real.constant_canon

Complex canonicalizer for the constant atom
Complex2Real-class

Lifts complex numbers to a real representation.
Complex2Real.imag_canon

Complex canonicalizer for the imaginary atom
Chain-class

The Chain class.
Complex2Real.hermitian_canon

Complex canonicalizer for the hermitian atom
CVXR-package

CVXR: Disciplined Convex Optimization in R
Complex2Real.norm_nuc_canon

Complex canonicalizer for the nuclear norm atom
CallbackParam-class

The CallbackParam class.
Complex2Real.param_canon

Complex canonicalizer for the parameter matrix atom
Complex2Real.quad_canon

Complex canonicalizer for the quadratic atom
Complex2Real.quad_over_lin_canon

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

Upcast 0D and 1D to 2D.
Canonical-class

The Canonical class.
Complex2Real.zero_canon

Complex canonicalizer for the zero atom
Complex2Real.canonicalize_expr

Canonicalizes a Complex Expression
Complex2Real.soc_canon

Complex canonicalizer for the SOC atom
Complex2Real.variable_canon

Complex canonicalizer for the variable atom
Canonicalization-class

The Canonicalization class.
Complex2Real.canonicalize_tree

Recursively Canonicalizes a Complex Expression.
Complex2Real.real_canon

Complex canonicalizer for the real atom
ConicSolver.get_coeff_offset

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

Summary of cone dimensions present in constraints.
Dcp2Cone-class

Reduce DCP Problem to Conic Form
Dcp2Cone.exp_canon

Dcp2Cone canonicalizer for the exponential atom
Complex2Real.binary_canon

Complex canonicalizer for the binary atom
ConicSolver.get_spacing_matrix

Returns a sparse matrix that spaces out an expression.
Dcp2Cone.log_sum_exp_canon

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

The Conjugate class.
Complex2Real.separable_canon

Complex canonicalizer for the separable atom
Constant-class

The Constant class.
Complex2Real.abs_canon

Complex canonicalizer for the absolute value atom
Complex2Real.add

Helper function to sum arguments.
Complex2Real.lambda_sum_largest_canon

Complex canonicalizer for the largest sum atom
Complex2Real.join

Helper function to combine arguments.
Dcp2Cone.logistic_canon

Dcp2Cone canonicalizer for the logistic function atom
Dcp2Cone.quad_form_canon

Dcp2Cone canonicalizer for the quadratic form atom
Dcp2Cone.quad_over_lin_canon

Dcp2Cone canonicalizer for the quadratic over linear term atom
Dgp2Dcp.add_canon

Dgp2Dcp canonicalizer for the addition atom
Dcp2Cone.geo_mean_canon

Dcp2Cone canonicalizer for the geometric mean atom
Complex2Real.matrix_frac_canon

Complex canonicalizer for the matrix fraction atom
Complex2Real.nonpos_canon

Complex canonicalizer for the non-positive atom
Complex2Real.psd_canon

Complex canonicalizer for the positive semidefinite atom
Complex2Real.pnorm_canon

Complex canonicalizer for the p norm atom
ConeMatrixStuffing-class

Construct Matrices for Linear Cone Problems
Dcp2Cone.huber_canon

Dcp2Cone canonicalizer for the huber atom
ConicSolver-class

The ConicSolver class.
Dcp2Cone.entr_canon

Dcp2Cone canonicalizer for the entropy atom
ConstantSolver-class

The ConstantSolver class.
Dgp2Dcp.one_minus_pos_canon

Dgp2Dcp canonicalizer for the 1-x atom
Dgp2Dcp.parameter_canon

Dgp2Dcp canonicalizer for the parameter atom
Constraint-class

The Constraint class.
CvxAttr2Constr-class

The CvxAttr2Constr class.
CumSum-class

The CumSum class.
Dcp2Cone.lambda_sum_largest_canon

Dcp2Cone canonicalizer for the largest lambda sum atom
Dcp2Cone.log1p_canon

Dcp2Cone canonicalizer for the log 1p atom
Dgp2Dcp.div_canon

Dgp2Dcp canonicalizer for the division atom
Dgp2Dcp.exp_canon

Dgp2Dcp canonicalizer for the exp atom
Dcp2Cone.indicator_canon

Dcp2Cone canonicalizer for the indicator atom
Dcp2Cone.matrix_frac_canon

Dcp2Cone canonicalizer for the matrix fraction atom
Dgp2Dcp.log_canon

Dgp2Dcp canonicalizer for the log atom
CumMax-class

The CumMax class.
Conv-class

The Conv class.
Dgp2Dcp.mul_canon

Dgp2Dcp canonicalizer for the multiplication atom
Dcp2Cone.normNuc_canon

Dcp2Cone canonicalizer for the nuclear norm atom
Dcp2Cone.pnorm_canon

Dcp2Cone canonicalizer for the p norm atom
Dgp2Dcp.power_canon

Dgp2Dcp canonicalizer for the power atom
Dcp2Cone.power_canon

Dcp2Cone canonicalizer for the power atom
Dgp2Dcp.prod_canon

Dgp2Dcp canonicalizer for the product atom
EyeMinusInv-class

The EyeMinusInv class.
EliminatePwl.abs_canon

EliminatePwl canonicalizer for the absolute atom
EliminatePwl-class

The EliminatePwl class.
Expression-class

The Expression class.
Dgp2Dcp.quad_form_canon

Dgp2Dcp canonicalizer for the quadratic form atom
Dgp2Dcp.quad_over_lin_canon

Dgp2Dcp canonicalizer for the quadratic over linear term atom
EliminatePwl.min_elemwise_canon

EliminatePwl canonicalizer for the elementwise minimum atom
DiffPos

The DiffPos atom.
/,Expression,Expression-method

The DivExpression class.
EliminatePwl.min_entries_canon

EliminatePwl canonicalizer for the minimum entries atom
Dgp2Dcp.norm1_canon

Dgp2Dcp canonicalizer for the 1 norm atom
Dgp2Dcp.constant_canon

Dgp2Dcp canonicalizer for the constant atom
Dcp2Cone.log_canon

Dcp2Cone canonicalizer for the log atom
Dcp2Cone.log_det_canon

Dcp2Cone canonicalizer for the log determinant atom
Dgp2Dcp.eye_minus_inv_canon

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

The Exp class.
Kron-class

The Kron class.
HStack-class

The HStack class.
ExpCone-class

The ExpCone class.
HarmonicMean

The HarmonicMean atom.
EliminatePwl.cummax_canon

EliminatePwl canonicalizer for the cumulative max atom
ECOS_BB-class

An interface for the ECOS BB solver.
Elementwise-class

The Elementwise class.
Dcp2Cone.kl_div_canon

Dcp2Cone canonicalizer for the KL Divergence atom
MOSEK-class

An interface for the MOSEK solver.
MOSEK.parse_dual_vars

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

The LambdaMax class.
OSQP-class

An interface for the OSQP solver.
PSDWrap-class

The PSDWrap class.
NormNuc-class

The NormNuc class.
Dcp2Cone.sigma_max_canon

Dcp2Cone canonicalizer for the sigma max atom
Dcp2Cone.lambda_max_canon

Dcp2Cone canonicalizer for the lambda maximization atom
LambdaMin

The LambdaMin atom.
Entr-class

The Entr class.
EliminatePwl.cumsum_canon

EliminatePwl canonicalizer for the cumulative sum atom
EliminatePwl.sum_largest_canon

EliminatePwl canonicalizer for the largest sum atom
LambdaSumLargest-class

The LambdaSumLargest class.
LogSumExp-class

The LogSumExp class.
Dgp2Dcp-class

Reduce DGP problems to DCP problems.
Logistic-class

The Logistic class.
GUROBI_QP-class

An interface for the GUROBI_QP solver.
Dgp2Dcp.nonpos_constr_canon

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

Dgp2Dcp canonicalizer for the multiplication expression atom
Norm

The Norm atom.
MaxEntries-class

The MaxEntries class.
Maximize-class

The Maximize class.
Norm1-class

The Norm1 class.
UpperTri-class

The UpperTri class.
Qp2SymbolicQp-class

The Qp2SymbolicQp class.
SolvingChain-class

The SolvingChain class.
QpMatrixStuffing-class

The QpMatrixStuffing class.
UnaryOperator-class

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

The SpecialIndex class.
Dgp2Dcp.zero_constr_canon

Dgp2Dcp canonicalizer for the zero constraint atom
Dgp2Dcp.norm_inf_canon

Dgp2Dcp canonicalizer for the infinite norm atom
Dgp2Dcp.pf_eigenvalue_canon

Dgp2Dcp canonicalizer for the spectral radius atom
Parameter-class

The Parameter class.
InverseData-class

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

The MulExpression class.
KLDiv-class

The KLDiv class.
GeoMean-class

The GeoMean class.
SCS.dims_to_solver_dict

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

Extracts the dual value for constraint starting at offset.
SumSquares

The SumSquares atom.
SumSmallest

The SumSmallest atom.
Rdict-class

The Rdict class.
QuadOverLin-class

The QuadOverLin class.
Dgp2Dcp.geo_mean_canon

Dgp2Dcp canonicalizer for the geometric mean atom
Dgp2Dcp.sum_canon

Dgp2Dcp canonicalizer for the sum atom
EliminatePwl.norm1_canon

EliminatePwl canonicalizer for the 1 norm atom
GLPK_MI-class

An interface for the GLPK MI solver.
Diag

Turns an expression into a DiagVec object
DiagMat-class

The DiagMat class.
EliminatePwl.norm_inf_canon

EliminatePwl canonicalizer for the infinite norm atom
Dgp2Dcp.pnorm_canon

Dgp2Dcp canonicalizer for the p norm atom
construct_intermediate_chain,Problem,list-method

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

An interface for the GUROBI conic solver.
Log1p-class

The Log1p class.
DgpCanonMethods-class

DGP canonical methods class.
LogDet-class

The LogDet class.
.LinOp__get_id

Get the id field of the LinOp Object
curvature

Curvature of Expression
.LinOp__get_size

Get the field size for the LinOp object
construct_solving_chain

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

Matrix Norm (Alternative)
bmat

Block Matrix
diff,Expression-method

Lagged and Iterated Differences
are_args_affine

Are the arguments affine?
diag,Expression-method

Matrix Diagonal
.LinOp__args_push_back

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

An alias for -MinElemwise(x, 0)
Norm2

The Norm2 atom.
-,Expression,missing-method

The NegExpression class.
Diff

Takes the k-th order differences
EvalParams-class

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

The Index class.
DiagVec-class

The DiagVec class.
==,Expression,Expression-method

The EqConstraint class
.LinOp__new

Create a new LinOp object.
.LinOp__get_dense_data

Get the field dense_data for the LinOp object
NormInf-class

The NormInf class.
PfEigenvalue-class

The PfEigenvalue class.
Pnorm-class

The Pnorm class.
ECOS-class

An interface for the ECOS solver
EliminatePwl.max_entries_canon

EliminatePwl canonicalizer for the max entries atom
EliminatePwl.max_elemwise_canon

EliminatePwl canonicalizer for the elementwise maximum atom
Dgp2Dcp.trace_canon

Dgp2Dcp canonicalizer for the trace atom
ECOS.dims_to_solver_dict

Utility method for formatting a ConeDims instance into a dictionary that can be supplied to ECOS.
<=,Expression,Expression-method

The IneqConstraint class
FlipObjective-class

The FlipObjective class.
.LinOp__set_sparse

Set the flag sparse of the LinOp object
.LinOp__set_dense_data

Set the field dense_data of the LinOp object
Reshape-class

The Reshape class.
Trace-class

The Trace class.
SCS-class

An interface for the SCS solver
Transpose-class

The Transpose class.
complex-atoms

Complex Numbers
conv

Discrete Convolution
complex-methods

Complex Properties
.LinOp__set_sparse_data

Set the field named sparse_data of the LinOp object
.ProblemData__get_const_vec

Get the const_vec field from the ProblemData Object
ListORConstr-class

A Class Union of List and Constraint
Multiply-class

The Multiply class.
format_constr

Format Constraints
.LinOp__slice_push_back

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

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

Set the const_to_row map of the ProblemData Object
Huber-class

The Huber class.
GLPK-class

An interface for the GLPK solver.
.ProblemData__set_const_vec

Set the const_vec field in the ProblemData Object
geo_mean

Geometric Mean
.LinOp_at_index

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

Cumulative Maximum
Imag-class

The Imag class.
MatrixStuffing-class

The MatrixStuffing class.
QpSolver-class

A QP solver interface.
Problem-arith

Arithmetic Operations on Problems
MinElemwise-class

The MinElemwise class.
QuadForm-class

The QuadForm class.
MaxElemwise-class

The MaxElemwise class.
Problem-class

The Problem class.
Log-class

The Log class.
MinEntries-class

The MinEntries class.
Reduction-class

The Reduction class.
Objective-class

The Objective class.
Objective-arith

Arithmetic Operations on Objectives
Pos

An alias for MaxElemwise(x, 0)
harmonic_mean

Harmonic Mean
import_solver

Import Solver
id

Identification Number
is_qp

Is Problem a QP?
ReductionSolver-class

The ReductionSolver class.
Power-class

The Power class.
is_stuffed_cone_constraint

Is the constraint a stuffed cone constraint?
SolverStats-class

The SolverStats class.
cone-methods

Second-Order Cone Methods
Wrap-class

The Wrap class.
ZeroConstraint-class

The ZeroConstraint class
Solution-class

The Solution class.
.LinOpVector__push_back

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

Create a new LinOpVector object.
.ProblemData__get_id_to_col

Get the id_to_col field of the ProblemData Object
dssamp

Direct Standardization: Sample
Rdictdefault-class

The Rdictdefault class.
Real-class

The Real class.
log_log_curvature-methods

Log-Log Curvature Properties
log_log_curvature-atom

Log-Log Curvature of an Atom
dual_value-methods

Get and Set Dual Value
grad

Sub/Super-Gradient
min_elemwise

Elementwise Minimum
mean.Expression

Arithmetic Mean
one_minus_pos

Difference on Restricted Domain
LambdaSumSmallest

The LambdaSumSmallest atom.
constr_value

Is Constraint Violated?
is_dgp

DGP Compliance
kl_div

Kullback-Leibler Divergence
graph_implementation

Graph Implementation
is_mixed_integer

Is Problem Mixed Integer?
.LinOp__get_sparse_data

Get the field named sparse_data from the LinOp object
Leaf-class

The Leaf class.
MOSEK.recover_dual_variables

Recovers MOSEK solutions dual variables
MatrixFrac-class

The MatrixFrac class.
.ProblemData__get_I

Get the I field of the ProblemData Object
.ProblemData__get_J

Get the J field of the ProblemData Object
.LinOp__get_type

Get the field named type for the LinOp object
psolve

Solve a DCP Problem
p_norm

P-Norm
quad_form

Quadratic Form
scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
SizeMetrics-class

The SizeMetrics class.
SigmaMax-class

The SigmaMax class.
SymbolicQuadForm-class

The SymbolicQuadForm class.
.ProblemData__set_J

Set the J field in the ProblemData Object
.ProblemData__get_const_to_row

Get the const_to_row field of the ProblemData Object
dim_from_args

Atom Dimensions
.ProblemData__get_V

Get the V field of the ProblemData Object
domain

Domain
TotalVariation

The TotalVariation atom.
scalene

Scalene Function
abs,Expression-method

Absolute Value
canonicalize

Canonicalize
curvature-atom

Curvature of an Atom
accepts

Reduction Acceptance
cdiac

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

Cumulative Sum
.LinOp__set_type

Set the field named type for the LinOp object
.LinOp__size_push_back

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

Atom Sign
.ProblemData__set_V

Set the V field in the ProblemData Object
extract_mip_idx

Coalesces bool, int indices for variables.
Minimize-class

The Minimize class.
ProdEntries-class

The ProdEntries class.
NonPosConstraint-class

The NonPosConstraint class
OneMinusPos-class

The OneMinusPos class.
NonlinearConstraint-class

The NonlinearConstraint class.
MixedNorm

The MixedNorm atom.
%>>%

The PSDConstraint class.
.build_matrix_1

Get the sparse flag field for the LinOp object
kronecker,Expression,ANY-method

Kronecker Product
size-methods

Size Properties
.p_norm

Internal method for calculating the p-norm
dspop

Direct Standardization: Population
get_np

Get numpy handle
inv_pos

Reciprocal Function
eye_minus_inv

Unity Resolvent
get_id

Get ID
installed_solvers

List installed solvers
leaf-attr

Attributes of an Expression Leaf
log_det

Log-Determinant
log,Expression-method

Logarithms
extract_dual_value

Gets a specified value of a dual variable.
huber

Huber Function
hstack

Horizontal Concatenation
lambda_max

Maximum Eigenvalue
expression-parts

Parts of an Expression Leaf
entr

Entropy Function
.decomp_quad

Compute a Matrix Decomposition.
exp,Expression-method

Natural Exponential
unpack_results

Parse output from a solver and updates problem state
tv

Total Variation
mixed_norm

Mixed Norm
linearize

Affine Approximation to an Expression
lambda_min

Minimum Eigenvalue
mip_capable

Solver Capabilities
^,Expression,numeric-method

Elementwise Power
min_entries

Minimum
pos

Elementwise Positive
size

Size of Expression
sqrt,Expression-method

Square Root
log_log_curvature

Log-Log Curvature of Expression
SOC-class

The SOC class.
VStack-class

The VStack class.
SumEntries-class

The SumEntries class.
SOCAxis-class

The SOCAxis class.
Promote-class

The Promote class.
SumLargest-class

The SumLargest class.
*,Expression,Expression-method

Elementwise multiplication operator
Variable-class

The Variable class.
get_problem_data

Get Problem Data
log_sum_exp

Log-Sum-Exponential
curvature-methods

Curvature Properties
curvature-comp

Curvature of Composition
.LinOp__get_slice

Get the slice field of the LinOp Object
multiply

Elementwise Multiplication
perform

Perform Reduction
pf_eigenvalue

Perron-Frobenius Eigenvalue
name

Variable, Parameter, or Expression Name
get_sp

Get scipy handle
invert

Return Original Solution
quad_over_lin

Quadratic over Linear
is_dcp

DCP Compliance
max_elemwise

Elementwise Maximum
.LinOp__get_sparse

Get the sparse flag field for the LinOp object
lambda_sum_smallest

Sum of Smallest Eigenvalues
norm,Expression,character-method

Matrix Norm
neg

Elementwise Negative
lambda_sum_largest

Sum of Largest Eigenvalues
problem-parts

Parts of a Problem
setIdCounter

Set ID Counter
prod_entries

Product of Entries
square,Expression-method

Square
reduce

Reduce a Problem
sum_entries

Sum of Entries
t.Expression

Matrix Transpose
sign-methods

Sign Properties
sigma_max

Maximum Singular Value
sign,Expression-method

Sign of Expression
validate_val

Validate Value
value-methods

Get or Set Value
.LinOp__set_size

Set the field size of the LinOp object
.LinOp__set_slice

Set the slice field of the LinOp Object
.ProblemData__new

Create a new ProblemData object.
.ProblemData__set_I

Set the I field in the ProblemData Object
.ProblemData__set_id_to_col

Set the id_to_col field of the ProblemData Object
tri_to_full

Expands lower triangular to full matrix.
norm2

Euclidean Norm
max_entries

Maximum
psd_coeff_offset

Given a problem returns a PSD constrain
norm1

1-Norm
project-methods

Project Value
resetOptions

Reset Options
get_data

Get Expression Data
.build_matrix_0

Get the sparse flag field for the LinOp object
reshape_expr

Reshape an Expression
sum_largest

Sum of Largest Values
is_stuffed_cone_objective

Is the objective a stuffed cone objective?
is_stuffed_qp_objective

Is the QP objective stuffed?
get_dual_values

Gets the values of the dual variables.
vstack

Vertical Concatenation
sum_smallest

Sum of Smallest Values
validate_args

Validate Arguments
upper_tri

Upper Triangle of a Matrix
logistic

Logistic Function
matrix_prop-methods

Matrix Properties
matrix_frac

Matrix Fraction
matrix_trace

Matrix Trace
norm_inf

Infinity-Norm
norm_nuc

Nuclear Norm
residual-methods

Constraint Residual
sum_squares

Sum of Squares
retrieve

Retrieve Solution
to_numeric

Numeric Value of Atom
vectorized_lower_tri_to_mat

Turns symmetric 2D array into a lower triangular matrix
vec

Vectorization of a Matrix