我正在尝试对经过一些文本处理(最终目标是执行潜在语义分析)获得的矩阵(3241x 12596)应用奇异值分解( SVD ),我不能理解为什么会发生这种情况,因为我的64位机器有16 of的RAM。一旦调用svd(self.A),它就会抛出一个错误。精确的误差如下所示:
Traceback (most recent call last):
File ".\SVD.py", line 985, in <module>
_svd.calc()
File ".\SVD.py", line 534, in calc
self.U, se
我在表演numpy svd
U, S, V = np.linalg.svd(A)
A的形状是:
(10000, 10000)
由于大小,它给我的内存错误:
U, S, V = np.linalg.svd(A, full_matrices=False) # nargout=3
File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 1319, in svd
work = zeros((lwork,), t)
MemoryError
那么我如何为我的矩阵找到svd?
我正在尝试R中python中的简单白化函数
Python
def svd_whiten(X):
U, s, Vt = np.linalg.svd(X, full_matrices=False)
#print(U)
#print(Vt)
# U and Vt are the singular matrices, and s contains the singular values.
# Since the rows of both U and Vt are orthonormal vectors, then U * Vt
# will be wh
我尝试使用LSI来生成表示文档的向量。我正在使用Scipy库中的svd包。但是程序抛出了一个内存错误。我的矩阵的大小是100x13057。这对我的8G内存来说是不是太大了?
我在stackflow中搜索了这个问题。有人说我只需要在我的64位操作系统上安装64位Python。(现在,我在64位操作系统上有32位Python )。但是重新安装所有的库太简单了。另一种观点是转换稀疏矩阵。
那么,每个人都对这个问题有想法吗?谢谢!
raw_matrix = []
for text in forest_lsi:
raw_matrix.append( text.get_vector() )
fro
我在Jupyter笔记本中写了一个python3脚本(名为'SVD.ipynb'):
from tkinter import *
from PIL import Image, ImageTk
import numpy as np
from scipy import linalg as lg
import matplotlib.pyplot as plt
########## Funktion zur Erstellung von Bilddateien in unterschiedlichen #####
########## Kompressionsstufen we
我想使用scipy对稀疏矩阵进行奇异值分解:
from svd import compute_svd
print("The size of raw matrix: "+str(len(raw_matrix))+" * "+str(len(raw_matrix[0])))
from scipy.sparse import dok_matrix
dok = dok_matrix(raw_matrix)
matrix = compute_svd( dok )
函数compute_svd是我定制的模块,如下所示:
def compute_svd( matrix ):
我不明白为什么这不编译。_svd返回一个double*,并且我将它分配给一个double*。
错误消息:在没有GIL的情况下不允许使用Python强制
cpdef svd(A_f, m, n):
cdef double *S_p
with nogil:
S_p = _svd(A_f, m, n)
return <double[:min(m, n)]> S_p
cdef double* _svd(double[:] A_f, int m, int n) nogil:
#code removed bc it is long
编辑:它
我正在将SVD应用于Python中的一个大型稀疏矩阵。我正在使用来自scipy.sparse.linalg包的svd。奇异值从升序中排序,因此奇异向量被排列成对应于升序奇异值的奇异向量。我想知道是否有一个选项,输出奇异值的降序,这样奇异向量也安排了相应的下降奇异值?下面只是一个示例代码:
from scipy.sparse.linalg import svds
from scipy import sparse
X = numpy.random.uniform(size = [40, 20])
X = scipy.sparse.csc_matrix(X)
u, s, vt = svds(X, 1
python中是否有函数将通过使用协作过滤 (ex )来为您填充矩阵中缺少的值。交替极小化算法等。还是需要从头开始实现这些功能?
编辑:虽然这不是一个矩阵完成的例子,但为了说明类似的情况,我知道Matlab中有一个svd()函数,它以一个矩阵作为输入,并自动输出它的奇异值分解(svd)。我在Python中寻找类似的东西,希望是一个内置的函数,但是即使是一个好的库也会很棒。
我正试图逆星火矩阵。下面是我使用的函数。
def computeInverse(matrix: RowMatrix): BlockMatrix = {
val numCoefficients = matrix.numCols.toInt
val svd = matrix.computeSVD(numCoefficients, computeU = true)
val indexed_U = new IndexedRowMatrix(svd.U.rows.zipWithIndex.map(r => new IndexedRow(r._2, r._1)))
val invS = Dens
我合并了两个数据帧,它们有一些公共的列,但是有一些不同的列。我想将奇异值分解(SVD)应用于组合数据帧.但是,填充NaN值会影响结果,在我的情况下,即使用零填充数据也是错误的,因为有些列的值为零。下面是一个例子。有什么办法解决这个问题吗?
>>> df1 = pd.DataFrame(np.random.rand(6, 4), columns=['A', 'B', 'C', 'D'])
>>> df1
A B C D
0 0.
我希望为Keras中的自定义优化器做SVD (具体来说,我想将移植到Keras。
在Tensorflow中,我会使用tensorflow.python.ops.linalg_ops.svd(),但是在keras.backend中没有这样的函数。
SVD是否可以在纯Keras设置中执行,或者我可以以某种方式直接使用Tensorflow函数(如果是,如何使用)?
编辑:只是为了将来参考,实际上存在一个包装器函数,允许在Keras中直接使用本机tf优化器:
import keras as ks
from tensorflow.contrib.opt import AdamWOptimizer
tf
我在Python中实现了一个非常简单的奇异值分解(不用担心,我知道numpy版本),它更多的是为了好玩。它基于A^TA和AA^T的特征向量的计算(例如,参见here)。从理论上讲,这在Python中实现起来非常简单: def calc_svd(A: np.array):
ATA = A.T@A
AAT = A@A.T
#compute the eigenvectors and sort them in ascending size of the eigenvalues
eigenvalues_ATA, eigenvectors_ATA = np.lina