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 p1, the p-norm is given by

xp=(i|xi|p)1/p,

with domain xRn.

For p<1, p0, the p-norm is given by

xp=(ixpi)1/p,

with domain xRn+.

  • Note that the “p-norm” is actually a norm only when p1 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 to max_denom. The resulting approximation can be found through the attribute pnorm.p. The approximation error is given by the attribute pnorm.approx_error. Increasing max_denom can give better approximations.

When p is an int or Fraction 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 an int, float, or Fraction then we must have p1.

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 p1, the inequality xpt is equivalent to the following convex inequalities:

    |xi|r1/pit11/piri=t.

    These inequalities happen to also be correct for p=+, if we interpret 1/ as 0.

  • For general 0<p<1, the inequality xpt is equivalent to the following convex inequalities:

    rixpit1piri=t.
  • For general p<0, the inequality xpt is equivalent to the following convex inequalities:

    txp/(1p)ir1/(1p)iiri=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

    xirixiriiri=t
  • For p=, we use the representation

    xitxit

    Note that we don’t need the r variable or the sum inequality.

  • For p=2, we use the natural second-order cone representation

    x2t

    Note 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.