Refer 3b1b
Metric spaces, normed vector spaces and inner product spaces are needed to anaylse some machine learning algorithms in-depth.
Metrics are generalisation of the notion of distance, norms are a generealisation of the notion of length and inner products are a generalisation of the dot product.

Metric space

Generalisation of the notion of distance from Euclidean space.
A metric on a set S is a function 𝑑:𝑆×𝑆→ℝ
such that for all π‘₯,𝑦,π‘§βˆˆπ‘†

  1. 𝑑(π‘₯,𝑦)β‰₯0and𝑑(π‘₯,𝑦)=0iffπ‘₯=𝑦 (non negative distance, distance from a point to itself is zero)
  2. 𝑑(π‘₯,𝑦)=𝑑(𝑦,π‘₯) (distance should be the same, symmetry)
  3. 𝑑(π‘₯,𝑧)≀𝑑(π‘₯,𝑦)+𝑑(𝑦,𝑧) (triangle inequality)
    ex. Take π‘†βŠ†β„ and define 𝑑(π‘₯,𝑦)=|π‘₯βˆ’π‘¦|; then (𝑆,𝑑) forms a metric space.
    For a metric, 𝑑(π‘₯,𝑦) is interpreted as the distance between x and y.

Norm

A norm on a real vector space (in context of machine learning) 𝑉 is a function β€–.β€–:𝑉→ℝ such that for all πœ†βˆˆβ„ and 𝒙,π’šβˆˆπ‘‰:

  1. ‖𝒙‖β‰₯0and‖𝒙‖=0iff𝒙=0
  2. β€–πœ†π’™β€–=|πœ†|‖𝒙‖
  3. ‖𝒙+π’šβ€–β‰€β€–π’™β€–+β€–π’šβ€–
    Here (𝑉,β€–.β€–) is called a normed vector space.

Every normed space is a metric space, but the converse is not true.

Some special norms; remember that 𝒙 is a vector (π‘₯1,π‘₯2,…,π‘₯𝑛):

  1. The Manhattan norm on ℝ𝑛 is defined for π’™βˆˆβ„π‘› as: ‖𝒙‖1β‰”βˆ‘π‘›π‘–=1|π‘₯𝑖| where |.| is the absolute value. It’s also called the 𝑙1 norm.
  2. The Euclidean norm of π’™βˆˆβ„π‘› is defined as: ‖𝒙‖2β‰”βˆšβˆ‘π‘›π‘–=1π‘₯2𝑖=βˆšπ’™π‘‡π’™ it computes the Euclidean distance of 𝒙 from the origin. It’s also called the 𝑙2 norm.
  3. The 𝑙𝑝 norm is calculated as: ‖𝒙‖𝑝≔(βˆ‘π‘›π‘–=1π‘₯𝑝𝑖)1𝑝 it’s also called the p-norm.
  4. The β€œmax norm” is calculated as: β€–π’™β€–βˆžβ‰”max(|π‘₯1|,|π‘₯2|,…,|π‘₯𝑛|)
  5. The "𝑙0" norm is defined as the number of non zero elements of 𝒙. Strictly speaking, it’s not a norm because it doesn’t satisfy the second property, but it’s still very useful in compression sensing.
    • ex. 𝒙=(1,2,3,0,0,4,6) then ‖𝒙‖0=5 as there are five non zero elements in the vector.

All norms are part of the convex set.

Convex function: A function 𝑓:π‘†βŠ†β„π‘› is said to be convex if for π‘₯1,π‘₯2βˆˆπ‘†, we have:

𝑓(πœ†π‘₯1+(1βˆ’πœ†)π‘₯2)β‰€πœ†π‘“(π‘₯1)+(1βˆ’πœ†)𝑓(π‘₯2)

where 0β‰€πœ†β‰€1.
In plain English, a function is said to be convex if the line segment between any two distinct points on the graph of the function lies above or on graph of the function between the two points.

Convex set: A set is said to be convex if the line joining any two points of the set lies entirely in the set 𝑆.
A convex set:

A non-convex set (note how the line joining the two points does not lie entirely in the set):

All norms (𝑙1,𝑙2,etc.) are a part of a convex set.

Inner product spaces

An inner product on a real vector space V is a function:
⟨.,.⟩:𝑉×𝑉→ℝ
satisfying for all 𝒙,π’š,π’›βˆˆπ‘‰ and πœ†βˆˆβ„

  1. βŸ¨π’™,π’™βŸ©β‰₯0andβŸ¨π’™,π’™βŸ©=0iffπ‘₯=0
  2. βŸ¨π’™+π’š,π’›βŸ©=βŸ¨π’™,π’›βŸ©+βŸ¨π’š,π’›βŸ©andβŸ¨πœ†π’™,π’šβŸ©=πœ†βŸ¨π’™,π’šβŸ©
  3. βŸ¨π’™,π’šβŸ©=βŸ¨π’š,π’™βŸ©
    A vector space together with an inner product is called an inner product space.
    ex. Let 𝑉=ℝ𝑛(ℝ). Now consider
𝒙=(π‘₯1,π‘₯2,…,π‘₯𝑛)π’š=(𝑦1,𝑦2,…,𝑦𝑛)

here it’s just the definition of the dot product, a particular type of inner product.

ex. consider 𝑉=ℝ2. If we define
βŸ¨π’™,π’šβŸ©β‰”π‘₯1𝑦1βˆ’(π‘₯1𝑦2+π‘₯2𝑦1)+2π‘₯2𝑦2
then ⟨.,.⟩ is an inner product but different from the dot product.

NOTE

The pair (𝑉,⟨.,.⟩) is called an inner product space or (real) vector space with inner product. If we use the dot product instead, (𝑉,⟨.,.⟩) is called a Euclidean vector space.

The particular type of inner product, the scalar/dot product in ℝ𝑛 is given by π’™π‘‡π’š=βˆ‘π‘›π‘–=1π‘₯𝑖𝑦𝑖
Any inner product induces a norm β€–π’™β€–β‰”βˆš(βŸ¨π’™,π’™βŸ©) in a natural way, such that we can compute the lengths of vectors using the inner product. The Manhattan norm is an example of a norm without a corresponding inner product.

For an inner product vector space (𝑉,⟨.,.⟩) the induced norm β€–.β€– satisfies the Cauchy-Schwarz inequality |βŸ¨π’™,π’šβŸ©|β‰€β€–π’™β€–β€–π’šβ€–
We have already seen what the metric means, but in an inner product space,
𝑑(𝒙,π’š)β‰”β€–π’™βˆ’π’šβ€–=√(βŸ¨π’™βˆ’π’š,π’™βˆ’π’šβŸ©)
is called the distance between 𝒙 and π’š if x and y are two vectors in V. If we use the dot product as the inner product, this is called the Euclidean distance.

Angles

When we remove the absolute value bars from the Cauchy-Schwarz inequality, we get the equation

βˆ’β€–π’™β€–β€–π’šβ€–β‰€βŸ¨π’™,π’šβŸ©β‰€β€–π’™β€–β€–π’šβ€–

Dividing this we get

βˆ’1β‰€βŸ¨π’™,π’šβŸ©β€–π’™β€–β€–π’šβ€–β‰€1

There exists a unique πœ”βˆˆ[0,πœ‹] with cosπœ”=βŸ¨π’™,π’šβŸ©β€–π’™β€–β€–π’šβ€–
And the number πœ” is the angle between the vectors.
We already know that if the inner product is zero, the angle between them is 90 degrees.