def estimate_rank(data, tol='auto', return_singular=False,
norm=True, copy=None):
"""Helper to estimate the rank of data
This function will normalize the rows of the data (typically
channels or vertices) such that non-zero singular values
should be close to one.
Parameters
----------
data : array
Data to estimate the rank of (should be 2-dimensional).
tol : float | str
Tolerance for singular values to consider non-zero in
calculating the rank. The singular values are calculated
in this method such that independent data are expected to
have singular value around one. Can be 'auto' to use the
same thresholding as ``scipy.linalg.orth``.
return_singular : bool
If True, also return the singular values that were used
to determine the rank.
norm : bool
If True, data will be scaled by their estimated row-wise norm.
Else data are assumed to be scaled. Defaults to True.
copy : bool
This parameter has been deprecated and will be removed in 0.13.
It is ignored in 0.12.
Returns
-------
rank : int
Estimated rank of the data.
s : array
If return_singular is True, the singular values that were
thresholded to determine the rank are also returned.
"""
if copy is not None:
warn('copy is deprecated and ignored. It will be removed in 0.13.')
data = data.copy() # operate on a copy
if norm is True:
norms = _compute_row_norms(data)
data /= norms[:, np.newaxis]
s = linalg.svd(data, compute_uv=False, overwrite_a=True)
if isinstance(tol, string_types):
if tol != 'auto':
raise ValueError('tol must be "auto" or float')
eps = np.finfo(float).eps
tol = np.max(data.shape) * np.amax(s) * eps
tol = float(tol)
rank = np.sum(s > tol)
if return_singular is True:
return rank, s
else:
return rank
utils.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录