44# Authors: G. Varoquaux, A. Gramfort, A. Passos, O. Grisel
55# License: BSD
66
7+ import warnings
78import numpy as np
89from scipy import linalg
910
@@ -78,7 +79,8 @@ def safe_sparse_dot(a, b, dense_output=False):
7879 return np .dot (a , b )
7980
8081
81- def randomized_range_finder (A , size , n_iterations , random_state = None ):
82+ def randomized_range_finder (A , size , n_iter , random_state = None ,
83+ n_iterations = None ):
8284 """Computes an orthonormal matrix whose range approximates the range of A.
8385
8486 Parameters
@@ -87,7 +89,7 @@ def randomized_range_finder(A, size, n_iterations, random_state=None):
8789 The input data matrix
8890 size: integer
8991 Size of the return array
90- n_iterations : integer
92+ n_iter : integer
9193 Number of power iterations used to stabilize the result
9294 random_state: RandomState or an int seed (0 by default)
9395 A random number generator instance
@@ -106,6 +108,10 @@ def randomized_range_finder(A, size, n_iterations, random_state=None):
106108 approximate matrix decompositions
107109 Halko, et al., 2009 (arXiv:909) http://arxiv.org/pdf/0909.4061
108110 """
111+ if n_iterations is not None :
112+ warnings .warn ("n_iterations was renamed to n_iter for consistency "
113+ "and will be removed in 0.16." , DeprecationWarning )
114+ n_iter = n_iterations
109115 random_state = check_random_state (random_state )
110116
111117 # generating random gaussian vectors r with shape: (A.shape[1], size)
@@ -117,16 +123,16 @@ def randomized_range_finder(A, size, n_iterations, random_state=None):
117123
118124 # perform power iterations with Y to further 'imprint' the top
119125 # singular vectors of A in Y
120- for i in xrange (n_iterations ):
126+ for i in xrange (n_iter ):
121127 Y = safe_sparse_dot (A , safe_sparse_dot (A .T , Y ))
122128
123129 # extracting an orthonormal basis of the A range samples
124130 Q , R = qr_economic (Y )
125131 return Q
126132
127133
128- def randomized_svd (M , n_components , n_oversamples = 10 , n_iterations = 0 ,
129- transpose = 'auto' , random_state = 0 ):
134+ def randomized_svd (M , n_components , n_oversamples = 10 , n_iter = 0 ,
135+ transpose = 'auto' , random_state = 0 , n_iterations = None ):
130136 """Computes a truncated randomized SVD
131137
132138 Parameters
@@ -142,7 +148,7 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iterations=0,
142148 to ensure proper conditioning. The total number of random vectors
143149 used to find the range of M is n_components + n_oversamples.
144150
145- n_iterations : int (default is 0)
151+ n_iter : int (default is 0)
146152 Number of power iterations (can be used to deal with very noisy
147153 problems).
148154
@@ -172,6 +178,11 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iterations=0,
172178 * A randomized algorithm for the decomposition of matrices
173179 Per-Gunnar Martinsson, Vladimir Rokhlin and Mark Tygert
174180 """
181+ if n_iterations is not None :
182+ warnings .warn ("n_iterations was renamed to n_iter for consistency "
183+ "and will be removed in 0.16." , DeprecationWarning )
184+ n_iter = n_iterations
185+
175186 random_state = check_random_state (random_state )
176187 n_random = n_components + n_oversamples
177188 n_samples , n_features = M .shape
@@ -182,7 +193,7 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iterations=0,
182193 # this implementation is a bit faster with smaller shape[1]
183194 M = M .T
184195
185- Q = randomized_range_finder (M , n_random , n_iterations , random_state )
196+ Q = randomized_range_finder (M , n_random , n_iter , random_state )
186197
187198 # project M to the (k + p) dimensional space using the basis vectors
188199 B = safe_sparse_dot (Q .T , M )
0 commit comments