Atoms¶
An atom (with a lower-case “a”) is a mathematical function that can be applied to
Expression
objects and returns an Expression
object.
Atoms and compositions thereof are precisely the mechanisms that allow you to build up mathematical expression trees in CVXPY.
Every atom is tagged with information about its domain, sign, curvature, log-log curvature, and monotonicity; this information lets atom instances reason about whether or not they are DCP or DGP. See the Atomic Functions page for a compact, accessible summary of each atom’s attributes.
- Affine Atoms
- Elementwise Atoms
- Other Atoms
- cummax
- cumprod
- cvar
- diff_pos
- dotsort
- eye_minus_inv
- geo_mean
- gmatmul
- harmonic_mean
- inv_prod
- lambda_max
- lambda_min
- lambda_sum_largest
- lambda_sum_smallest
- log_det
- log_sum_exp
- matrix_frac
- max
- min
- mixed_norm
- norm
- norm1
- norm2
- norm_inf
- normNuc
- one_minus_pos
- perspective
- pf_eigenvalue
- pnorm
- Pnorm
- ptp
- prod
- quad_form
- quad_over_lin
- resolvent
- sigma_max
- std
- sum_largest
- sum_smallest
- sum_squares
- SuppFuncAtom
- tr_inv
- tv
- var
- von_neumann_entr
Representation of atoms¶
From an implementation perspective, an atom might be the constructor for some class.
For example, the atom \(X \mapsto \lambda_{\max}(X)\) is applied by constructing
an instance of the lambda_max
class, which inherits
directly from Atom
and indirectly from Expression
.
Most atoms are implemented this way.
Alternatively, an atom be a wrapper that initializes and returns an Atom of some other class. For example, running
import cvxpy as cp
X = cp.Variable(shape=(2,2), symmetric=True)
expr = cp.lambda_min(X)
print(type(expr))
shows
<class 'cvxpy.atoms.affine.unary_operators.NegExpression'>
This happens because (1) CVXPY implements lambda_min()
as
(2) the negation operator is a class-based atom, and (3) the precise type of an Expression is based on the last class-based atom applied to it (if any such atom has been applied).
Atom¶
- class cvxpy.atoms.atom.Atom(*args)[source]¶
Bases:
Expression
Abstract base class for atoms.
- property domain : list[Constraint]¶
A list of constraints describing the closure of the region where the expression is finite.