8 minute read

Kernel in Linear Algebra: Part 1Permalink

在 Chapter 6, Digest of Essence of Linear Algebra 有讲:

The null space of matrix A is the set of all vectors v such that Av=0

这里我们用函数的观点展开讲一讲。

Wikipedia: Kernel (linear algebra): The kernel (also known as null space or nullspace) of a linear map (i.e. linear transformation) L:VW between two vector spaces V and W, is the set of all elements v of V for which L(v)=0, where 0 denotes the zero vector in W. That is, in set-builder notation,

ker(L)={vVL(v)=0}

A linear map is essentially a function,so we can define:

  • L(v) is the image of v in W (注意有 L(v)W)
  • The image of L is im(L)={L(v)vV} (所以 im(L)W 的子空间)

Two elements of V have the same image in W if and only if their difference lies in the kernel of L:

L(v1)=L(v2)L(v1v2)=0

The image of L is isomorphic to the quotient of V by the kernel:

im(L)V/ker(L)
  • In linear algebra, the quotient ([ˈkwəʊʃənt], 商) of a vector space V by a subspace N is a vector space obtained by “collapsing” N to zero. The space obtained is called a quotient space and is denoted V/N (read V mod N or V by N).
  • Morphism refers to a structure-preserving map from one mathematical structure to another.
    • In universal algebra and in model theory, a structure consists of a set along with a collection of finitary operations (an operation that takes a finite number of input values) and relations that are defined on it.
    • Structure 的大类有 groups (群), rings (环), fields (域,比如实数域) and vector spaces
    • 比如 Vector space 的定义就是 vector 的集合以及定义在 vector 上的 add、multiply 的操作
    • structure-preserving 的意思就是你的 mapping 不能跳出 structure 的范围
  • Isomorphism is a morphism that can be reversed by an inverse morphism

This implies the rank–nullity theorem:

dim(ker(L))+dim(im(L))=dim(V)

where, by rank we mean the dimension of im(L), and by nullity that of ker(L).

  • vector space 的 demension 即 basis vector 的个数

举个例子:

  • V={[xy]x2+y2=1}
  • W=R
  • L(v)=Av=[10][xy]=x
    • 相当于把 x2+y2=1 这个圆压扁到 x-axis
  • ker(L)={vVv=[0y]},即 y-axis 上的所有 vector
  • im(L)={x1x1}
  • dim(ker(L))=1,dim(im(L))=1,dim(V)=2

Inner Product SpacePermalink

Given a vector space V on a field K, an inner product between the vectors v and w in V, which we denote by the symbol v,w, is any operation of V×VK such that the following three properties are satisfied for every u,v,wV and for every a,bK:

  • (Positivity or Positive Definiteness):
    • v,v0
    • v,v=0v=0
  • (Linearity): av+bv,w=au,w+bv,w
  • (Conjugate Symmetry): u,v=v,u
    • conjugate 这个词的意义有很多,比如:
      • xyx+y 的 conjugate
      • abia+bi 的 conjugate
      • F=Y1GYG 的 conjugate

很多地方把 inner product 这个 operation 写作 ,,它本质就是个 function f(,)=,。另外一个很烦人的地方是,inner product 你得结合语境去判断它到底是指的 v,w 这个具体值还是 , 这个 operation。

从 inner product 的定义来看,dot product 是 inner product 的一种,即 dot product 可以通过 inner product 定义:v,w=vw

我们知道 Vector space 的定义就是 vector 的集合以及定义在 vector 上的 add、multiply 的操作;如果我们在 vector space 的基础上再加上一个 , 操作,我们就可以得到一个 inner product space

Two vectors of an inner product space are orthogonal if and only if their inner product is zero.

If V is an inner product space, and W is a subspace of V, we define the orthogonal complement of W, which we denote by W, as the set of all the vectors of V that are orthogonal to every vector of W:

W={vVv,w=0,wW}

Kernel in Linear Algebra: Part 2Permalink

Let A:VW be a linear transformation of finite-dimensional vector spaces. Then

im(AT)=(ker(A))

Proof:

注意:

  1. 如果有 A:VW,那么 AT 就是个 WV 的 linear transformation
  2. 这里 inner product 其实就是 dot product 了
  3. 这个其实可以扩展到任意的 linear operator A,只是不用 AT 而是 adjoint A 来表示逆运算

If vim(AT)V, then v=ATw for some wW. Now given uker(A), then Au=0. Therefore,

u,v=uATw=AuAATw=0w=0

That is v(ker(A)). 后续证明暂略。感觉直接证 adjoint 更简单……

HyperplanePermalink

Let Rn be an n-dimension vector space and a=(a1,a2,,an). {ai} are scalars not all equal to 0. Then the set S={xRnax=b}, where b is a constant, is a subspace of Rn called a hyperplane.

注意 a=(a1,a2,,an) 这个变换并没有 preserve 原点,所以它不是一个严格的 linear transformation 而是一个 affine transformation。然后 hyperplane 可以看作是这个 affine transformation A(x)=axb 的 kernel。

Hyperplane 的 normal vector 可以由 transformation 的 gradient 给出:n=A(x),刚好有 A(x)=a,所以 hyperplane 的 normal vector n=a

Normal vector 的性质是它垂直于 hyperplane。

对任意 vector x,当 hyperplane 经过原点时,x 到 hyperplane 的距离等于它到 normal vector 的投影的绝对值,所以有:

D(x)=|ax|a||

若 hyperplane 不经过原点,我们取 hyperplane 上的任意一点 p,原点到 p 的向量为 op。我们把 x 写作 ox,所以 px=oxop 到 normal vector 的投影的绝对值才是 x 到 hyperplane 的距离。又因为 p 在 hyperplane 上,所以 aop=b,所以:

D(x)=|a(oxop)|a||=|axb|a||

注意这里有一个很重要的思想:当 hyperplane 过原点时,我们很容易错误地认为 hyperplane 是 hyperplane 上所有 vector 的集合;从 hyperplane 不经过原点的情况来看,正确的理解应该是:hyperplane 是所有从原点出发、落到 hyperplane 上的 vector 的终点的集合。扩展开来,所谓 “vector 张成的空间”,指的就是 “所有 vector 的终点所构成的空间”

造成这个误解的原因在于我混淆了 hyperplane 在几何学和集合论中的意义:

  • 几何学中,hyperplane 是个平面(假设 3-D 情况下)
  • 集合论中,hyperplane 是 vector 的集合(vector space)
  • 我们说 vector vH, where H is a hyperplane,并不是说在几何学中,整个 vector v 都在 H 这个平面之中,而是说 v 从原点出发,终点会落在 H 这个平面之中

基于这个思想,我们还应该认识到:

  1. (几何学)Hyperplane 平面上没有 vector,只有 vector 的终点;只是当 hyperplane 平面经过原点时,它恰巧包含 vector
  2. (几何学)从原点出发,终点落到 hyperplane 平面上的 vector x 才满足 A(x)=axb=0,并不是 hyperplane 平面上的 vector 满足 A(x)=axb=0
    • (集合论)Hyperplane 这个 vector space 内的所有 vector x 满足 A(x)=axb=0
  3. (几何学)Normal vector 垂直于 hyperplane 平面,并不是说 Normal vector 垂直于 hyperplane 平面上的所有 vector
    • (集合论)Normal vector 也并不垂直于 hyperplane 这个 vector space 内的所有 vector(除非 hyperplane 经过原点)
  4. (几何学)我们可以把 原点 + hyperplane 平面 的整体结构想象成一个底面积无限大的圆锥:
    • 顶点是原点
    • 底是 hyperplane 平面
    • 顶点到底面任意一点的连线都是 vector
    • 顶点到底面几何中心的连线是一个 normal vector
      • 这个 normal vector 的长度,即圆锥的高是 |b|a||
      • 这个 normal vector 不一定是 a,但一定与 a 共线
        • 换言之 a 不一定落在 hyperplane 平面上
        • 再换言之 a 相当于是从原点出发的一个旋转臂,它的方向即圆锥高的方向
      • 已知长度和方向,我们可以得知这个 normal vector n=|b|a||a|a|=|b|a|2|a
    • (集合论)所有顶点到底面的连线的集合构成 hyperplane 的 vector space

Affine transformation A(x)=axb 的几何意义是:

  1. a 为 x-axis,将空间内所有 x 压缩到一维,即压缩到 a 这个 x-axis 上
  2. x 压缩后位于 x=ax 位置
  3. 将所有压缩后的 x 左移 b
    • 此时位于 x=0 位置的所有 x 反压缩后即是 hyperplane vector space
    • 此时原点位于 x=b 位置
    • 这个长度为 |b| 的移动距离反压缩后即是圆锥的高 |b|a||

SVMPermalink

回头看这个 SVM 的最简单的 hard-margin 就很好懂了

注意这个 margin 是设置成常数 1 还是符号 c 并没有太大区别,因为最终都是可以通过 |w| 来调节的。

最终的 optimization problem:

“Minimize |w| subject to yi(wxib)1, for i=1,,n”.

这个图是 linear-separable (或者 precisely,hyperplane-separable) 的情况,如果是 non-linear-separable 的情况该怎么办呢?

用 kernel method

Kernel Method / Kernel FunctionPermalink

我们先看 Kernel Methods for Pattern Analysis 的定义:

Definition 2.8 [Kernel function] A kernel is a function κ that for all x,zX satisfies

κ(x,z)=ϕ(x),ϕ(z)

where ϕ is a mapping from X to an (inner product) feature space F

ϕ:xϕ(x)F

用到 SVM 里,基本思想就是:

  1. 你在 vector space X 不是 hyperplane 不可分嘛,我把你 transform 到另外一个 vector space F,如果在 F 里 hyperplane 可分,problem solved
  2. 我们需要用到 dot product,所以 F 需要是个 inner product vector space
  3. 我们其实并不关心 transformation ϕ 是怎么个 transform 法,我们只关心 dot product ϕ(x)ϕ(z)

从定义可以看出:

  • 这里 kernel 和 kernel function 是一个意思,而且和 Linear Algebra 里的 kernel 无关!(我宁愿你叫 inner-product method!)
    • How to intuitively explain what a kernel is?: Kernel is a way of computing the dot product of two vectors in some (possibly very high dimensional) feature space, which is why kernel functions are sometimes called “generalized dot product”.
  • 所以凡是涉及到 inner product 的 ML 算法,应该都可以用 kernel 处理
    • 我能最快想到的场景就是 clustering,很多 metric 都可以用 inner product 表示

Normed vector space / Metric SpacePermalink

Norms and Metrics, Normed Vector Spaces and Metric Spaces: Let V be a vector space. A function ||:VR+ is a norm on V if it satisfies:

  1. xV:|x|0
  2. xV:|x|=0x=0
  3. x,yV:|x+y||x|+|y|
  4. αR,xV:|αx|=α|x|

A vector space together with a norm is called a normed vector space.

Wikipedia: Metric space: A metric space is an ordered pair (M,d) where M is a set and d is a metric on M, i.e., a function

d:M×MR

such that for any x,y,zM, the following holds:

  1. (non-negativity or separation axiom): d(x,y)0
  2. (identity of indiscernibles): d(x,y)=0x=y
  3. (symmetry): d(x,y)=d(y,x)
  4. (subadditivity or triangle inequality): d(x,z)d(x,y)+d(y,z)

Norms and Metrics, Normed Vector Spaces and Metric Spaces:

In other words, a normed vector space is automatically a metric space, by defining the metric in terms of the norm in the natural way. But a metric space may have no algebraic (vector) structure–i.e., it may not be a vector space–so the concept of a metric space is a generalization of the concept of a normed vector space.

所以,我们可以把 normed vector space 加上 inner product 操作,然后做成一个 inner product metric space。在这样一个 feature space 上的 clustering 应该都可以用 kernel method

更多 kernel clustering 内容参考 A Survey of Kernel Clustering Methods

Categories:

Updated:

Comments