Proxable functions¶
Proxable functions are convex functions whose proximal operators can be used as
steps, each supplying a numerical prox and the encoding needed by the
verification problem. Use vp.prox(function, arg, gamma=1.0); support varies by
backend, and unsupported operations raise explicitly. They all derive from the
abstract base class below.
ProxableFunction
¶
Abstract base class for proxable functions.
A function \(f : \mathbb{R}^n \to \mathbb{R} \cup \{+\infty\}\) is proxable if its proximal operator
can be evaluated efficiently (in closed form or via a structured subproblem).
Subclasses provide the numerical interface (eval, prox, grad).
The mapping from a proxable function to one or more steps lives in the
step decomposer's _PROX_DECOMPOSERS registry — it is not a method
on this class.
Source code in fomtools/proxable_functions/proximal_operator.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised by the base class; must be implemented by subclasses. |
Source code in fomtools/proxable_functions/proximal_operator.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient (or a subgradient) of the function at x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the (sub)gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Gradient \(\nabla f(x)\) or a subgradient when \(f\) is non-smooth. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised by the base class; must be implemented by subclasses. |
Source code in fomtools/proxable_functions/proximal_operator.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute the proximal point of the function.
Solves
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point at which to evaluate the proximal operator. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised by the base class; must be implemented by subclasses. |
Source code in fomtools/proxable_functions/proximal_operator.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
ElasticNet
¶
Bases: ProxableFunction
Elastic-net regularizer.
Represents
Convex; strongly convex when \(\beta > 0\). Note that the \(\ell_2\) term has no leading \(1/2\) factor: \(\nabla(\beta \|x\|_2^2) = 2\beta x\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Weight \(\alpha \ge 0\) of the \(\ell_1\) term. |
required |
beta
|
float
|
Weight \(\beta \ge 0\) of the squared \(\ell_2\) term. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
NormL1 : The case \(\beta = 0\), identical to NormL1(lambd=alpha).
Notes
Proximal operator.
where \(S_\lambda(w) = \operatorname{sign}(w)\,\max(|w| - \lambda, 0)\) is element-wise soft thresholding. For \(\alpha = 0\) it reduces to the ridge shrinkage \(v / (1 + 2\beta\gamma)\).
Verification lowering. prox_elasticnet posts a single
SoftThreshold step with threshold \(\alpha\gamma\) and scales its output
by \(1 / (1 + 2\beta\gamma)\).
Source code in fomtools/proxable_functions/elastic_net.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \alpha\|x\|_1 + \beta\|x\|_2^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/elastic_net.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0 \in [-1, 1]\) is the canonical choice at the kink \(x_i = 0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/elastic_net.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/elastic_net.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
HingeLoss
¶
Bases: ProxableFunction
Hinge loss (unlabeled).
Represents
Convex and piecewise linear.
See Also
LabeledHingeLoss : Labeled variant \(\sum_i \max(0, 1 - y_i x_i)\).
Notes
Proximal operator. Element-wise separable; per coordinate,
which collapses to \(\operatorname{prox}_{\gamma f}(v) = v + \mathrm{satlin}(1 - v;\, 0,\, \gamma)\).
Verification lowering. prox_hingeloss posts a single
SaturatedLinear clip of the margin residual \(1 - v\) to \([0, \gamma]\)
and adds it back to the input.
Source code in fomtools/proxable_functions/hinge_loss.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i \max(0, 1 - x_i)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/hinge_loss.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0 \in [-1, 0]\) is the canonical choice at the kink \(x_i = 1\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/hinge_loss.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/hinge_loss.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
HuberLoss
¶
Bases: ProxableFunction
Element-wise Huber loss.
Represents
Convex and \(C^1\). This is the standard element-wise robust loss, not the multivariate norm-based "vector Huber" function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta
|
float
|
Threshold \(\delta \ge 0\) between the quadratic and linear regimes. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
Proximal operator. Element-wise separable; per coordinate,
The branches join continuously at \(|v_i| = \delta(1+\gamma)\). Equivalently, with element-wise soft thresholding \(S\),
Verification lowering. prox_huberloss uses the soft-threshold form:
a single SoftThreshold step with threshold \(\delta(1+\gamma)\) followed
by affine arithmetic.
Source code in fomtools/proxable_functions/huber_loss.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i h(x_i)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/huber_loss.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient of \(f\) at x.
Per coordinate,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The gradient \(\nabla f(x)\). |
Source code in fomtools/proxable_functions/huber_loss.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form, per coordinate,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/huber_loss.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
IndAffine
¶
Bases: ProxableFunction
Indicator of the affine set \(\{x : Ax = b\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Constraint matrix of shape |
required |
b
|
float, np.ndarray, or LinearExpression
|
Right-hand side of shape |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndPolyhedral : Inequality-constrained counterpart \(\{Ax \le b\}\).
Notes
Proximal operator. The Euclidean projection onto the affine set, independent of \(\gamma\). Its KKT conditions form the block system
whose solution is \(u = v - A^\top (AA^\top)^{-1}(Av - b)\).
Verification lowering. prox_indaffine posts the two KKT rows as
linear equalities on fresh iterates \(u\) and \(\nu\); it never forms
\((AA^\top)^{-1}\) and needs no complementarity constraints.
Source code in fomtools/proxable_functions/ind_affine.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{Ax = b\}}(x)\).
Requires numeric b; a LinearExpression b is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/ind_affine.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_affine.py
149 150 151 152 153 154 155 156 157 158 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the affine set \(\{x : Ax = b\}\).
Solves the \(m \times m\) system \(AA^\top \nu = A\,\text{arg} - b\) and returns \(\text{arg} - A^\top \nu\).
Requires numeric b; a LinearExpression b is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/ind_affine.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
IndBallL1
¶
Bases: ProxableFunction
Indicator of the \(\ell_1\) ball \(\{x : \|x\|_1 \le r\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float or LinearExpression
|
Ball radius \(r \ge 0\), or a dim-1 |
required |
dual_ub
|
float or None
|
Upper bound on the KKT multipliers used by the verification lowering.
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndBallLinf : The \(\ell_\infty\) ball. NormInf : Its prox is computed from this projection by Moreau decomposition.
Notes
Proximal operator. The Euclidean projection onto the ball,
independent of \(\gamma\).
Verification lowering. prox_indballl1 encodes the KKT system of the
lifted problem
with complementarity constraints, bounding the multipliers by dual_ub.
Source code in fomtools/proxable_functions/ind_ball_l1.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the \(\ell_1\) ball of radius \(r\).
Solved numerically with CVXPY (Clarabel) as an independent reference; a
LinearExpression r uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_ball_l1.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
IndBallLinf
¶
Bases: ProxableFunction
Indicator of the \(\ell_\infty\) ball \(\{x : \|x\|_\infty \le r\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Ball radius \(r \ge 0\). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndBox : General box \([l, u]\). IndBallL1 : The \(\ell_1\) ball.
Notes
Proximal operator. The Euclidean projection onto the ball, an element-wise clip,
independent of \(\gamma\).
Verification lowering. prox_indballlinf posts a single
SaturatedLinear step clipping to \([-r, r]\).
Source code in fomtools/proxable_functions/ind_ball_linf.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{\|x\|_\infty \leq r\}}(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in fomtools/proxable_functions/ind_ball_linf.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_ball_linf.py
93 94 95 96 97 98 99 100 101 102 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the \(\ell_\infty\) ball of radius \(r\).
Computes \(\operatorname{clip}(\text{arg}, -r, r)\) element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_ball_linf.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
IndBox
¶
Bases: ProxableFunction
Indicator of the box \([l, u]\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l
|
float, np.ndarray, or LinearExpression
|
Lower bound. A scalar is broadcast; a |
required |
u
|
float, np.ndarray, or LinearExpression
|
Upper bound, with the same conventions as |
required |
See Also
IndBallLinf : Symmetric box \([-r, r]\). IndNonNegative : One-sided box \([0, +\infty)\).
Notes
Proximal operator. The Euclidean projection onto the box,
independent of \(\gamma\).
Verification lowering. prox_indbox posts a single
SaturatedLinear step clipping to \([l, u]\). LinearExpression bounds
enter through their interval bounds during bound propagation.
Source code in fomtools/proxable_functions/ind_box.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{[l, u]}(x)\).
Requires numeric l and u; LinearExpression bounds are
supported only by the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/ind_box.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_box.py
122 123 124 125 126 127 128 129 130 131 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the box \([l, u]\).
Computes \(\min(\max(\text{arg}, l), u)\) element-wise.
Requires numeric l and u; LinearExpression bounds are
supported only by the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/ind_box.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
IndHalfSpace
¶
Bases: ProxableFunction
Indicator of the closed half-space \(\{x : a^\top x \le b\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Nonzero normal vector of shape |
required |
b
|
float
|
Offset. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndPolyhedral : Intersection of several half-spaces \(\{Ax \le b\}\).
Notes
Proximal operator. The Euclidean projection onto the half-space,
independent of \(\gamma\).
Verification lowering. prox_indhalfspace posts a single scalar
Relu step on \((a^\top v - b)/\|a\|_2^2\) and lifts it back along \(a\).
Source code in fomtools/proxable_functions/ind_half_space.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{a^\top x \le b\}}(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in fomtools/proxable_functions/ind_half_space.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_half_space.py
100 101 102 103 104 105 106 107 108 109 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the half-space \(\{x : a^\top x \le b\}\).
Computes \(\text{arg} - \max(0,\, a^\top \text{arg} - b)\, a / \|a\|_2^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_half_space.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
IndNonNegative
¶
Bases: ProxableFunction
Indicator of the non-negative orthant.
Represents
See Also
IndNonPositive : The non-positive orthant. IndBox : General box \([l, u]\). SoftNonNegative : Smooth quadratic relaxation.
Notes
Proximal operator. The Euclidean projection onto the orthant,
independent of \(\gamma\).
Verification lowering. prox_indnonnegative posts a single Relu
step.
Source code in fomtools/proxable_functions/ind_nonnegative.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{x \geq 0\}}(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in fomtools/proxable_functions/ind_nonnegative.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_nonnegative.py
80 81 82 83 84 85 86 87 88 89 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the non-negative orthant.
Computes \(\max(\text{arg}, 0)\) element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_nonnegative.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
IndNonPositive
¶
Bases: ProxableFunction
Indicator of the non-positive orthant.
Represents
See Also
IndNonNegative : The non-negative orthant. IndBox : General box \([l, u]\).
Notes
Proximal operator. The Euclidean projection onto the orthant,
independent of \(\gamma\).
Verification lowering. prox_indnonpositive posts a single Relu
step via \(\min(v, 0) = -\operatorname{ReLU}(-v)\).
Source code in fomtools/proxable_functions/ind_nonpositive.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{x \leq 0\}}(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in fomtools/proxable_functions/ind_nonpositive.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_nonpositive.py
79 80 81 82 83 84 85 86 87 88 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the non-positive orthant.
Computes \(\min(\text{arg}, 0)\) element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_nonpositive.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
IndPoint
¶
Bases: ProxableFunction
Indicator of the singleton \(\{p\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float or ndarray
|
The point. A scalar is broadcast against the input. |
required |
See Also
IndBox : The box \([l, u]\); \(\{p\}\) is the case \(l = u = p\).
Notes
Proximal operator. The constant map
independent of \(\gamma\).
Verification lowering. prox_indpoint posts a degenerate
SaturatedLinear step with \(l = u = p\).
Source code in fomtools/proxable_functions/ind_point.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = I_{\{p\}}(x)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in fomtools/proxable_functions/ind_point.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
grad
¶
grad(x: ndarray) -> ndarray
Not defined: indicator functions are not differentiable.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always. |
Source code in fomtools/proxable_functions/ind_point.py
86 87 88 89 90 91 92 93 94 95 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto \(\{p\}\).
Returns \(p\) broadcast to the shape of arg; arg is used only for
its shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_point.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
IndPolyhedral
¶
Bases: ProxableFunction
Indicator of the polyhedron \(\{x : Ax \le b\}\).
Represents
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Constraint matrix of shape |
required |
b
|
float, np.ndarray, or LinearExpression
|
Right-hand side. A scalar or array is broadcast to shape |
required |
dual_ub
|
float, np.ndarray, or None
|
Upper bound(s) on the multipliers \(\lambda \ge 0\). Required for
verification: the multipliers of a general polyhedron cannot be bounded
automatically, so the verification lowering raises |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndHalfSpace : Single half-space, with a closed-form projection. IndAffine : Equality-constrained counterpart \(\{Ax = b\}\).
Notes
Proximal operator. The Euclidean projection onto the polyhedron,
independent of \(\gamma\).
Verification lowering. prox_indpolyhedral encodes the KKT system
with complementarity constraints. The MIP big-M encoding needs the finite
bound dual_ub on \(\lambda\); OBBT tightens it further when enabled.
Source code in fomtools/proxable_functions/ind_polyhedral.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the polyhedron \(\{x : Ax \le b\}\).
Solved numerically with CVXPY (Clarabel) as an independent reference; a
LinearExpression b uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point of dimension |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_polyhedral.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
IndSimplex
¶
Bases: ProxableFunction
Indicator of the scaled simplex \(\{x : x \ge 0,\ \mathbf{1}^\top x = a\}\).
Represents
For \(a = 1\) this is the probability simplex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float or LinearExpression
|
Simplex sum \(a > 0\), or a dim-1 |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndPolyhedral : General polyhedron \(\{Ax \le b\}\).
Notes
Proximal operator. The Euclidean projection onto the simplex,
independent of \(\gamma\).
Verification lowering. prox_indsimplex encodes the KKT system of
this projection with complementarity constraints. The simplex is bounded,
so the multiplier bounds are derived from the input box and no dual_ub
is needed.
Source code in fomtools/proxable_functions/ind_simplex.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Project arg onto the simplex \(\{x : x \ge 0,\ \mathbf{1}^\top x = a\}\).
Solved numerically with CVXPY (Clarabel) as an independent reference; a
LinearExpression a uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size; unused, since the projection is independent of \(\gamma\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/ind_simplex.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
LabeledHingeLoss
¶
Bases: ProxableFunction
Labeled hinge loss for binary classification.
Represents
with labels \(y \in \{-1, +1\}^n\) fixed at construction. Convex and
piecewise linear; for \(y = \mathbf{1}\) it reduces to HingeLoss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
ndarray
|
1-D array of labels, each exactly \(\pm 1\) (\(\{0, 1\}\)-encoded labels are rejected). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
HingeLoss : Unlabeled case \(y = \mathbf{1}\).
Notes
Proximal operator. The substitution \(w = y u\), \(z = y v\) (using \(y_i^2 = 1\)) reduces the labeled prox to the unlabeled one; back-substituting,
Verification lowering. prox_labeledhingeloss posts a single
SaturatedLinear clip of \(1 - y \odot v\) to \([0, \gamma]\); the
element-wise scaling by \(y\) is a sparse diagonal matrix.
Source code in fomtools/proxable_functions/labeled_hinge_loss.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i \max(0, 1 - y_i x_i)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/labeled_hinge_loss.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0\) is the canonical choice at the kink \(y_i x_i = 1\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/labeled_hinge_loss.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/labeled_hinge_loss.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
LeastSquares
¶
Bases: Quadratic
Least-squares loss.
Represents
Convex and smooth. This is a Quadratic with \(Q = A^\top A\) and
\(q = -A^\top b\) plus a constant, so prox and grad are inherited;
only eval is overridden to add back \(\tfrac{1}{2}\|b\|_2^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
np.ndarray or scipy.sparse matrix
|
Data matrix of shape |
required |
b
|
float, np.ndarray, or LinearExpression
|
Target of shape |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
Quadratic : Parent class.
Notes
Proximal operator.
Verification lowering. Registered to prox_quadratic: a single linear
equality on a fresh iterate, as for Quadratic.
Source code in fomtools/proxable_functions/least_squares.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \tfrac{1}{2}\|Ax - b\|_2^2\).
Requires numeric b; a LinearExpression b is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/least_squares.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
Linear
¶
Bases: ProxableFunction
Linear cost.
Represents
Convex and smooth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
float, np.ndarray, or LinearExpression
|
Cost vector. A scalar is broadcast; a |
required |
Notes
Proximal operator.
Verification lowering. prox_linear is a pure affine shift; no step
and no fresh leaf variables are introduced.
Source code in fomtools/proxable_functions/linear.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = c^\top x\).
Requires numeric c; a LinearExpression c is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/linear.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient of \(f\) at x.
\(\nabla f(x) = c\), broadcast to the shape of x.
Requires numeric c; a LinearExpression c is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The gradient \(\nabla f(x)\). |
Source code in fomtools/proxable_functions/linear.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form \(\operatorname{prox}_{\gamma f}(\text{arg}) = \text{arg} - \gamma c\).
Requires numeric c; a LinearExpression c is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/linear.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
NormInf
¶
Bases: ProxableFunction
Scaled \(\ell_\infty\) norm.
Represents
Convex and piecewise linear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambd
|
float or LinearExpression
|
Weight \(\lambda \ge 0\) (a single scalar, since the \(\ell_\infty\) norm is
not separable), or a dim-1 |
1.0
|
dual_ub
|
float or None
|
Upper bound forwarded to the underlying |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndBallL1 : Projection used by the Moreau decomposition below. NormL1 : The \(\ell_1\) norm.
Notes
Proximal operator. By Moreau decomposition, the prox is the residual of the projection onto the dual-norm ball,
Verification lowering. prox_norminf applies this identity, reusing
prox_indballl1 with radius \(\gamma\lambda\) and the given dual_ub.
Source code in fomtools/proxable_functions/norm_inf.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
_lambd_value
¶
_lambd_value() -> float
Concrete scalar weight (a parameter uses its stored constant value).
Source code in fomtools/proxable_functions/norm_inf.py
70 71 72 73 74 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \lambda \|x\|_\infty\).
A LinearExpression lambd uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/norm_inf.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Solved numerically with CVXPY (Clarabel) from the defining problem, as
a reference independent of the Moreau identity used by the verification
lowering; a LinearExpression lambd uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/norm_inf.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
NormL1
¶
Bases: ProxableFunction
Weighted \(\ell_1\) norm.
Represents
which is \(\lambda \|x\|_1\) when lambd is a scalar. Convex and piecewise
linear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambd
|
float or ndarray
|
Non-negative weight: a scalar, or a 1-D array of per-coordinate weights. |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any weight is negative, or |
See Also
ElasticNet : Adds a squared \(\ell_2\) term. NormInf : The \(\ell_\infty\) norm.
Notes
Proximal operator. Element-wise soft thresholding,
Verification lowering. prox_norml1 posts a single SoftThreshold
step with threshold \(\gamma\lambda\).
Source code in fomtools/proxable_functions/norm_l1.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i \lambda_i |x_i|\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in fomtools/proxable_functions/norm_l1.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0\) is the canonical choice at the kink \(x_i = 0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/norm_l1.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
prox
¶
prox(arg: ndarray, gamma: float | ndarray = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Applies element-wise soft thresholding by \(\gamma \lambda\). With an
array gamma, this is the prox in the scaled metric
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float or ndarray
|
Step size \(\gamma > 0\): a scalar, or an array broadcastable to the
shape of |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in fomtools/proxable_functions/norm_l1.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
Quadratic
¶
Bases: ProxableFunction
Convex quadratic.
Represents
Convex and smooth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
np.ndarray or scipy.sparse matrix
|
Symmetric positive semidefinite matrix of shape |
required |
q
|
float, np.ndarray, or LinearExpression
|
Linear term of shape |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
LeastSquares : The case \(Q = A^\top A\), \(q = -A^\top b\). SqL2Norm : The case \(Q = I\), \(q = 0\).
Notes
Proximal operator. The unique solution \(u\) of the linear system
Verification lowering. prox_quadratic posts this single linear
equality on a fresh iterate \(u\); no inverse is formed and no duals or
complementarity constraints are introduced.
Source code in fomtools/proxable_functions/quadratic.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \tfrac{1}{2}\,x^\top Q x + q^\top x\).
Requires numeric q; a LinearExpression q is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/quadratic.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient of \(f\) at x.
\(\nabla f(x) = Qx + q\).
Requires numeric q; a LinearExpression q is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The gradient \(\nabla f(x)\). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in fomtools/proxable_functions/quadratic.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Solves \((I + \gamma Q)\, u = \text{arg} - \gamma q\) directly (sparse
solve when Q is sparse).
Requires numeric q; a LinearExpression q is supported only by
the verification lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/quadratic.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
SoftNonNegative
¶
Bases: ProxableFunction
One-sided quadratic penalty on negative coordinates.
Represents
Convex, smooth, and zero on the non-negative orthant. Its prox is a scaled LeakyReLU, and the slope \(\alpha\) interpolates between two familiar cases:
- \(\alpha = 1\): \(f \equiv 0\), so the prox is the identity.
- \(\alpha \to 0^+\): \(f\) tends to the indicator \(I_{\mathbb{R}_+^n}\), and the prox tends to ReLU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
LeakyReLU slope \(\alpha \in (0, 1]\). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
IndNonNegative : The limit \(\alpha \to 0^+\).
Notes
Proximal operator.
an element-wise LeakyReLU with effective slope \(\tilde\alpha(\gamma)\); at \(\gamma = 1\) the slope is \(\alpha\).
Verification lowering. prox_softnonnegative posts a single Relu
step and combines it affinely with the input.
Source code in fomtools/proxable_functions/soft_nonnegative.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \frac{1-\alpha}{2\alpha}\sum_i \min(x_i, 0)^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/soft_nonnegative.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient of \(f\) at x.
\(\nabla f(x)_i = \frac{1-\alpha}{\alpha}\,\min(x_i, 0)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The gradient \(\nabla f(x)\). |
Source code in fomtools/proxable_functions/soft_nonnegative.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Applies a LeakyReLU with effective slope \(\tilde\alpha(\gamma) = \alpha / (\alpha + \gamma(1-\alpha))\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/soft_nonnegative.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
SqL2Norm
¶
Bases: ProxableFunction
Squared \(\ell_2\) norm.
Represents
Convex and smooth.
See Also
Quadratic : General convex quadratic \(\tfrac{1}{2} x^\top Q x + q^\top x\).
Notes
Proximal operator.
Verification lowering. prox_sql2norm is a pure scalar shrinkage; no
step and no fresh leaf variables are introduced.
Source code in fomtools/proxable_functions/sq_l2_norm.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \tfrac{1}{2}\|x\|_2^2\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/sq_l2_norm.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute the gradient of \(f\) at x.
\(\nabla f(x) = x\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the gradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The gradient \(\nabla f(x)\). |
Source code in fomtools/proxable_functions/sq_l2_norm.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form \(\operatorname{prox}_{\gamma f}(\text{arg}) = \text{arg}/(1 + \gamma)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/sq_l2_norm.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
SumNegative
¶
Bases: ProxableFunction
Sum of negative parts.
Represents
Convex and piecewise linear. Penalizes only the negative coordinates and leaves non-negative ones untouched.
See Also
SumPositive : Mirror image under \(x \mapsto -x\). NormL1 : Two-sided counterpart \(\lambda \|x\|_1\).
Notes
Proximal operator. Element-wise separable; per coordinate,
which collapses to \(\operatorname{prox}_{\gamma f}(v) = v - \mathrm{satlin}(v;\, -\gamma,\, 0)\).
Verification lowering. prox_sumnegative posts a single
SaturatedLinear clip to \([-\gamma, 0]\) and subtracts it from the input.
Source code in fomtools/proxable_functions/sum_negative.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i \max(0, -x_i)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/sum_negative.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0 \in [-1, 0]\) is the canonical choice at the kink \(x_i = 0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/sum_negative.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/sum_negative.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
SumPositive
¶
Bases: ProxableFunction
Sum of positive parts.
Represents
Convex and piecewise linear. A one-sided variant of \(\|x\|_1\) that penalizes only the positive coordinates and leaves negative ones untouched.
See Also
SumNegative : Mirror image under \(x \mapsto -x\). NormL1 : Two-sided counterpart \(\lambda \|x\|_1\).
Notes
Proximal operator. Element-wise separable; per coordinate,
which collapses to \(\operatorname{prox}_{\gamma f}(v) = v - \mathrm{satlin}(v;\, 0,\, \gamma)\).
Verification lowering. prox_sumpositive posts a single
SaturatedLinear clip to \([0, \gamma]\) and subtracts it from the input.
Source code in fomtools/proxable_functions/sum_positive.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \sum_i \max(0, x_i)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/sum_positive.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
grad
¶
grad(x: ndarray) -> ndarray
Compute a subgradient of \(f\) at x.
Per coordinate,
where \(0 \in [0, 1]\) is the canonical choice at the kink \(x_i = 0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the subgradient. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A subgradient \(g \in \partial f(x)\). |
Source code in fomtools/proxable_functions/sum_positive.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Uses the closed form
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input point. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Source code in fomtools/proxable_functions/sum_positive.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
TotalVariation1D
¶
Bases: ProxableFunction
1-D total variation.
Represents
where \(D\) is the first-difference operator (see diff_matrix). Convex
and piecewise linear.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambd
|
float or LinearExpression
|
Weight \(\lambda \ge 0\), or a dim-1 |
1.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
See Also
NormL1 : The case \(D = I\).
Notes
Proximal operator. The 1-D fused-lasso signal approximator,
For a signal of length \(n < 2\), \(f \equiv 0\) and the prox is the identity.
Verification lowering. prox_totalvariation1d encodes the KKT system
with complementarity constraints. All variable bounds are derived from the
data, so no dual_ub is needed.
Source code in fomtools/proxable_functions/total_variation_1d.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
eval
¶
eval(x: ndarray) -> float
Evaluate \(f(x) = \lambda \sum_i |x_{i+1} - x_i|\).
A LinearExpression lambd uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point at which to evaluate the function. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The function value \(f(x)\). |
Source code in fomtools/proxable_functions/total_variation_1d.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
prox
¶
prox(arg: ndarray, gamma: float = 1.0) -> ndarray
Compute \(\operatorname{prox}_{\gamma f}(\text{arg})\).
Solved numerically with CVXPY (Clarabel) as an independent reference; a
LinearExpression lambd uses its constant value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
ndarray
|
Input signal. |
required |
gamma
|
float
|
Step size \(\gamma > 0\). |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The proximal point \(\operatorname{prox}_{\gamma f}(\text{arg})\). |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If |
Source code in fomtools/proxable_functions/total_variation_1d.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Sets and projections¶
Use vp.project(set_instance, arg).
Set
¶
Base class for convex sets onto which we can project.
A Set is the user-facing, math-named counterpart of an indicator
ProxableFunction: for a
closed convex set \(C\), the Euclidean projection onto \(C\) is exactly the proximal
operator of its indicator \(I_C\),
Each concrete set therefore only needs to know its indicator
(indicator); projection and membership reuse the indicator's existing
numerical prox/eval. The verifier-level fomtools.verifier.Verifier.project
is a thin wrapper that calls prox on this indicator, so Set adds no
new lowering logic.
Subclasses form an inheritance tree mirroring the mathematics (e.g.
NonNegative is a Polyhedron),
but each concrete set overrides indicator to return its most specific
indicator so the efficient backend lowering is preserved.
Source code in fomtools/sets/set.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
contains
¶
contains(x: ndarray, tol: float = 1e-06, rtol: float = 1e-05) -> bool
Return True if x lies in the set (within tolerance).
Tested via projection idempotence: for a closed convex set,
\(x \in C \iff \Pi_C(x) = x\). This relies only on the indicator's prox
(which every indicator implements), so it works uniformly across all sets.
The comparison uses numpy.allclose semantics,
\(\lVert \Pi_C(x) - x \rVert \le \text{tol} + \text{rtol}\,\lvert x \rvert\)
(elementwise): tol is the absolute tolerance and rtol adds a relative,
scale-aware slack so large-magnitude points are not held to an unrealistic
absolute bound. Pass rtol=0.0 for a pure absolute check. For cvxpy-solved
sets (Simplex, L1Ball, Polyhedron) the round-trip inherits the solver's
precision (~PROX_ATOL), so tol may need to be loosened accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Point to test. |
required |
tol
|
float
|
Absolute tolerance. |
1e-6
|
rtol
|
float
|
Relative tolerance (scale-aware term). |
1e-5
|
Notes
Calls project, which constructs a fresh indicator each call; for tight
membership-checking loops reuse a single indicator (see project).
Source code in fomtools/sets/set.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
indicator
¶
indicator() -> ProxableFunction
Return the indicator ProxableFunction whose prox is the Euclidean
projection onto this set.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised by the base class; concrete sets must implement this. |
Source code in fomtools/sets/set.py
46 47 48 49 50 51 52 53 54 55 56 | |
project
¶
project(x: ndarray) -> ndarray
Euclidean projection of the point x onto this set, \(\Pi_C(x)\).
Delegates to the indicator's numerical prox (projection is
prox of the indicator).
Notes
A fresh indicator object is constructed on each call (construction is cheap —
it only stores the set's parameters). If you are projecting/checking membership
in a tight loop, build the indicator once and reuse it:
ind = my_set.indicator(); ind.prox(x1); ind.prox(x2); ....
Source code in fomtools/sets/set.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
Polyhedron
¶
Bases: Set
The polyhedron \(\{x : A x \le b\}\).
Backed by IndPolyhedral,
whose prox solves the projection via a KKT system. dual_ub bounds the
inequality multipliers and is required by the MIP/SDP lowering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Constraint matrix |
None
|
b
|
ndarray or LinearExpression
|
Right-hand side (dim |
None
|
dual_ub
|
float
|
Upper bound on the inequality dual variables (needed by the backend). |
None
|
Source code in fomtools/sets/polyhedron.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
HalfSpace
¶
Bases: Polyhedron
The half-space \(\{x : a^\top x \le b\}\) (a single linear inequality).
A Polyhedron with a single row: A = a (shape (1, n)) and RHS vector
b = [b]. The inherited self.A/self.b therefore carry the usual polyhedral
meaning (self.b is the length-1 RHS vector, not a bare scalar); the scalar normal
is kept on self.a. Backed by
IndHalfSpace, which projects in
closed form (no dual bound needed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Normal vector (nonzero). |
required |
b
|
float
|
Offset (the scalar right-hand side of |
required |
Source code in fomtools/sets/polyhedron.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
Simplex
¶
Bases: Polyhedron
The scaled probability simplex \(\{x : x \ge 0,\ \mathbf{1}^\top x = a\}\).
Backed by IndSimplex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float or LinearExpression
|
Total mass ( |
1.0
|
Source code in fomtools/sets/polyhedron.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Box
¶
Bases: Polyhedron
The axis-aligned box \(\{x : l \le x \le u\}\) (element-wise).
A Polyhedron specialization that projects by
element-wise clipping; backed by
IndBox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l
|
float, np.ndarray, or LinearExpression
|
Lower and upper bounds (scalars broadcast to the dimension of the input). |
required |
u
|
float, np.ndarray, or LinearExpression
|
Lower and upper bounds (scalars broadcast to the dimension of the input). |
required |
Source code in fomtools/sets/box.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
NonNegative
¶
Bases: Box
The non-negative orthant \(\{x : x \ge 0\}\), i.e. the box \([0, +\infty)\).
A parameterless Box specialization (l = 0, u = +\infty); backed by
IndNonNegative, which projects
via a single ReLU (more efficient than the generic box/polyhedron path). The box
bounds are stored for the inherited Box/Polyhedron contract but are
not used by indicator.
Source code in fomtools/sets/box.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
NonPositive
¶
Bases: Box
The non-positive orthant \(\{x : x \le 0\}\), i.e. the box \((-\infty, 0]\).
A parameterless Box specialization (l = -\infty, u = 0); backed by
IndNonPositive. The box bounds
are stored for the inherited contract but are not used by indicator.
Source code in fomtools/sets/box.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Point
¶
Bases: Box
The singleton \(\{p\}\) (a degenerate box with \(l = u = p\)).
Backed by IndPoint; projection
is the constant map \(x \mapsto p\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float or ndarray
|
The single point (scalars broadcast to the dimension of the input). |
required |
Source code in fomtools/sets/box.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
L1Ball
¶
Bases: Set
The \(\ell_1\)-ball \(\{x : \lVert x \rVert_1 \le r\}\).
Backed by IndBallL1, whose
projection lifts auxiliary variables and solves a KKT system. dual_ub bounds
the inequality multipliers for the MIP/SDP lowering. Sits directly under
Set (the lifting does not fit the plain Ax <= b mold).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float or LinearExpression
|
Radius ( |
required |
dual_ub
|
float
|
Upper bound on the inequality dual variables (needed by the backend). |
None
|
Source code in fomtools/sets/ball.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
LinfBall
¶
Bases: Box
The \(\ell_\infty\)-ball \(\{x : \lVert x \rVert_\infty \le r\}\), i.e. the box \([-r, r]\).
A Box specialization; backed by
IndBallLinf, which projects
by clipping to \([-r, r]\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius ( |
required |
Source code in fomtools/sets/ball.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
AffineSubspace
¶
Bases: Set
The affine subspace \(\{x : A x = b\}\).
Backed by IndAffine, which
projects onto the equality set in closed form. Named AffineSubspace to avoid
colliding with the Affine step. Sits directly
under Set (it is an equality, not an Ax <= b
inequality polyhedron).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Constraint matrix |
required |
b
|
float, np.ndarray, or LinearExpression
|
Right-hand side (dim |
required |
Source code in fomtools/sets/affine_subspace.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |