SVD APPLICATIONS: PCA AND PSEUDO-INVERSE

SVD Applications: PCA and Pseudo-inverse

Maths

There are two typical applications of Singular Value Decomposition, Principal Component Analysis (PCA) and matrix pseudo-inverse. Let's recapitulate the SVD before elaborating on these two applications one by one.

Any m-by-n matrix can be decomposed into


where U’s columns are the eigenvectors of AATV’s columns are the eigenvectors of ATA and


with sigmai’s (1 <=i <=r) being the singular values of A.


Principal Component Analysis

Compared with factor analysis based on a probabilistic model and resorting to the iterative EM algorithm, PCA is known as a dimension reduction method, trying to directly identify the subspace in which the data approximately lies.

Given a data set,


chances are that some attributes are almost correlated. What PCA does is to reduce n-dimensional data to k-dimensional. Prior to running PCA algorithm, we need first to pre-process the data to normalize its mean and variance to be zero and one respectively, as follows:


After having carried out this normalization, we might end up with a figure below.


How do we compute the “major axis of variation” u, that is, the direction on which the data approximately lies? One way to pose this problem is as finding the unit vector so that when the data is projected onto the direction corresponding to u, the variance of the projected data is maximized. Intuitively, the data starts off with some amount of variance/information in it. We would like to choose a direction u so that if we were to approximate the data as lying in the direction/subspace corresponding to u, as much as possible of this variance is still retained.


Noting that the length of the projection of x(i) onto u is given by


we would like to choose a unit-length to maximize the variance of all the projections,


Letting


we pose the optimization problem to


Constructing Lagrange function,


Setting its derivative to zero,


we easily recognize that u must be the eigenvector of matrix SIGMA.

Noting that SIGMA is an n-by-n symmetric matrix having n independent eigenvectors, we should choose u1,…,uk to be the top k eigenvectors of SIGMA (the corresponding singular values must be in non-ascending order, for the optimization target equals to the eigenvalue) so as to project the data into a ­k-dimensional subspace (k <n).

By designing data matrix X,


and noting that (See the interpretation of matrix multiplication in Appendix)


we can efficiently compute top eigenvectors u’s of data matrix X using SVD by X = UDVT, since the top k columns of V are exactly the top k eigenvectors of XTX = SIGMA. When x(i) is high dimensional, XTwould be much harder to represent. By computing V decomposed out of X, alternatively, the top k eigenvectors of X become available.

Since the top k eigenvectors of SIGMA have been determined, by projecting the data into this k-dimensional subspace, we can obtain the a new lower, k-dimensional approximation/representation for x(i),


The vectors u1,…,uk are called the first k principal components of the data. Therefore, using SVD to implement PCA is a much better method if we are given a set of extremely high dimensional data.


Pseudo-inverse

Given an m-by-n matrix A whose rank is r, the two-sided inverse exists (AA-1 =I = A-1A) iff r = m = n (full rank).

In the case where rn < m (n columns are independent <=> N(A) = {0}), the left inverse exists as A-1left = (ATA)-1AT, for ATA is always invertible. (See its proof in Appendix)

In the case where rm < n (m rows are independent <=> N(AT) = {0}), the right inverse exists as A-1right = AT(AAT)-1, for AAT is always invertible. (See its proof in Appendix)

In least squares, we have the projection matrix Pcol = AA-1left = A(ATA)-1Awhich can project b onto the column space of A and the projection matrix Prow =A-1right = AT(AAT)-1which can project b onto the row space of A.

However, for most of cases where r < min{m, n}, neither the left inverse nor the right inverse exists. How can we implement least square in this situation?

The pseudo-inverse denoted by A(n-by-m matrix) is the generalized inverse of A (m-by-n matrix) with any rank. Therefore, we can project b onto the column space of A by Pb, where P =AA+, and continue with the least squares.

SVD is an effective way to find the pseudo inverse A+ of A. First, decomposing A into


then, taking the pseudo-inverse of A, we obtain,


In conclusion, we can use SVD to find the pseudo-inverse of any matrix A whatsoever.


Appendix

1. There are four ways to interpret the matrix multiplication (matrix-matrix product).

First, the most obvious viewpoint following immediately from the definition of matrix multiplication by representing A by rows and B by columns, symbolically, looks like the following.


Second, we can represent A by columns and B by rows. This representation leads to a much trickier interpretation of AB as a sum of outer products. Symbolically,


Third, we can view matrix-matrix product as a set of products between matrix and column vectors.


Fourth, we have the analogous viewpoint, where we represent A by rows, and view the rows of as a set of products between row vectors and matrix. Symbolically,


2. ATA is always invertible iff rnm (is the rank of the m-by-n matrix A).

    Proof:

      ATA (n-by-matrix) is invertible <=> r(ATA)=<=>

      Equation ATAx = 0 has only one solution x = 0 <=>

      (Ax)T(Ax)=0 has only one solution x = 0 <=>

      Ax = 0 has only one solution x = 0 <=> r(A) = n.

   Similarly, we can prove that AAT is always invertible iff r = m < n.


Postscript

This is the last blog of the year 2014 during which everything finally worked out but Eth(...)ara. This work is for the loving memories of us.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值