randomized_range_finder#

sklearn.utils.extmath.randomized_range_finder(A, *, size, n_iter, power_iteration_normalizer='auto', random_state=None)[source]#

计算一个正交矩阵,其范围近似于 A 的范围。

参数:
A{array-like, sparse matrix} of shape (n_samples, n_features)

输入数据矩阵。

sizeint

返回数组的大小。

n_iter整型

用于稳定结果的幂迭代次数。

power_iteration_normalizer{‘auto’, ‘QR’, ‘LU’, ‘none’}, default=’auto’

幂迭代是否通过逐级QR分解(最慢但最准确)、'none'(最快但在n_iter较大时(例如,通常为5或更大)在数值上不稳定)或'LU'分解(数值稳定但精度可能略有损失)进行归一化。'auto'模式在n_iter <= 2时应用不归一化,否则切换到LU。

版本 0.18 新增。

random_stateint, RandomState instance or None, default=None

用于在打乱数据时使用的伪随机数生成器种子,即获取用于初始化算法的随机向量。传入一个整数可在多次函数调用中获得可重现的结果。参见Glossary

返回:
Qndarray of shape (size, size)

一个投影矩阵,其范围近似于输入矩阵A的范围。

注意事项

遵循 Halko 等人 (2009) “Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions” 中的算法 4.3。

A. Szlam 等人 (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]])