compute_svd#
- cherab.inversion.core.compute_svd(T, H, Q=None, use_gpu=False, dtype=None, sp: Spinner | DummySpinner | None = None) tuple[Any, Any, Any] | tuple[Any, Any, Any, Any]Source#
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 mathmatical 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_gpubool,
optional 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
strornumpydtype,optional Data type of the matrix elements, by default numpy.float64. In case of using GPU, the data type numpy.float32 is a little bit faster and saves memory.
- sp
SpinnerorDummySpinner,optional Spinner object to show the progress of calculation, by default
DummySpinner.
- T(
- Returns:
- s{ (
r, ), (r-1, ) }array 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)array Left singular vectors like \(\mathbf{U}\in\mathbb{R}^{M\times r}\).
- basis(
N,r)array Inverted solution basis like \(\tilde{\mathbf{V}} \in \mathbb{R}^{N\times r}\).
- B(
M,M)scipy.sparse.csr_matrix Matrix \(\mathbf{B}\) coming from \(\mathbf{Q} = \mathbf{B}^\mathsf{T}\mathbf{B}\). Only returned when \(\mathbf{Q}\) is given.
- s{ (
Examples
s, U, basis = compute_svd(T, H) s, U, basis, B = compute_svd(T, H, Q, dtype=np.float32, use_gpu=True)