@@ -28,39 +28,6 @@ PMQRTest >> assert: inverse isMoorePenroseInverseOf: aMatrix [
2828 closeTo: aMatrix mpInverse transpose.
2929]
3030
31- { #category : ' tests' }
32- PMQRTest >> testDecompositionOfMatrixCausingErraticFailure [
33-
34- | a qrDecomposition matricesAndPivot q r expectedMatrix pivot |
35- a := PMSymmetricMatrix rows:
36- #( #( 0.41929313699681925 0.05975350554089691
37- 0.2771676258543356 0.35628773381760703 )
38- #( 0.05975350554089691 0.12794227252152854
39- 0.3257742693302102 0.28814463284245906 )
40- #( 0.2771676258543356 0.3257742693302102 0.8468441832097453
41- 0.9101872061892353 )
42- #( 0.35628773381760703 0.28814463284245906
43- 0.9101872061892353 0.5163744224777326 ) ).
44-
45- qrDecomposition := PMQRDecomposition of: a.
46- matricesAndPivot := qrDecomposition decomposeWithPivot.
47-
48- expectedMatrix := PMMatrix rows:
49- #( #( 0.2771676258543356 0.35628773381760703
50- 0.41929313699681925 0.05975350554089691 )
51- #( 0.3257742693302102 0.28814463284245906
52- 0.05975350554089691 0.12794227252152854 )
53- #( 0.8468441832097453 0.9101872061892353
54- 0.2771676258543356 0.3257742693302102 )
55- #( 0.9101872061892353 0.5163744224777326
56- 0.35628773381760703 0.28814463284245906 ) ).
57- q := matricesAndPivot at: 1 .
58- r := matricesAndPivot at: 2 .
59- pivot := matricesAndPivot at: 3 .
60- self assert: q * r closeTo: expectedMatrix.
61- self assert: pivot equals: #( 3 4 3 nil )
62- ]
63-
6431{ #category : ' tests' }
6532PMQRTest >> testHorizontalRectangularMatrixCannotBeDecomposed [
6633
@@ -225,24 +192,25 @@ PMQRTest >> testSimpleQRDecomposition [
225192{ #category : ' tests' }
226193PMQRTest >> testSimpleQRDecompositionWithPivot [
227194
228- | a qrDecomposition decomposition expected |
229- a := PMMatrix rows: {
195+ | a qrDecomposition expectedQR expectedPivot reconstruction |
196+ a := PMMatrix rows: {
230197 { 12 . - 51 . 4 }.
231198 { 6 . 167 . - 68 }.
232199 { - 4 . 24 . - 41 } }.
200+ expectedQR := PMMatrix rows: {
201+ { - 51 . 4 . 12 }.
202+ { 167 . - 68 . 6 }.
203+ { 24 . - 41 . - 4 } }.
204+ expectedPivot := #( 2 3 1 ) .
233205
234206 qrDecomposition := PMQRDecomposition of: a.
207+ qrDecomposition decomposeWithPivot.
235208
236- decomposition := qrDecomposition decomposeWithPivot .
237- decomposition first * decomposition second .
209+ self assert: qrDecomposition q * qrDecomposition r closeTo: expectedQR .
210+ self assert: qrDecomposition pivot equals: expectedPivot .
238211
239- expected := PMMatrix rows: {
240- { - 51 . 4 . 12 }.
241- { 167 . - 68 . 6 }.
242- { 24 . - 41 . - 4 } }.
243- self
244- assert: decomposition first * decomposition second
245- closeTo: expected
212+ reconstruction := qrDecomposition q * qrDecomposition r * qrDecomposition permutationMatrixFromPivot inverse.
213+ self assert: reconstruction closeTo: a
246214]
247215
248216{ #category : ' tests' }
0 commit comments