@@ -1668,19 +1668,23 @@ def __init__(self, a):
1668
1668
1669
1669
*numrows*, *numcols*: the dimensions of a
1670
1670
1671
- *mu* : a numdims array of means of a
1671
+ *mu* : a numdims array of means of a. This is the vector that points to the
1672
+ origin of PCA space.
1672
1673
1673
- *sigma* : a numdims array of atandard deviation of a
1674
+ *sigma* : a numdims array of standard deviation of a
1674
1675
1675
1676
*fracs* : the proportion of variance of each of the principal components
1677
+
1678
+ *s* : the actual eigenvalues of the decomposition
1676
1679
1677
1680
*Wt* : the weight vector for projecting a numdims point or array into PCA space
1678
1681
1679
1682
*Y* : a projected into PCA space
1680
1683
1681
1684
1682
1685
The factor loadings are in the Wt factor, ie the factor
1683
- loadings for the 1st principal component are given by Wt[0]
1686
+ loadings for the 1st principal component are given by Wt[0].
1687
+ This row is also the 1st eigenvector.
1684
1688
1685
1689
"""
1686
1690
n , m = a .shape
@@ -1697,15 +1701,27 @@ def __init__(self, a):
1697
1701
1698
1702
U , s , Vh = np .linalg .svd (a , full_matrices = False )
1699
1703
1700
-
1701
- Y = np .dot (Vh , a .T ).T
1702
-
1703
- vars = s ** 2 / float (len (s ))
1704
- self .fracs = vars / vars .sum ()
1705
-
1706
-
1704
+ # Note: .H indicates the conjugate transposed / Hermitian.
1705
+
1706
+ # The SVD is commonly written as a = U s V.H.
1707
+ # If U is a unitary matrix, it means that it satisfies U.H = inv(U).
1708
+
1709
+ # The rows of Vh are the eigenvectors of a.H a.
1710
+ # The columns of U are the eigenvectors of a a.H.
1711
+ # For row i in Vh and column i in U, the corresponding eigenvalue is s[i]**2.
1712
+
1707
1713
self .Wt = Vh
1714
+
1715
+ # save the transposed coordinates
1716
+ Y = np .dot (Vh , a .T ).T
1708
1717
self .Y = Y
1718
+
1719
+ # save the eigenvalues
1720
+ self .s = s ** 2
1721
+
1722
+ # and now the contribution of the individual components
1723
+ vars = self .s / float (len (s ))
1724
+ self .fracs = vars / vars .sum ()
1709
1725
1710
1726
1711
1727
def project (self , x , minfrac = 0. ):
0 commit comments