p-norm¶
-
class
cvxpy.
pnorm
(x, p=2, axis=None, max_denom=1024)[source]¶ The vector p-norm.
If given a matrix variable,
pnorm
will treat it as a vector, and compute the p-norm of the concatenated columns.For p≥1, the p-norm is given by
‖x‖p=(∑i|xi|p)1/p,with domain x∈Rn.
For p<1, p≠0, the p-norm is given by
‖x‖p=(∑ixpi)1/p,with domain x∈Rn+.
- Note that the “p-norm” is actually a norm only when p≥1 or p=+∞. For these cases, it is convex.
- The expression is not defined when p=0.
- Otherwise, when p<1, the expression is concave, but it is not a true norm.
Note
Generally,
p
cannot be represented exactly, so a rational, i.e., fractional, approximation must be made.Internally,
pnorm
computes a rational approximation to the reciprocal 1/p with a denominator up tomax_denom
. The resulting approximation can be found through the attributepnorm.p
. The approximation error is given by the attributepnorm.approx_error
. Increasingmax_denom
can give better approximations.When
p
is anint
orFraction
object, the approximation is usually exact.Parameters: x : cvxpy.Variable
The value to take the norm of.
p : int, float, Fraction, or string
If
p
is anint
,float
, orFraction
then we must have p≥1.The only other valid inputs are
numpy.inf
,float('inf')
,float('Inf')
, or the strings"inf"
or"inf"
, all of which are equivalent and give the infinity norm.max_denom : int
The maximum denominator considered in forming a rational approximation for
p
.axis : 0 or 1
The axis to apply the norm to.
Returns: Expression :
An Expression representing the norm.
-
static
graph_implementation
(arg_objs, shape, data=None)[source]¶ Reduces the atom to an affine expression and list of constraints.
Parameters: arg_objs : list
LinExpr for each argument.
shape : tuple
The shape of the resulting expression.
data : :
Additional data required by the atom.
Returns: tuple :
(LinOp for objective, list of constraints)
Notes
Implementation notes.
For general p≥1, the inequality ‖x‖p≤t is equivalent to the following convex inequalities:
|xi|≤r1/pit1−1/p∑iri=t.These inequalities happen to also be correct for p=+∞, if we interpret 1/∞ as 0.
For general 0<p<1, the inequality ‖x‖p≥t is equivalent to the following convex inequalities:
ri≤xpit1−p∑iri=t.For general p<0, the inequality ‖x‖p≥t is equivalent to the following convex inequalities:
t≤x−p/(1−p)ir1/(1−p)i∑iri=t.
Although the inequalities above are correct, for a few special cases, we can represent the p-norm more efficiently and with fewer variables and inequalities.
For p=1, we use the representation
xi≤ri−xi≤ri∑iri=tFor p=∞, we use the representation
xi≤t−xi≤tNote that we don’t need the r variable or the sum inequality.
For p=2, we use the natural second-order cone representation
‖x‖2≤tNote that we could have used the set of inequalities given above if we wanted an alternate decomposition of a large second-order cone into into several smaller inequalities.