cherab.inversion.regularization.compute_svdΒΆ
-
cherab.inversion.regularization.compute_svd(T: NDArray[float64] | _spbase[float64, tuple[int, int]], H: NDArray[float64] | _spbase[float64, tuple[int, int]], Q: None =
None, use_gpu: bool =False, dtype: DTypeLike | None =None, progress: Progress | None =None, task_id: TaskID | None =None) tuple[NDArray[float64], NDArray[float64], NDArray[float64]]SourceΒΆ -
cherab.inversion.regularization.compute_svd(T: NDArray[float64] | _spbase[float64, tuple[int, int]], H: NDArray[float64] | _spbase[float64, tuple[int, int]], Q: NDArray[float64] | _spbase[float64, tuple[int, int]], use_gpu: bool =
False, dtype: DTypeLike | None =None, progress: Progress | None =None, task_id: TaskID | None =None) tuple[NDArray[float64], NDArray[float64], NDArray[float64], sp_csr_array[float64, tuple[int, int]]] Compute singular value decomposition (SVD) components of the generalized Tikhonov regularization problem.
This function returns the \(\mathbf{s}\), \(\mathbf{U}\), \(\tilde{\mathbf{V}}\) and \(\mathbf{B}\) from the given matrix \(\mathbf{T}\), \(\mathbf{Q}\), and \(\mathbf{H}\).
Note
The mathematical notation and calculation procedure is based on the inversion theory.
- Parameters:
- T : (M, N) array_likeΒΆ
Matrix for a linear equation \(\mathbf{T}\in\mathbb{R}^{M\times N}\).
- H : (N, N) array_likeΒΆ
Regularization matrix \(\mathbf{H} \in \mathbb{R}^{N\times N}\) which must be a symmetric positive semi-definite matrix.
- Q : (M, M) array_like, optionalΒΆ
Weighted matrix for the residual norm \(\mathbf{Q}\in\mathbb{R}^{M\times M}\), by default None (meaning \(\mathbf{Q} = \mathbf{I}\)). This matrix must be a symmetric positive semi-definite matrix.
- use_gpu: bool =
FalseΒΆ Whether to use GPU or not, by default False. If True, the
cupyfunctionalities is used instead ofnumpyandscipyones when calculating the inverse of a sparse matrix, singular value decomposition, inverted solution basis \(\tilde{\mathbf{V}}\), etc. Please ensurecupyis installed before using this option, otherwise anModuleNotFoundErrorwill be raised.- dtype: DTypeLike | None =
NoneΒΆ Data type of the matrix elements, by default same as the input matrix
T. In case of using GPU, the data type numpy.float32 is a little bit faster and saves memory.- progress: Progress | None =
NoneΒΆ rich.progress.Progressinstance for displaying computation status, by default None.- task_id: TaskID | None =
NoneΒΆ Task ID within progress to update with sub-step descriptions, by default None.
- Returns:
s ({ (r, ), (r-1, ) } ndarray) β Vector of singular values like \(\begin{bmatrix}\sigma_1&\cdots&\sigma_r\end{bmatrix}^\mathsf{T}\in\mathbb{R}^r\). If one set \(\mathbf{T}\) as a sparse matrix, \(r\) is reduced by 1 (i.e. \(r \to r-1\)) because of the use of
scipy.sparse.linalg.eigshfunction to calculate the singular values.U ((M, r) ndarray) β Left singular vectors like \(\mathbf{U}\in\mathbb{R}^{M\times r}\).
basis ((N, r) ndarray) β Inverted solution basis like \(\tilde{\mathbf{V}} \in \mathbb{R}^{N\times r}\).
B ((M, M) scipy.sparse.csr_array) β Matrix \(\mathbf{B}\) coming from \(\mathbf{Q} = \mathbf{B}^\mathsf{T}\mathbf{B}\). Only returned when \(\mathbf{Q}\) is given.
- Raises:
AttributeError β If
TorH(orQif given) do not have the attributesndimorshape.ValueError β If the dimensions or shapes of
T,H, orQ(if given) are not appropriate.
Examples
>>> s, U, basis = compute_svd(T, H)>>> s, U, basis, B = compute_svd(T, H, Q, dtype=np.float32, use_gpu=True)