1
0
mirror of https://gitlab.com/scemama/qp_plugins_scemama.git synced 2024-07-26 12:47:30 +02:00
qp_plugins_scemama/devel/svdwf/RSVD.py

20 lines
497 B
Python
Raw Normal View History

2021-04-08 16:31:31 +02:00
# !!!
import numpy as np
from QR import QR_fact
# !!!
def powit_RSVD(X, new_r, nb_powit, nb_oversamp):
# !!!
G = np.random.randn(X.shape[1], new_r+nb_oversamp)
Q = QR_fact( np.dot(X,G) )
# !!!
for _ in range(nb_powit):
Q = QR_fact( np.dot(X.T,Q) )
Q = QR_fact( np.dot(X,Q) )
# !!!
Y = np.dot(Q.T,X)
# !!!
U, S, VT = np.linalg.svd(Y, full_matrices=0)
U = np.dot(Q,U)
return U[:,:(new_r)], S[:(new_r)], VT[:(new_r),:]
# !!!
# !!!