sklearn.utils.extmath
.randomized_range_finder¶
- sklearn.utils.extmath.randomized_range_finder(A, *, size, n_iter, power_iteration_normalizer='auto', random_state=None)[source]¶
Compute an orthonormal matrix whose range approximates the range of A.
- Parameters:
- A2D array
The input data matrix.
- sizeint
Size of the return array.
- n_iterint
Number of power iterations used to stabilize the result.
- power_iteration_normalizer{‘auto’, ‘QR’, ‘LU’, ‘none’}, default=’auto’
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 ifn_iter
<= 2 and switches to LU otherwise.New in version 0.18.
- random_stateint, RandomState instance or None, default=None
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.
- Returns:
- Qndarray
A (size x size) projection matrix, the range of which approximates well the range of the input matrix A.
Notes
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
Examples
>>> 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.21..., 0.88...], [-0.52..., 0.24...], [-0.82..., -0.38...]])