cherab.inversion.regularization.SVDΒΆ

class cherab.inversion.regularization.SVD(s: ArrayLike, U: ArrayLike, basis: ArrayLike, /, B: NDArray[float64] | _spbase[float64, tuple[int, int]] | None = None, *, data: ArrayLike | None = None)SourceΒΆ
class cherab.inversion.regularization.SVD(T: NDArray[float64] | _spbase[float64, tuple[int, int]], /, *, H: NDArray[float64] | _spbase[float64, tuple[int, int]] | None = None, Q: NDArray[float64] | _spbase[float64, tuple[int, int]] | None = None, data: ArrayLike | None = None, use_gpu: bool = False, dtype: DTypeLike | None = None, sp: Progress | None = None, task_id: TaskID | None = None)

Bases: _SVDBase

Tikhonov regularization solver based on Singular Value Decomposition.

This class inherits all methods from _SVDBase and uses the Tikhonov filter:

\[f_{\lambda,i} = \left(1 + \frac{\lambda}{\sigma_i^2}\right)^{-1}.\]

Pass a Criterion object (e.g. GCV or Lcurve) to solve() to determine the optimal regularization parameter.

Parameters:
*args

Same as _SVDBase.

**kwargs

Same as _SVDBase.

Examples

>>> from cherab.inversion import GCV, SVD, compute_svd

Prepare forward model and data:

>>> A = np.array([[1, 0], [0, 1], [1, 1]])
>>> b = np.array([1, 1, 2])

Then directly input them to SVD:

>>> svd = SVD(A, data=b)

or add data later:

>>> svd.data = b

Alternatively, compute SVD components first and then pass them to SVD:

>>> s, U, basis = compute_svd(A, np.eye(A.shape[1]))
>>> svd = SVD(s, U, basis, data=b)

When the SVD solver is ready, pass a criterion to solve() to find the optimal regularization parameter and the corresponding solution:

>>> gcv = GCV()
>>> sol, status = svd.solve(gcv)

Methods

eta(beta)

Squared regularization norm \(\eta\).

eta_diff(beta)

Differential of \(\eta\).

filter(beta)

Tikhonov filter factors \(f_{\lambda,i}\).

regularization_norm(beta)

Regularization norm: \(\sqrt{\eta} = \|\mathbf{x}_\lambda\|_\mathbf{H}\).

residual_norm(beta)

Residual norm: \(\sqrt{\rho} = \|\mathbf{T}\mathbf{x}_\lambda - \mathbf{b}\|_{\mathbf{Q}}\).

rho(beta)

Squared residual norm \(\rho\).

solution(beta)

Solution vector \(\mathbf{x}_\lambda\).

solve(criterion[,Β bounds,Β stepsize])

Solve the ill-posed inversion problem using criterion to select \(\lambda\).

Attributes

B

Matrix \(\mathbf{B}\) from \(\mathbf{Q} = \mathbf{B}^\mathsf{T}\mathbf{B}\).

U

Left singular vectors \(\mathbf{U}\).

basis

Inverted solution basis \(\tilde{\mathbf{V}}\).

bounds

\((\log_{10}\sigma_r^2, \log_{10}\sigma_1^2)\).

data

Given data for inversion calculation \(\mathbf{b}\).

lambda_opt

Optimal regularization parameter, set after solve() is executed.

s

Singular values \(\mathbf{s}\).

property B : NDArray[float64] | _spbase[float64, tuple[int, int]] | NoneSourceΒΆ

Matrix \(\mathbf{B}\) from \(\mathbf{Q} = \mathbf{B}^\mathsf{T}\mathbf{B}\).

If users do not specify the matrix \(\mathbf{B}\), this property is None.

property U : ndarray[tuple[Any, ...], dtype[float64]]SourceΒΆ

Left singular vectors \(\mathbf{U}\).

Left singular vectors form a matrix containing column vectors like \(\mathbf{U}=\begin{bmatrix}\mathbf{u}_1 & \cdots &\mathbf{u}_r\end{bmatrix}\in\mathbb{R}^{M\times r}\).

property basis : ndarray[tuple[Any, ...], dtype[float64]]SourceΒΆ

Inverted solution basis \(\tilde{\mathbf{V}}\).

The inverted solution basis is a matrix containing column vectors like \(\tilde{\mathbf{V}}=\begin{bmatrix}\tilde{\mathbf{v}}_1&\cdots&\tilde{\mathbf{v}}_r\end{bmatrix}\in\mathbb{R}^{N\times r}\).

property bounds : tuple[float, float]SourceΒΆ

\((\log_{10}\sigma_r^2, \log_{10}\sigma_1^2)\).

Type:

Default bounds of \(\log_{10}\lambda\)

property data : ndarray[tuple[Any, ...], dtype[float64]] | NoneSourceΒΆ

Given data for inversion calculation \(\mathbf{b}\).

The given data is a vector array like \(\mathbf{b} \in \mathbb{R}^M\).

eta(beta: float) floatSourceΒΆ

Squared regularization norm \(\eta\).

\(\eta\) can be expressed with SVD components as follows:

\[\begin{split}\eta &= \|\mathbf{x}_\lambda\|_\mathbf{H}^2\\ &= \| \mathbf{F}_\lambda\mathbf{S}^{-1} \mathbf{U}^\mathsf{T}\mathbf{B}\mathbf{b} \|^2\end{split}\]
Parameters:
beta: floatΒΆ

Regularization parameter.

Returns:

float – Squared regularization norm \(\eta\).

eta_diff(beta: float) floatSourceΒΆ

Differential of \(\eta\).

\(\eta'\equiv\frac{\partial\eta}{\partial\lambda}\) can be calculated with SVD components as follows:

\[\eta' = \frac{2}{\lambda} (\mathbf{U}^\mathsf{T}\mathbf{B}\mathbf{b})^\mathsf{T} (\mathbf{F}_\lambda - \mathbf{I}_r) \mathbf{F}_\lambda^2\mathbf{S}^{-2}\ \mathbf{U}^\mathsf{T}\mathbf{B}\mathbf{b}.\]
Parameters:
beta: floatΒΆ

Regularization parameter \(\lambda\).

Returns:

float – Differential of \(\eta\) with respect to \(\lambda\).

filter(beta: float) ndarray[tuple[Any, ...], dtype[float64]]SourceΒΆ

Tikhonov filter factors \(f_{\lambda,i}\).

The filter factors are diagonal elements of the filter matrix \(\mathbf{F}_\lambda\), and can be expressed with SVD components as follows:

\[f_{\lambda, i} = \left( 1 + \frac{\lambda}{\sigma_i^2} \right)^{-1}.\]
Parameters:
beta: floatΒΆ

Regularization parameter \(\lambda\).

Returns:

(r,) ndarray – 1-D array containing filter factors, the length of which is the same as the number of singular values.

property lambda_opt : float | NoneSourceΒΆ

Optimal regularization parameter, set after solve() is executed.

regularization_norm(beta: float) floatSourceΒΆ

Regularization norm: \(\sqrt{\eta} = \|\mathbf{x}_\lambda\|_\mathbf{H}\).

Parameters:
beta: floatΒΆ

Regularization parameter.

Returns:

float – Regularization norm \(\sqrt{\eta}\).

residual_norm(beta: float) floatSourceΒΆ

Residual norm: \(\sqrt{\rho} = \|\mathbf{T}\mathbf{x}_\lambda - \mathbf{b}\|_{\mathbf{Q}}\).

Parameters:
beta: floatΒΆ

Regularization parameter.

Returns:

float – Residual norm \(\sqrt{\rho}\).

rho(beta: float) floatSourceΒΆ

Squared residual norm \(\rho\).

\(\rho\) can be expressed with SVD components as follows:

\[\begin{split}\rho &= \| \mathbf{T}\mathbf{x}_\lambda - \mathbf{b} \|_\mathbf{Q}^2\\ &= \| (\mathbf{F}_\lambda - \mathbf{I}_r) \mathbf{U}^\mathsf{T}\mathbf{B}\mathbf{b} \|^2.\end{split}\]
Parameters:
beta: floatΒΆ

Regularization parameter.

Returns:

float – Squared residual norm \(\rho\).

property s : ndarray[tuple[Any, ...], dtype[float64]]SourceΒΆ

Singular values \(\mathbf{s}\).

Singular values form a vector array like \(\mathbf{s} = \begin{bmatrix}\sigma_1 & \cdots & \sigma_r\end{bmatrix}^\mathsf{T} \in \mathbb{R}^r\).

solution(beta: float) ndarraySourceΒΆ

Solution vector \(\mathbf{x}_\lambda\).

The solution vector \(\mathbf{x}_\lambda\) can be expressed with SVD components as

\[\mathbf{x}_\lambda = \tilde{\mathbf{V}} \mathbf{F}_\lambda \mathbf{S}^{-1} \mathbf{U}^\mathsf{T}\mathbf{B}\mathbf{b}.\]
Parameters:
beta: floatΒΆ

Regularization parameter.

Returns:

(N, ) array – Solution vector \(\mathbf{x}_\lambda\).

solve(criterion: Criterion, bounds: Collection[float | None] | None = None, stepsize: float = 10, **kwargs: Any) tuple[ndarray, Any]SourceΒΆ

Solve the ill-posed inversion problem using criterion to select \(\lambda\).

Parameters:
criterion: CriterionΒΆ

A Criterion instance (e.g. GCV, Lcurve, etc.).

bounds: Collection[float | None] | None = NoneΒΆ

Boundary pair (log10_lower, log10_upper) for the optimization, by default bounds. Either element may be None to use the default limit.

stepsize: float = 10ΒΆ

Step-size for basinhopping, by default 10.

**kwargs: AnyΒΆ

Additional keyword arguments forwarded to the criterion’s optimize method.

Returns: