diff --git a/src/Math-Matrix-Tests/PMQRTest.class.st b/src/Math-Matrix-Tests/PMQRTest.class.st index b8b5d7b..4f1e753 100644 --- a/src/Math-Matrix-Tests/PMQRTest.class.st +++ b/src/Math-Matrix-Tests/PMQRTest.class.st @@ -31,7 +31,6 @@ PMQRTest >> assert: inverse isMoorePenroseInverseOf: aMatrix [ { #category : 'tests' } PMQRTest >> testDecompositionOfMatrixCausingErraticFailure [ - | a qrDecomposition matricesAndPivot q r expectedMatrix pivot | a := PMSymmetricMatrix rows: #( #( 0.41929313699681925 0.05975350554089691 diff --git a/src/Math-Matrix/PMQRDecomposition.class.st b/src/Math-Matrix/PMQRDecomposition.class.st index b361301..5fc426c 100644 --- a/src/Math-Matrix/PMQRDecomposition.class.st +++ b/src/Math-Matrix/PMQRDecomposition.class.st @@ -8,7 +8,8 @@ Class { 'matrixToDecompose', 'colSize', 'r', - 'q' + 'q', + 'comparisonPrecision' ], #category : 'Math-Matrix', #package : 'Math-Matrix' @@ -21,6 +22,18 @@ PMQRDecomposition class >> of: matrix [ ^ self new of: matrix ] +{ #category : 'constants' } +PMQRDecomposition >> comparisonPrecision [ + + ^ comparisonPrecision ifNil: [ self defaultComparisonPrecision ] +] + +{ #category : 'accessing' } +PMQRDecomposition >> comparisonPrecision: anObject [ + + comparisonPrecision := anObject +] + { #category : 'arithmetic' } PMQRDecomposition >> decompose [ " @@ -108,7 +121,7 @@ PMQRDecomposition >> decomposeWithPivot [ positionOfMaximum := (vectorOfNormSquareds copyFrom: rank + 1 to: vectorOfNormSquareds size) max. - (positionOfMaximum closeTo: 0) ifTrue: [ positionOfMaximum := 0 ]. + (positionOfMaximum closeTo: 0 precision: self comparisonPrecision) ifTrue: [ positionOfMaximum := 0 ]. positionOfMaximum := positionOfMaximum > 0 ifTrue: [ vectorOfNormSquareds indexOf: positionOfMaximum startingAt: rank + 1 ] @@ -128,6 +141,12 @@ PMQRDecomposition >> decomposeWithPivot [ ^ Array with: q with: r with: pivot ] +{ #category : 'constants' } +PMQRDecomposition >> defaultComparisonPrecision [ + + ^ 0.0001 +] + { #category : 'private' } PMQRDecomposition >> householderReflectionOf: columnVector atColumnNumber: columnNumber [