Skip to content

Commit d5d36d0

Browse files
Clarified the assertion a little more by making the code follow the definition in the wiki more closely.
1 parent b67cdf9 commit d5d36d0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Math-Tests-Matrix/PMQRTest.class.st

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ Class {
55
}
66

77
{ #category : #running }
8-
PMQRTest >> assert: inverse isInverseOf: aMatrix [
9-
"A~ * A = A * A~ = I"
8+
PMQRTest >> assert: inverse isMoorePenroseInverseOf: aMatrix [
9+
"https://en.wikipedia.org/wiki/Moore–Penrose_inverse#Definition"
1010

1111
| identityMatrix |
12-
identityMatrix := inverse * aMatrix.
13-
self assert: (aMatrix * identityMatrix closeTo: aMatrix).
14-
self assert: identityMatrix * inverse closeTo: inverse.
15-
self assert: identityMatrix transpose closeTo: identityMatrix.
12+
"These two assertions are what define a pseudoinverse. They are known as
13+
the Moore–Penrose conditions of which there are four, but here we have two. The other two
14+
are that (A * A+) and A+ * A are Hermitian.
15+
"
16+
self assert: (aMatrix * inverse * aMatrix closeTo: aMatrix).
17+
self assert: inverse * aMatrix * inverse closeTo: inverse.
18+
19+
"Pseudoinversion commutes with transposition, complex conjugation, and taking the conjugate transpose"
20+
self assert: aMatrix transpose mpInverse closeTo: aMatrix mpInverse transpose.
21+
1622
identityMatrix := aMatrix * inverse.
1723
self assert: identityMatrix transpose closeTo: identityMatrix.
1824
self assert: (identityMatrix * aMatrix) closeTo: aMatrix.
@@ -23,7 +29,7 @@ PMQRTest >> mpTestFunction: aMatrix [
2329

2430
| inverse |
2531
inverse := aMatrix mpInverse.
26-
self assert: inverse isInverseOf: aMatrix.
32+
self assert: inverse isMoorePenroseInverseOf: aMatrix.
2733

2834
]
2935

0 commit comments

Comments
 (0)