使用特征值测试奇异性:识别共线列 [英] using eigenvalues to test for singularity: identifying collinear columns

查看:79
本文介绍了使用特征值测试奇异性:识别共线列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用特征值方法检查矩阵是否为奇异(即,如果特征值之一为零,则矩阵为奇异)。这是代码:

I am trying to check if my matrix is singular using the eigenvalues approach (i.e. if one of the eigenvalues is zero then the matrix is singular). Here is the code:

z <- matrix(c(-3,2,1,4,-9,6,3,12,5,5,9,4),nrow=4,ncol=3) 
eigen(t(z)%*%z)$values

我知道特征值按降序排列。有人可以让我知道是否有办法找出与矩阵中哪个列相关联的特征值吗?我需要删除共线列。

I know the eigenvalues are sorted in descending order. Can someone please let me know if there is a way to find out what eigenvalue is associated to what column in the matrix? I need to remove the collinear columns.

在上面的示例中可能很明显,但这只是一个示例,旨在节省您创建新矩阵的时间。

It might be obvious in the example above but it is just an example intended to save you time from creating a new matrix.

推荐答案

示例:

z <- matrix(c(-3,2,1,4,-9,6,3,12,5,5,9,4),nrow=4,ncol=3)
m <- crossprod(z) ## slightly more efficient than t(z) %*% z

第三个特征向量对应于共线组合:

This tells you that the third eigenvector corresponds to the collinear combinations:

ee <- eigen(m)
(evals <- zapsmall(ee$values))
## [1] 322.7585 124.2415   0.0000

现在检查相应的特征向量列为对应于它们各自特征值的列

Now examine the corresponding eigenvectors, which are listed as columns corresponding to their respective eigenvalues:

   (evecs <- zapsmall(ee$vectors))
   ## [1,] -0.2975496 -0.1070713  0.9486833
   ## [2,] -0.8926487 -0.3212138 -0.3162278
   ## [3,] -0.3385891  0.9409343  0.0000000

第三个特征值是零;第三个特征向量的前两个元素( evecs [,3] )不为零,这告诉您第1列和第2列是共线的。

The third eigenvalue is zero; the first two elements of the third eigenvector (evecs[,3]) are non-zero, which tells you that columns 1 and 2 are collinear.

这是一种自动化该测试的方法:

Here's a way to automate this test:

   testcols <- function(ee) {
       ## split eigenvector matrix into a list, by columns
       evecs <- split(zapsmall(ee$vectors),col(ee$vectors))
       ## for non-zero eigenvalues, list non-zero evec components
       mapply(function(val,vec) {
           if (val!=0) NULL else which(vec!=0)
       },zapsmall(ee$values),evecs)
   }

testcols(ee)
##  [[1]]
## NULL
## [[2]]
## NULL
## [[3]]
## [1] 1 2

这篇关于使用特征值测试奇异性:识别共线列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆