You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple (but slightly time-consuming) implementation can be based on SVD:
PMMatrix>> pseudoinverse
| svdusvsPseudoinverse |
svd :=PMSingularValueDecompositiondecompose: matrix.
u := svd leftSingularMatrix.
s := svd diagonalSingularValueMatrix.
v := svd rightSingularMatrix.
sPseudoinverse :=selfpseudoinverseOfDiagonal: s.
^ v * sPseudoinverse * u transpose
PMMatrix>>pseudoinverseOfDiagonal: aMatrix [
"To get pseudoinverse of a diagonal rectangular matrix, we take reciprocal of any no-zero element of the main diagonal, leaving all zeros in place. Then we transpose the matrix."
| pseudoinversediagonalSize |
"Rows become columns and columns become rows because we transpose"
pseudoinverse :=PMMatrixzerosRows: aMatrix numberOfColumns
cols: aMatrix numberOfRows.
"The size of the main diagonal of a rectangular matrix is its smallest dimension"
diagonalSize := aMatrix numberOfRows min: aMatrix numberOfColumns.
"Inverting the elements on the main diaginal"1to: diagonalSize do: [ :i |
pseudoinverse at: i at: i put: ((aMatrix at: i at: i) =0ifTrue: [ 0 ] ifFalse: [ 1/ (aMatrix at: i at: i) ]) ].
^ pseudoinverse
The text was updated successfully, but these errors were encountered:
PMMatrix>> mpInverse
"Moore Penrose Inverse. "
|fg|
self numberOfRows <self numberOfColumns
ifTrue:[ f :=self transpose qrFactorizationWithPivoting.
g := f first.
f := f second inversePivotColumns: (f at:3) ]
ifFalse: [ f :=self qrFactorizationWithPivoting.
g := (f second inversePivotColumns: (f at:3)) transpose.
f := f first transpose ].
^ g * ((f *self*g) inverse) *f
@olekscode@SergeStinckwich the tests for these (MP Inverse) fail because of QR Decomposition with pivoting. I am attempting to fix it with #288. Specifically, the Pivot has nils in it for some matrices and I focusing on why very closely.
https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse
A simple (but slightly time-consuming) implementation can be based on SVD:
The text was updated successfully, but these errors were encountered: