randomized_range_finder
- sklearn.utils.extmath.randomized_range_finder(A, *, size, n_iter, power_iteration_normalizer='auto', random_state=None)
Compute an orthonormal matrix whose range approximates the range of A.
- Parameters:
- A
Compute an orthonormal matrix whose range approximates the range of A.
The input data matrix.
Size of the return array.
Number of power iterations used to stabilize the result.
Whether the power iterations are normalized with step-by-step
QR factorization (the slowest but most accurate), ‘none’
(the fastest but numerically unstable when n_iter is large, e.g.
typically 5 or larger), or ‘LU’ factorization (numerically stable
but can lose slightly in accuracy). The ‘auto’ mode applies no
normalization if n_iter <= 2 and switches to LU otherwise.
The seed of the pseudo random number generator to use when shuffling the data, i.e. getting the random vectors to initialize the algorithm. Pass an int for reproducible results across multiple function calls. See Glossary.
A projection matrix, the range of which approximates well the range of the input matrix A.
Follows Algorithm 4.3 of “Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions” Halko, et al. (2009)
An implementation of a randomized algorithm for principal component analysis A. Szlam et al. 2014
>>> import numpy as np
>>> from sklearn.utils.extmath import randomized_range_finder
>>> A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> randomized_range_finder(A, size=2, n_iter=2, random_state=42)
array([[-0.214, 0.887],
[-0.521, 0.249],
[-0.826, -0.388]])