A norm is a property of a vector that binds the vector to its quantifiable length. Simply put, we can say that a norm allows us to think of a vector in terms of distance i.e. how long it is.
Norms are highly useful in fields such as physics, engineering, and computational mathematics.
We can think of a norm as a function that takes an object as input and returns a non-negative scalar value as its output. In the context of vector space, the norm is used to measure the size of a vector.
There is a diverse range of norms that exists in the mathematical world. There are different types of norms because they capture the varying aspects of the mathematical objects being measured. The choice we ultimately take depends on our individual needs and the application at hand.
Let's say we have a two-dimensional space. Then the norm of a
Today we will be discussing a type of norm called nuclear norm in our answer.
A nuclear norm of
Before we fully explore nuclear norms, let's understand singular values first. Suppose we have a matrix
The eigenvalues must be sorted in a decreasing order before taking their square roots. These values are crucial to demonstrating the magnitude of a vector.
Note: Singular values always belong to real numbers.
Now that we understand singular values, we can think of the nuclear norm as the function of taking the sum of all these individual values.
It can be mathematically expressed as:
Therefore, the sum of each singular value is added to the nuclear norm variable.
import numpy as npdef nuclearNorm(matrix):singularVals = np.linalg.svd(matrix, compute_uv = False)nuclearNormVal = np.sum(singularVals)return nuclearNormValmatrix = np.array([[9, 5, 1], [2, 9, 3], [7, 6, 9]])norm = nuclearNorm(matrix)print('The nuclear norm of' , matrix, 'is = ', norm)
Line 1: Since we will be storing the values of the matrix in an array, we have to import the numpy
library which makes applying operations on arrays faster. The alias name for numpy
is conventionally taken as np
.
Line 3: We define a function called nuclearNorm
that takes in a matrix as a parameter and returns its nuclear norm value
Lines 4 – 5: np.linalg.svd
is a function in the linear algebra module of numpy that computes singular value decomposition on the values of the matrix. We pass false to the compute_uv
parameter since we do not require the left and right singular matrices. Since the nuclear norm is the sum of the singular values, we will simply call np.sum(singularVals)
to save the value in nuclearNormVal
.
Line 6: We return the calculated nuclearNormVal
value.
Line 8: We define a 3 x 3 matrix
with some starting values and save it in a 2D array.
Line 9: We call the nuclearNorm
method on our matrix and finally print the results.
from numpy import linalg as LNGimport numpy as npmatrix = np.array([[9, 5, 1], [2, 9, 3], [7, 6, 9]])print(LNG.norm(matrix, ord = "nuc"))
For the sake of simplicity, let's use the same matrix we defined above.
We use the simple norm function provided by the linalg
(linear algebra) module and pass a parameter ord
the value of nuc
.
ord
refers to the order of the norm.
value of nuc
means we want a norm of the order nuclear norm.
Nuclear norms can be pretty helpful in finding corrupted elements in a partially observed matrix.
This is a technique that separates a matrix into low-rank and sparse components. We can utilize the nuclear norm here to encourage low ranks and the sparse components can be used to find the outliers in data. For instance, video surveillance and image denoising.
Nuclear norm regularization is a technique that is used in graph analysis problems. We can solve problems like graph completion and link prediction as well as finding missing links.
How well do you know norms?
Why is a norm always greater or equal to 0?
Free Resources