Atoms#
Atoms are pre-built mathematical functions that can be used in optimization objectives and constraints. They extend the base Atom class and provide efficient implementations of common optimization functions.
What are Atoms?#
Atoms represent mathematical functions with specific properties:
Smoothness: Whether the function is differentiable everywhere
Proxability: Whether the function has an efficient proximal operator
These properties determine which optimization algorithms can be used with the atom.
Available Atoms#
L1 Norm#
The L1Norm atom represents the L1 (Manhattan) norm: \(\|x\|_1 = \sum_i |x_i|\).
from rlaopt.atoms import L1Norm
from rlaopt.expression import Variable
x = Variable((10,), name='x')
l1 = L1Norm(x, scaling=0.1) # 0.1 * ||x||_1
L2 Norm#
The L2Norm atom represents the L2 (Euclidean) norm: \(\|x\|_2 = \sqrt{\sum_i x_i^2}\).
from rlaopt.atoms import L2Norm
from rlaopt.expression import Variable
x = Variable((10,), name='x')
l2 = L2Norm(x, scaling=0.1) # 0.1 * ||x||_2
Quadratic Form#
The QuadForm atom represents a quadratic form defined by a matrix \(Q\): \(x^\top Q x\).
import torch
from rlaopt.atoms import QuadForm
from rlaopt.expression import Variable
x = Variable((10,), name='x')
Q = torch.randn(10, 10)
Q = Q.T @ Q
qf = QuadForm(x, Q) # x^T Q x
The quadratic form is smooth, but it is not proxable, since its proximal operator would require solving a linear system.
Elastic Net#
The ElasticNet atom combines L1 and L2 regularization:
\(\lambda_1 \|x\|_1 + \lambda_2 \|x\|_2^2\).
from rlaopt.atoms import ElasticNet
from rlaopt.expression import Variable
x = Variable((10,), name='x')
elastic = ElasticNet(x, l1_scaling=0.1, l2_scaling=0.01)
Other Atoms#
rlaopt provides many other atoms:
SumSquares: Sum of squares (squared L2 norm)Box: Box constraintsHalfspace: Halfspace constraintsPolyhedron: Polyhedral constraintsL1NormBall: L1-norm ball constraintL2NormBall: L2-norm ball constraintLinearRegression: Linear (least-squares) regression lossLogisticRegression: Logistic regression lossPoissonRegression: Poisson regression lossHuberRegression: Huber regression lossMultinomialRegression: Multinomial regression loss
See the Atoms Module section for a complete list.
Using Atoms in Objectives#
Atoms can be combined with expressions to build optimization objectives:
from rlaopt.expression import Variable
from rlaopt.atoms import L1Norm, SumSquares
x = Variable((10,), name='x')
A = Variable((5, 10), name='A')
b = Variable((5,), name='b')
# Build objective: ||Ax - b||^2 + lambda * ||x||_1
residual = A @ x - b
objective = SumSquares(residual) + L1Norm(x, scaling=0.1)
Atom Properties#
Each atom provides information about its properties:
atom = L1Norm(x)
# Check if smooth
print(atom.is_smooth()) # False
# Check if proxable
print(atom.is_proxable()) # True
These properties help determine which solvers can be used with the atom.