Routine to extract linear independent rows from a rank deficient matrix

前端 未结 2 1107
陌清茗
陌清茗 2021-01-13 07:45

I\'m struggling with the following problem: I have some very big matrices (say, at least, 2000x2000, and probably in the future they will even reach 10000x10000) with very s

相关标签:
2条回答
  • 2021-01-13 08:03

    The Gram Schmidt process finds a basis (equivalently largest independent subset) using linear combinations, and the QR Decomposition effectively mimics this.

    Therefore, one way to do what you want is to apply numpy.linalg.qr to the transpose, and check the non-zero components of the R matrix. The corresponding columns (in the transpose matrix, i.e., the rows in your original matrix) are independent.


    Edit After some searching, I believe this Berkeley lecture explains it, but here are examples

    import numpy as np
    
    # 2nd column is redundant
    a = np.array([[1, 0, 0], [0, 0, 0], [1, 0, 1]])
    >> np.linalg.qr(a)[1] # 2nd row empty
    array([[ 1.41421356,  0.        ,  0.70710678],
       [ 0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.70710678]])
    
    # 3rd column is redundant
    a = np.array([[1, 0, 0], [1, 0, 1], [0, 0, 0], ])
    >> np.linalg.qr(a)[1] # 3rd row empty
    array([[ 1.41421356,  0.        ,  0.70710678],
       [ 0.        ,  0.        , -0.70710678],
       [ 0.        ,  0.        ,  0.        ]])
    
    # No column redundant
    a = np.array([[1, 0, 0], [1, 0, 1], [2, 3, 4], ])
    >> np.linalg.qr(a)[1] # No row empty
    array([[ 2.44948974,  2.44948974,  3.67423461],
       [ 0.        ,  1.73205081,  1.73205081],
       [ 0.        ,  0.        ,  0.70710678]])
    
    0 讨论(0)
  • 2021-01-13 08:27

    Here's the link where I found a solution to my problem! The Cauchy-Schwartz method proposed here works just fine!!

    0 讨论(0)
提交回复
热议问题