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 ECOS and SCS. Recent versions (0.97+) also include support for commercial solvers such as MOSEK and GUROBI.

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.

Copy Link

Version

Install

install.packages('CVXR')

Monthly Downloads

8,918

Version

1.0

License

Apache License 2.0 | file LICENSE

Maintainer

Anqi Fu

Last Published

February 2nd, 2020

Functions in CVXR (1.0)

Abs-class

The Abs class.
AxisAtom-class

The AxisAtom class.
CPLEX_CONIC-class

An interface for the CPLEX solver
CBC_CONIC-class

An interface to the CBC solver
AffAtom-class

The AffAtom class.
CPLEX_QP-class

An interface for the CPLEX solver.
Atom-class

The Atom class.
BinaryOperator-class

The BinaryOperator class.
+,Expression,missing-method

The AddExpression class.
Canonical-class

The Canonical class.
Complex2Real.at_least_2D

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

The Canonicalization class.
Complex2Real.binary_canon

Complex canonicalizer for the binary atom
CVXR-package

CVXR: Disciplined Convex Optimization in R
Complex2Real.join

Helper function to combine arguments.
CallbackParam-class

The CallbackParam class.
CVXOPT-class

An interface for the CVXOPT solver.
Complex2Real.lambda_sum_largest_canon

Complex canonicalizer for the largest sum atom
Complex2Real.nonpos_canon

Complex canonicalizer for the non-positive atom
Complex2Real.matrix_frac_canon

Complex canonicalizer for the matrix fraction atom
Complex2Real.add

Helper function to sum arguments.
Complex2Real.abs_canon

Complex canonicalizer for the absolute value atom
Complex2Real.hermitian_canon

Complex canonicalizer for the hermitian atom
Chain-class

The Chain class.
Complex2Real.variable_canon

Complex canonicalizer for the variable atom
Complex2Real.soc_canon

Complex canonicalizer for the SOC atom
Complex2Real.conj_canon

Complex canonicalizer for the conjugate atom
Complex2Real.quad_over_lin_canon

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

Complex canonicalizer for the real atom
Conjugate-class

The Conjugate class.
Complex2Real.quad_canon

Complex canonicalizer for the quadratic atom
Complex2Real.separable_canon

Complex canonicalizer for the separable atom
Complex2Real.constant_canon

Complex canonicalizer for the constant atom
Complex2Real-class

Lifts complex numbers to a real representation.
Complex2Real.canonicalize_tree

Recursively Canonicalizes a Complex Expression.
Complex2Real.canonicalize_expr

Canonicalizes a Complex Expression
Complex2Real.norm_nuc_canon

Complex canonicalizer for the nuclear norm atom
Constant-class

The Constant class.
ConeMatrixStuffing-class

Construct Matrices for Linear Cone Problems
ConicSolver-class

The ConicSolver class.
Dcp2Cone.indicator_canon

Dcp2Cone canonicalizer for the indicator atom
Complex2Real.param_canon

Complex canonicalizer for the parameter matrix atom
Complex2Real.pnorm_canon

Complex canonicalizer for the p norm atom
Complex2Real.imag_canon

Complex canonicalizer for the imaginary atom
Complex2Real.psd_canon

Complex canonicalizer for the positive semidefinite atom
Dcp2Cone.huber_canon

Dcp2Cone canonicalizer for the huber atom
ConstantSolver-class

The ConstantSolver class.
CumSum-class

The CumSum class.
ConicSolver.get_coeff_offset

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

The Constraint class.
Dcp2Cone.entr_canon

Dcp2Cone canonicalizer for the entropy atom
Dcp2Cone-class

Reduce DCP Problem to Conic Form
Dcp2Cone.log_det_canon

Dcp2Cone canonicalizer for the log determinant atom
CumMax-class

The CumMax class.
Conv-class

The Conv class.
Dgp2Dcp.add_canon

Dgp2Dcp canonicalizer for the addition atom
ConicSolver.get_spacing_matrix

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

Dcp2Cone canonicalizer for the log atom
Dgp2Dcp.constant_canon

Dgp2Dcp canonicalizer for the constant atom
ConeDims-class

Summary of cone dimensions present in constraints.
Complex2Real.zero_canon

Complex canonicalizer for the zero atom
Dgp2Dcp.div_canon

Dgp2Dcp canonicalizer for the division atom
Dcp2Cone.log_sum_exp_canon

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

Dgp2Dcp canonicalizer for the 1-x atom
Dcp2Cone.logistic_canon

Dcp2Cone canonicalizer for the logistic function atom
Dcp2Cone.lambda_sum_largest_canon

Dcp2Cone canonicalizer for the largest lambda sum atom
Dgp2Dcp.exp_canon

Dgp2Dcp canonicalizer for the exp atom
CvxAttr2Constr-class

The CvxAttr2Constr class.
Dgp2Dcp.log_canon

Dgp2Dcp canonicalizer for the log atom
Dgp2Dcp.mul_canon

Dgp2Dcp canonicalizer for the multiplication atom
Dcp2Cone.log1p_canon

Dcp2Cone canonicalizer for the log 1p atom
Dgp2Dcp.zero_constr_canon

Dgp2Dcp canonicalizer for the zero constraint atom
Dgp2Dcp.nonpos_constr_canon

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

Dcp2Cone canonicalizer for the power atom
Dcp2Cone.normNuc_canon

Dcp2Cone canonicalizer for the nuclear norm atom
Dcp2Cone.matrix_frac_canon

Dcp2Cone canonicalizer for the matrix fraction atom
Dcp2Cone.pnorm_canon

Dcp2Cone canonicalizer for the p norm atom
Dgp2Dcp.mulexpression_canon

Dgp2Dcp canonicalizer for the multiplication expression atom
Dgp2Dcp.power_canon

Dgp2Dcp canonicalizer for the power 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.norm1_canon

Dgp2Dcp canonicalizer for the 1 norm atom
Dcp2Cone.exp_canon

Dcp2Cone canonicalizer for the exponential atom
EliminatePwl.min_elemwise_canon

EliminatePwl canonicalizer for the elementwise minimum atom
ECOS-class

An interface for the ECOS solver
Dgp2Dcp.prod_canon

Dgp2Dcp canonicalizer for the product atom
ECOS.dims_to_solver_dict

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

EliminatePwl canonicalizer for the minimum entries atom
GLPK-class

An interface for the GLPK solver.
FlipObjective-class

The FlipObjective class.
Dgp2Dcp.norm_inf_canon

Dgp2Dcp canonicalizer for the infinite norm atom
GUROBI_QP-class

An interface for the GUROBI_QP solver.
Dcp2Cone.geo_mean_canon

Dcp2Cone canonicalizer for the geometric mean atom
EliminatePwl.abs_canon

EliminatePwl canonicalizer for the absolute atom
DgpCanonMethods-class

DGP canonical methods class.
Dgp2Dcp.quad_over_lin_canon

Dgp2Dcp canonicalizer for the quadratic over linear term atom
DiffPos

The DiffPos atom.
Dgp2Dcp.quad_form_canon

Dgp2Dcp canonicalizer for the quadratic form atom
==,Expression,Expression-method

The EqConstraint class
EliminatePwl-class

The EliminatePwl class.
/,Expression,Expression-method

The DivExpression class.
Dgp2Dcp.parameter_canon

Dgp2Dcp canonicalizer for the parameter atom
GeoMean-class

The GeoMean class.
Dcp2Cone.kl_div_canon

Dcp2Cone canonicalizer for the KL Divergence atom
HarmonicMean

The HarmonicMean atom.
HStack-class

The HStack class.
Kron-class

The Kron class.
EvalParams-class

The EvalParams class.
LogDet-class

The LogDet class.
ListORConstr-class

A Class Union of List and Constraint
Log1p-class

The Log1p class.
Log-class

The Log class.
Dgp2Dcp.pf_eigenvalue_canon

Dgp2Dcp canonicalizer for the spectral radius atom
%*%,Expression,Expression-method

The MulExpression class.
Dcp2Cone.lambda_max_canon

Dcp2Cone canonicalizer for the lambda maximization atom
Diff

Takes the k-th order differences
EliminatePwl.norm1_canon

EliminatePwl canonicalizer for the 1 norm atom
DiagVec-class

The DiagVec class.
Norm2

The Norm2 atom.
Parameter-class

The Parameter class.
PSDWrap-class

The PSDWrap class.
Multiply-class

The Multiply class.
NormInf-class

The NormInf class.
LambdaMax-class

The LambdaMax class.
Dcp2Cone.sigma_max_canon

Dcp2Cone canonicalizer for the sigma max atom
Dgp2Dcp-class

Reduce DGP problems to DCP problems.
EliminatePwl.norm_inf_canon

EliminatePwl canonicalizer for the infinite norm atom
QpSolver-class

A QP solver interface.
QuadForm-class

The QuadForm class.
EliminatePwl.max_elemwise_canon

EliminatePwl canonicalizer for the elementwise maximum atom
ECOS_BB-class

An interface for the ECOS BB solver.
EliminatePwl.max_entries_canon

EliminatePwl canonicalizer for the max entries atom
Dgp2Dcp.pnorm_canon

Dgp2Dcp canonicalizer for the p norm atom
Elementwise-class

The Elementwise class.
Dgp2Dcp.eye_minus_inv_canon

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

Dgp2Dcp canonicalizer for the geometric mean atom
EliminatePwl.sum_largest_canon

EliminatePwl canonicalizer for the largest sum atom
Expression-class

The Expression class.
SigmaMax-class

The SigmaMax class.
Dgp2Dcp.sum_canon

Dgp2Dcp canonicalizer for the sum atom
Entr-class

The Entr class.
LogSumExp-class

The LogSumExp class.
GLPK_MI-class

An interface for the GLPK MI solver.
KLDiv-class

The KLDiv class.
GUROBI_CONIC-class

An interface for the GUROBI conic solver.
EyeMinusInv-class

The EyeMinusInv class.
InverseData-class

The InverseData class.
Diag

Turns an expression into a DiagVec object
SizeMetrics-class

The SizeMetrics class.
DiagMat-class

The DiagMat class.
Dgp2Dcp.trace_canon

Dgp2Dcp canonicalizer for the trace atom
EliminatePwl.cummax_canon

EliminatePwl canonicalizer for the cumulative max atom
Objective-arith

Arithmetic Operations on Objectives
MinElemwise-class

The MinElemwise class.
Logistic-class

The Logistic class.
Objective-class

The Objective class.
MinEntries-class

The MinEntries class.
EliminatePwl.cumsum_canon

EliminatePwl canonicalizer for the cumulative sum atom
Exp-class

The Exp class.
ExpCone-class

The ExpCone class.
Huber-class

The Huber class.
MOSEK.recover_dual_variables

Recovers MOSEK solutions dual variables
OneMinusPos-class

The OneMinusPos class.
Minimize-class

The Minimize class.
MatrixFrac-class

The MatrixFrac class.
Norm

The Norm atom.
Norm1-class

The Norm1 class.
MixedNorm

The MixedNorm atom.
PfEigenvalue-class

The PfEigenvalue class.
Pnorm-class

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

The IneqConstraint class
LambdaMin

The LambdaMin atom.
[,Expression,missing,missing,ANY-method

The Index class.
Imag-class

The Imag class.
SumSmallest

The SumSmallest atom.
SumSquares

The SumSquares atom.
ProdEntries-class

The ProdEntries class.
Promote-class

The Promote class.
Leaf-class

The Leaf class.
MOSEK-class

An interface for the MOSEK solver.
LambdaSumSmallest

The LambdaSumSmallest atom.
%>>%

The PSDConstraint class.
Real-class

The Real class.
Rdictdefault-class

The Rdictdefault class.
LambdaSumLargest-class

The LambdaSumLargest class.
SOC-class

The SOC class.
abs,Expression-method

Absolute Value
MatrixStuffing-class

The MatrixStuffing class.
MOSEK.parse_dual_vars

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

The SOCAxis class.
Solution-class

The Solution class.
SolverStats-class

The SolverStats class.
ZeroConstraint-class

The ZeroConstraint class
Wrap-class

The Wrap class.
Reshape-class

The Reshape class.
-,Expression,missing-method

The NegExpression class.
Neg

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

The MaxElemwise class.
accepts

Reduction Acceptance
are_args_affine

Are the arguments affine?
SymbolicQuadForm-class

The SymbolicQuadForm class.
SCS-class

An interface for the SCS solver
MaxEntries-class

The MaxEntries class.
NormNuc-class

The NormNuc class.
Maximize-class

The Maximize class.
TotalVariation

The TotalVariation atom.
UnaryOperator-class

The UnaryOperator class.
UpperTri-class

The UpperTri class.
cone-methods

Second-Order Cone Methods
construct_intermediate_chain,Problem,list-method

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

Is Constraint Violated?
construct_solving_chain

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

Matrix Norm (Alternative)
.LinOpVector__new

Create a new LinOpVector object.
curvature

Curvature of Expression
.LinOpVector__push_back

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

Set the flag sparse of the LinOp object
diag,Expression-method

Matrix Diagonal
.LinOp__set_sparse_data

Set the field named sparse_data of the LinOp object
.LinOp__args_push_back

Perform a push back operation on the args field of LinOp
.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
.LinOp__get_dense_data

Get the field dense_data for the LinOp object
bmat

Block Matrix
diff,Expression-method

Lagged and Iterated Differences
OSQP-class

An interface for the OSQP solver.
Power-class

The Power class.
Pos

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

The NonPosConstraint class
.ProblemData__new

Create a new ProblemData object.
Problem-arith

Arithmetic Operations on Problems
NonlinearConstraint-class

The NonlinearConstraint class.
Problem-class

The Problem class.
ReductionSolver-class

The ReductionSolver class.
Rdict-class

The Rdict class.
Reduction-class

The Reduction class.
QuadOverLin-class

The QuadOverLin class.
SumEntries-class

The SumEntries class.
.ProblemData__set_I

Set the I field in the ProblemData Object
.LinOp__slice_push_back

Perform a push back operation on the slice field of LinOp
.ProblemData__set_const_to_row

Set the const_to_row map of the ProblemData Object
.LinOp_at_index

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

Is the QP objective stuffed?
harmonic_mean

Harmonic Mean
eye_minus_inv

Unity Resolvent
invert

Return Original Solution
is_stuffed_cone_objective

Is the objective a stuffed cone objective?
group_constraints

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

Coalesces bool, int indices for variables.
.ProblemData__set_J

Set the J field in the ProblemData Object
.ProblemData__set_V

Set the V field in the ProblemData Object
is_dcp

DCP Compliance
log_log_curvature

Log-Log Curvature of Expression
cummax_axis

Cumulative Maximum
.LinOp__get_sparse

Get the sparse flag field for the LinOp object
conv

Discrete Convolution
.LinOp__get_slice

Get the slice field of the LinOp Object
VStack-class

The VStack class.
SumLargest-class

The SumLargest class.
Variable-class

The Variable class.
Qp2SymbolicQp-class

The Qp2SymbolicQp class.
complex-atoms

Complex Numbers
complex-methods

Complex Properties
.LinOp__set_size

Set the field size of the LinOp object
matrix_trace

Matrix Trace
matrix_prop-methods

Matrix Properties
log_sum_exp

Log-Sum-Exponential
.LinOp__set_slice

Set the slice field of the LinOp Object
curvature-atom

Curvature of an Atom
cumsum_axis

Cumulative Sum
.ProblemData__get_const_vec

Get the const_vec field from the ProblemData Object
.p_norm

Internal method for calculating the p-norm
.ProblemData__get_id_to_col

Get the id_to_col field of the ProblemData Object
dspop

Direct Standardization: Population
norm2

Euclidean Norm
norm1

1-Norm
QpMatrixStuffing-class

The QpMatrixStuffing class.
SCS.extract_dual_value

Extracts the dual value for constraint starting at offset.
SCS.dims_to_solver_dict

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

Set the const_vec field in the ProblemData Object
SolvingChain-class

The SolvingChain class.
problem-parts

Parts of a Problem
residual-methods

Constraint Residual
expression-parts

Parts of an Expression Leaf
entr

Entropy Function
get_np

Get numpy handle
exp,Expression-method

Natural Exponential
is_dgp

DGP Compliance
get_id

Get ID
Transpose-class

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

The SpecialIndex class.
Trace-class

The Trace class.
sum_largest

Sum of Largest Values
retrieve

Retrieve Solution
prod_entries

Product of Entries
sum_smallest

Sum of Smallest Values
.LinOp__get_size

Get the field size for the LinOp object
.LinOp__new

Create a new LinOp object.
.LinOp__get_id

Get the id field of the LinOp Object
.LinOp__set_dense_data

Set the field dense_data of the LinOp object
extract_dual_value

Gets a specified value of a dual variable.
tv

Total Variation
.ProblemData__get_const_to_row

Get the const_to_row field of the ProblemData Object
.ProblemData__set_id_to_col

Set the id_to_col field of the ProblemData Object
format_constr

Format Constraints
unpack_results

Parse output from a solver and updates problem state
.ProblemData__get_V

Get the V field of the ProblemData Object
.build_matrix_0

Get the sparse flag field for the LinOp object
geo_mean

Geometric Mean
kl_div

Kullback-Leibler Divergence
is_mixed_integer

Is Problem Mixed Integer?
grad

Sub/Super-Gradient
get_data

Get Expression Data
id

Identification Number
canonicalize

Canonicalize
is_stuffed_cone_constraint

Is the constraint a stuffed cone constraint?
leaf-attr

Attributes of an Expression Leaf
import_solver

Import Solver
graph_implementation

Graph Implementation
is_qp

Is Problem a QP?
min_entries

Minimum
linearize

Affine Approximation to an Expression
quad_over_lin

Quadratic over Linear
mip_capable

Solver Capabilities
log_log_curvature-methods

Log-Log Curvature Properties
lambda_max

Maximum Eigenvalue
hstack

Horizontal Concatenation
log_log_curvature-atom

Log-Log Curvature of an Atom
lambda_min

Minimum Eigenvalue
one_minus_pos

Difference on Restricted Domain
get_dual_values

Gets the values of the dual variables.
huber

Huber Function
sigma_max

Maximum Singular Value
mean.Expression

Arithmetic Mean
curvature-comp

Curvature of Composition
cdiac

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

Curvature Properties
dim_from_args

Atom Dimensions
domain

Domain
.LinOp__get_sparse_data

Get the field named sparse_data from the LinOp object
.LinOp__get_type

Get the field named type for the LinOp object
sign_from_args

Atom Sign
t.Expression

Matrix Transpose
project-methods

Project Value
multiply

Elementwise Multiplication
name

Variable, Parameter, or Expression Name
vec

Vectorization of a Matrix
psd_coeff_offset

Given a problem returns a PSD constrain
size-methods

Size Properties
reduce

Reduce a Problem
setIdCounter

Set ID Counter
tri_to_full

Expands lower triangular to full matrix.
vectorized_lower_tri_to_mat

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

Compute a Matrix Decomposition.
.ProblemData__get_J

Get the J field of the ProblemData Object
.build_matrix_1

Get the sparse flag field for the LinOp object
get_problem_data

Get Problem Data
dssamp

Direct Standardization: Sample
dual_value-methods

Get and Set Dual Value
get_sp

Get scipy handle
.ProblemData__get_I

Get the I field of the ProblemData Object
min_elemwise

Elementwise Minimum
installed_solvers

Installed Solvers
inv_pos

Reciprocal Function
pos

Elementwise Positive
p_norm

P-Norm
sign-methods

Sign Properties
^,Expression,numeric-method

Elementwise Power
sign,Expression-method

Sign of Expression
lambda_sum_smallest

Sum of Smallest Eigenvalues
lambda_sum_largest

Sum of Largest Eigenvalues
max_elemwise

Elementwise Maximum
sum_squares

Sum of Squares
to_numeric

Numeric Value of Atom
logistic

Logistic Function
matrix_frac

Matrix Fraction
kronecker,Expression,ANY-method

Kronecker Product
norm_inf

Infinity-Norm
max_entries

Maximum
perform

Perform Reduction
pf_eigenvalue

Perron-Frobenius Eigenvalue
log,Expression-method

Logarithms
log_det

Log-Determinant
neg

Elementwise Negative
mixed_norm

Mixed Norm
*,Expression,Expression-method

Elementwise multiplication operator
psolve

Solve a DCP Problem
norm,Expression,character-method

Matrix Norm
resetOptions

Reset Options
value-methods

Get or Set Value
norm_nuc

Nuclear Norm
square,Expression-method

Square
reshape_expr

Reshape an Expression
quad_form

Quadratic Form
validate_val

Validate Value
sum_entries

Sum of Entries
scalene

Scalene Function
scaled_lower_tri

Utility methods for special handling of semidefinite constraints.
upper_tri

Upper Triangle of a Matrix
vstack

Vertical Concatenation
sqrt,Expression-method

Square Root
size

Size of Expression
validate_args

Validate Arguments