我有一百万个3D点要传递给numpy.linalg.svd
,但它很快就会耗尽内存。有没有办法将此操作分解成更小的块?
我不知道它在做什么,但我只能传递代表3x3、4x4矩阵的数组吗?因为我在网上看到过使用任意数量元素的数组的用法。
我有一百万个3D点要传递给numpy.linalg.svd
,但它很快就会耗尽内存。有没有办法将此操作分解成更小的块?
我不知道它在做什么,但我只能传递代表3x3、4x4矩阵的数组吗?因为我在网上看到过使用任意数量元素的数组的用法。
numpy.linalg.svd
不需要M==N。实际上,这正是SVD用于计算诸如秩和伪逆之类的东西的地方。而像linalg.inv这样的方法需要一个定义结果的正方形(和满秩)矩阵。@Saullo Castro是正确的。full_matrices=False可以使棘手的问题变得易于处理,因为U矩阵的元素变为1Mx3,大大节省了空间。我不确定numpy使用哪种缩减SVD算法(我认为它可能是紧凑型SVD或薄型SVD),维基百科上的3种广泛使用的算法在Reduced SVDs部分中简要描述:http://en.wikipedia.org/wiki/Singular_value_decomposition。它们都围绕将完整的U矩阵的计算缩减为一种缩减形式,并且这对于某些问题甚至许多问题来说已经足够了。当numberObservations>>numberFeatures时,节省最多。numberObservations = 900
numberFeatures = 600
mostSignificantSingularValues = 600
a = np.random.randn( numberObservations, numberFeatures) + 1j*np.random.randn(numberObservations, numberFeatures)
#Reconstruction based on full SVD:
U, s, V = np.linalg.svd(a, full_matrices=True)
print(U.shape, V.shape, s.shape)
S = np.zeros((numberObservations, numberFeatures), dtype=complex)
S[:mostSignificantSingularValues, :mostSignificantSingularValues] = np.diag(s[:mostSignificantSingularValues])
print(np.allclose(a, np.dot(U, np.dot(S, V))))
d1 = a - np.dot(U, np.dot(S, V))#
#True
#Reconstruction based on reduced SVD:
U, s, V = np.linalg.svd(a, full_matrices=False)
print(U.shape, V.shape, s.shape)
S = np.diag(s)
print(np.allclose(a, np.dot(U, np.dot(S, V))))
d2 = a - np.dot(U, np.dot(S, V))#
scipy.linalg.svd
而不是numpy的函数。
svd
需要输入2-D arrays
。如果传递full_matrices=False
,似乎需要更少的内存... - Saullo G. P. Castro