Vectors typically provide an (approximate) description of a physical (or some other) object. One of the main question is how accurate the approximation is (1%, 10%). What is an acceptable representation, of course, depends on the particular applications. For example:
Norm is a qualitative measure of smallness of a vector and is typically denoted as $\Vert x \Vert$ The norm should satisfy certain properties:
The distance between two vectors is then defined as $$ d(x, y) = \Vert x - y \Vert. $$
Euclidean norm, or $2$-norm, is a subclass of an important class of $p$-norms: $$ \Vert x \Vert_p = \Big(\sum_{i=1}^n |x_i|^p\Big)^p. $$ There are two very important special cases:
We will give examples where Manhattan is very important: it all relates to the compressed sensing methods that emerged in the mid-2005 as one of the most popular research topics.
In [9]:
import numpy as np
n = 100
a = np.ones(n)
b = a + 1e-3 * np.random.randn(n)
print 'Relative error:', np.linalg.norm(a - b) / np.linalg.norm(b)
All norms are equivalent in the sense that $$ C_1 \Vert x \Vert_* \leq \Vert x \Vert_{**} \leq C_2 \Vert x \Vert_* $$ for some constants $C_1(n), C_2(n)$ for any pairs of norms $\Vert \cdot \Vert_*$ and $\Vert \cdot \Vert_{**}$. You will have some problems on that in your homework! The equivalence of the norms basically means that if the vector is small in one norm, it is small in another norm. However, the constants can be large.
In [45]:
%matplotlib inline
import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
p = 3 #Which norm do we use
M = 100000 #Number of sampling points
a = np.random.randn(M, 2)
b = []
for i in xrange(M):
if np.linalg.norm(a[i, :], p) <= 1:
b.append(a[i, :])
b = np.array(b)
plt.fill(b[:, 0], b[:, 1])
plt.axis('equal')
Out[45]:
$L_1$ norm, as it was discovered quite recently, plays an important role in compressed sensing. The simplest formulation is as follows:
The solution is obviously non-unique, so the natural approach is to find the solution that is minimal in the certain sense: $$ \Vert x \Vert \rightarrow \min, \quad \mbox{subject to } Ax = f$$
Typical choice of $\Vert x \Vert = \Vert x \Vert_2$ leads to the linear least squares problem (and has been used for ages).
The choice $\Vert x \Vert = \Vert x \Vert_1$ leads to the compressed sensing and what happens, it typically yields the sparsest solution.
A short demo
It is worth to note that formally $\Vert x \Vert_0$ is the number of non-zero elements in $x$, so $\Vert x \Vert_1$ is an approximation to the number of non-zeros.
How to measure distances between matrices? A trivial answer is that there is no big differences between matrices and vectors, and here comes the Frobenius norm of the matrix: $$ \Vert A \Vert_F = \Big(\sum_{i=1}^n \sum_{j=1}^m |a_{ij}|^2\Big)^{1/2} $$ There is a more general definition though:
$\Vert \cdot \Vert$ is called a matrix norm if it is a vector norm on the linear space of $n \times m$ matrices, and it also is consistent with the matrix-by-matrix product, i.e. $$\Vert A B \Vert \leq \Vert A \Vert \Vert B \Vert$$
The multiplicative property is needed in many places, for example in the estimates for the error of solution of linear systems (we will cover this subject later).
Can you think of some matrix norms?
The most important class of the norms is the class of operator norms. Mathematically, they are defined as $$ \Vert A \Vert_* = \sup_{x \ne 0} \frac{\Vert A x \Vert_*}{\Vert x \Vert_*}, $$ where $\Vert \cdot \Vert_*$ is a vector norm. It is not diffcult to show that operator norm is a matrix norm. Among all operator norms $p$-norms are used, where $p$-norm is used as the vector norm. Among all $p$-norms three norms are the most common ones:
Note that Frobenius norm is not an operator one.
Spectral norm, $\Vert A \Vert_2$ is undoubtedly the most used matrix norm. It can not be computed directly from the entries using a simple formula, like the Euclidean norm, however, there are efficient algorithm to compute it. It is directly related to the singular value decomposition (SVD) of the matrix. It holds $$ \Vert A \Vert_2 = \sigma_1(A) $$ where $\sigma_1(A)$ is the largest singular value of the matrix $A$. We will soon learn all about this. Meanwhile, we can already compute the norm in Python.
In [25]:
import numpy as np
n = 100
a = np.random.randn(n, n) #Random n x n matrix
s1 = np.linalg.norm(a, 2) #Spectral
s2 = np.linalg.norm(a, 'fro') #Frobenius
s3 = np.linalg.norm(a, 1) #1-norm
s4 = np.linalg.norm(a, np.inf) #It was trick to find the infinity
print 'Spectral:', s1, 'Frobenius:', s2, '1-norm', s3, 'infinity', s4
In [1]:
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()
Out[1]: