Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Inverse of singular matrix
#1
How one can invert this singular matrix?

m1 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1], [0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1], [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0,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 0 0 0 1 0 0 0 0 0 0 0 0 0] [1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
Quote
#2
This matrix is of shape (30, 20). Therefore, it couldn't be inverted in traditional sense. The main question here is why do you need to invert such matrix? May be you need to solve a system of linear equation with that matrix, e.g. Ax = b. In this case, your system is probably overdetermined and has no solution in classical sense, but it could be solved in least squares sense.
Even if the matrix has insufficient rank, e.g. rank(A) < 20, you can obtain least squares solution using Moore-Penrose inversion. It is implemented in numpy: np.linalg.pinv.
So, least squares solution could be obtained as follows:

x = np.linalg.pinv(A) @ b, where
b is known vector of shape (30, 1); you can use np.dot(np.linalg.pinv(A), b) instead of @ (if you work with Py < 3.5).
Gribouillis likes this post
Quote
#3
(May-04-2019, 10:42 AM)scidam Wrote: This matrix is of shape (30, 20). Therefore, it couldn't be inverted in traditional sense. The main question here is why do you need to invert such matrix? May be you need to solve a system of linear equation with that matrix, e.g. Ax = b. In this case, your system is probably overdetermined and has no solution in classical sense, but it could be solved in least squares sense.
Even if the matrix has insufficient rank, e.g. rank(A) < 20, you can obtain least squares solution using Moore-Penrose inversion. It is implemented in numpy: np.linalg.pinv.
So, least squares solution could be obtained as follows:

x = np.linalg.pinv(A) @ b, where
b is known vector of shape (30, 1); you can use np.dot(np.linalg.pinv(A), b) instead of @ (if you work with Py < 3.5).

Yes I need to solve a system of linear equation, and I tried with Moore-Penrose inversion, but the solution it is not sufficient. Therefore I am looking for another was of inverting this matrix.
Quote
#4
Pseudoinverse gives you a solution of minimum norm; In your case matrix A has rank=15, so you have "quite large subspace of freedom" to choose another solution. From the following post you can find how to get any solution:
any_solution = np.linalg.pinv(A) @ b + (np.ones((20, 20)) - np.linalg.pinv(A)@A)@ y  # y.shape = (20, 1)
y is arbitrary vector. Choosing appropriate y probably lead you to desirable solution.
Quote
#5
I made a mistake in my previous post, np.ones(...) should be replaced with np.eye(20).
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  comparing each rows of two matrix PhysChem 10 923 May-17-2019, 06:50 AM
Last Post: Gribouillis
  matrix by vector mcgrim 8 289 May-02-2019, 10:39 AM
Last Post: ichabod801
  Extract of matrix subpart using a deep copy paul18fr 2 183 May-02-2019, 06:49 AM
Last Post: paul18fr
  Help in adding confusion matrix Aashish 5 489 Apr-15-2019, 11:45 PM
Last Post: scidam
  counting the occurence of a specified number in a numpy-matrix PhysChem 1 217 Apr-03-2019, 01:37 PM
Last Post: PhysChem
  function matrix mcgrim 14 684 Mar-19-2019, 09:28 PM
Last Post: mcgrim
  PyCM 1.8 released: Machine learning library for confusion matrix statistical analysis sepandhaghighi 0 299 Jan-05-2019, 12:36 PM
Last Post: sepandhaghighi
  Creating matrix counting words in list of strings jazmad 2 433 Dec-23-2018, 05:47 PM
Last Post: jazmad
  Clustering based on a variable and on a distance matrix flucoe 2 571 Dec-16-2018, 09:57 PM
Last Post: flucoe
  The twelfth root of a matrix Arduinol 9 707 Nov-28-2018, 11:36 AM
Last Post: Gribouillis

Forum Jump:


Users browsing this thread: 1 Guest(s)