Skip to content

Commit 2e935d7

Browse files
authored
Fixes #236 (#237)
* Fixes #236 * Renamed variables and added new accessors methods
1 parent 18b3e91 commit 2e935d7

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

src/Math-Matrix/PMSingularValueDecomposition.class.st

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Class {
3232
#name : #PMSingularValueDecomposition,
3333
#superclass : #Object,
3434
#instVars : [
35-
'u',
36-
's',
37-
'v'
35+
'diagonalSingularValueMatrix',
36+
'leftSingularMatrix',
37+
'rightSingularMatrix'
3838
],
3939
#category : #'Math-Matrix'
4040
}
@@ -44,6 +44,13 @@ PMSingularValueDecomposition class >> decompose: aMatrix [
4444
^ self new initialize: aMatrix
4545
]
4646

47+
{ #category : #accessing }
48+
PMSingularValueDecomposition >> diagonalSingularValueMatrix [
49+
"Diagonal matrix S in A = USV decomposition. All elements are 0 except those on the main diagonal. The values on the diagonal are singular values of matrix A. By convention, they are sorted in descending order"
50+
51+
^ diagonalSingularValueMatrix
52+
]
53+
4754
{ #category : #initialization }
4855
PMSingularValueDecomposition >> initialize: aMatrix [
4956

@@ -56,26 +63,55 @@ PMSingularValueDecomposition >> initialize: aMatrix [
5663
"Expensive computation"
5764
eigenU := symU eigen.
5865
eigenV := symV eigen.
59-
u := (PMMatrix rows: eigenU vectors) transpose.
60-
v := (PMMatrix rows: eigenV vectors) transpose.
66+
leftSingularMatrix := (PMMatrix rows: eigenU vectors) transpose.
67+
rightSingularMatrix := (PMMatrix rows: eigenV vectors) transpose.
6168
diag := m < n
6269
ifTrue: [ eigenU values ]
6370
ifFalse: [ eigenV values ].
64-
s := PMMatrix rows: m columns: n random: 0.
65-
s setDiagonal: diag sqrt
71+
diagonalSingularValueMatrix := PMMatrix rows: m columns: n random: 0.
72+
diagonalSingularValueMatrix setDiagonal: diag sqrt
6673
]
6774

6875
{ #category : #accessing }
6976
PMSingularValueDecomposition >> leftSingularForm [
70-
^ u
77+
78+
self
79+
deprecated: 'Use leftSingularMatrix instead'
80+
transformWith:'`@receiver leftSingularForm' -> '`@receiver leftSingularMatrix'.
81+
82+
^ leftSingularMatrix
83+
]
84+
85+
{ #category : #accessing }
86+
PMSingularValueDecomposition >> leftSingularMatrix [
87+
"Matrix U in the A = USV decomposition. The columns of this matrix are the eigenvectors of the A * (A transposed) matrix (called left singular vectors). The columns of this matrix are orthonormal"
88+
89+
^ leftSingularMatrix
7190
]
7291

7392
{ #category : #accessing }
7493
PMSingularValueDecomposition >> rightSingularForm [
75-
^ v
94+
95+
self
96+
deprecated: 'Use rightSingularMatrix instead'
97+
transformWith: '`@receiver rightSingularForm' -> '`@receiver rightSingularMatrix'.
98+
99+
^ rightSingularMatrix
100+
]
101+
102+
{ #category : #accessing }
103+
PMSingularValueDecomposition >> rightSingularMatrix [
104+
"Matrix V in the A = USV decomposition. The columns of this matrix are the eigenvectors of the (A transposed) * A matrix (called right singular vectors). The columns of this matrix are orthonormal"
105+
106+
^ rightSingularMatrix
76107
]
77108

78109
{ #category : #accessing }
79110
PMSingularValueDecomposition >> sForm [
80-
^ s
111+
112+
self
113+
deprecated: 'Use diagonalSingularValueMatrix instead'
114+
transformWith: '`@receiver sForm' -> '`@receiver diagonalSingularValueMatrix'.
115+
116+
^ diagonalSingularValueMatrix
81117
]

0 commit comments

Comments
 (0)