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 \geq 1\), the p-norm is given by

\[\|x\|_p = \left(\sum_i |x_i|^p \right)^{1/p},\]

with domain \(x \in \mathbf{R}^n\).

For \(p < 1,\ p \neq 0\), the p-norm is given by

\[\|x\|_p = \left(\sum_i x_i^p \right)^{1/p},\]

with domain \(x \in \mathbf{R}^n_+\).

  • Note that the “p-norm” is actually a norm only when \(p \geq 1\) or \(p = +\infty\). 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 \(p \geq 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 \geq 1\), the inequality \(\|x\|_p \leq t\) is equivalent to the following convex inequalities:

    \[\begin{split}|x_i| &\leq r_i^{1/p} t^{1 - 1/p}\\ \sum_i r_i &= t.\end{split}\]

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

  • For general \(0 < p < 1\), the inequality \(\|x\|_p \geq t\) is equivalent to the following convex inequalities:

    \[\begin{split}r_i &\leq x_i^{p} t^{1 - p}\\ \sum_i r_i &= t.\end{split}\]
  • For general \(p < 0\), the inequality \(\|x\|_p \geq t\) is equivalent to the following convex inequalities:

    \[\begin{split}t &\leq x_i^{-p/(1-p)} r_i^{1/(1 - p)}\\ \sum_i r_i &= t.\end{split}\]

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

    \[\begin{split}x_i &\leq r_i\\ -x_i &\leq r_i\\ \sum_i r_i &= t\end{split}\]
  • For \(p = \infty\), we use the representation

    \[\begin{split}x_i &\leq t\\ -x_i &\leq t\end{split}\]

    Note 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 \leq t\]

    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.