eispy2d.regularization package#

Submodules#

eispy2d.regularization.regularization module#

class eispy2d.regularization.regularization.ConjugatedGradient(iterations)#

Bases: Regularization

__init__(iterations)#

Initialize Conjugated Gradient regularization.

Parameters:

iterations (int) – Number of iterations for the CG method.

solve(K, y)#

Solve the linear system using Conjugated Gradient method.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The CG method solves the normal equations: \(K^*K x = K^*y\) using an iterative approach.

class eispy2d.regularization.regularization.Landweber(iterations)#

Bases: Regularization

__init__(iterations)#

Initialize Landweber regularization.

Parameters:

iterations (int) – Number of iterations for the Landweber method.

solve(K, y)#

Solve the linear system using Landweber iteration.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The Landweber iteration is given by:

\[x_{n+1} = x_n + a K^*(y - Kx_n)\]

where \(a = 1/\|K\|^2\).

class eispy2d.regularization.regularization.LeastSquares(cutoff=None)#

Bases: Regularization

__init__(cutoff=None)#

Initialize Least Squares regularization with spectral cutoff.

Parameters:

cutoff (float, optional) – Cutoff threshold for singular values (rcond parameter). If None, uses default from numpy.linalg.lstsq.

solve(K, y)#

Solve the linear system using least squares with spectral cutoff.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

Uses numpy.linalg.lstsq with specified rcond cutoff for regularization by truncating small singular values.

class eispy2d.regularization.regularization.Regularization#

Bases: ABC

abstractmethod solve(K, y)#
class eispy2d.regularization.regularization.SingularValueDecomposition(tikhonov=0.0, cutoff=0.0)#

Bases: Regularization

__init__(tikhonov=0.0, cutoff=0.0)#

Initialize SVD-based regularization.

Parameters:
  • tikhonov (float, default: 0.0) – Tikhonov regularization parameter.

  • cutoff (float, default: 0.0) – Cutoff threshold for singular values.

solve(K=None, y=None, U=None, s=None, V=None)#

Solve the linear system using SVD-based regularization.

Parameters:
  • K (numpy.ndarray, optional) – Coefficient matrix (kernel) with shape (M, N). Required if U, s, V not provided.

  • y (numpy.ndarray, optional) – Right-hand side vector or matrix with shape (M,) or (M, P).

  • U (numpy.ndarray, optional) – Left singular vectors matrix from SVD.

  • s (numpy.ndarray, optional) – Singular values vector from SVD.

  • V (numpy.ndarray, optional) – Right singular vectors matrix from SVD.

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The solution is computed using singular value decomposition:

\[x = \sum_{n} \frac{s_n}{s_n^2 + \alpha} (U_n^* y) V_n\]

where \(\alpha\) is the Tikhonov parameter and singular values below cutoff are truncated.

class eispy2d.regularization.regularization.Tikhonov(choice, parameter=None)#

Bases: Regularization

__init__(choice, parameter=None)#

Initialize Tikhonov regularization.

Parameters:
  • choice (int, float, or {'fixed', 'mozorov', 'lcurve'}) – Regularization parameter selection strategy: - If int or float: fixed regularization parameter value. - ‘fixed’: use a fixed parameter value (must provide parameter). - ‘mozorov’: use Morozov’s discrepancy principle. - ‘lcurve’: use L-curve criterion.

  • parameter (float, optional) – Fixed regularization parameter value (required if choice=’fixed’).

Raises:
solve(K, y)#

Solve the linear system using Tikhonov regularization.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel) with shape (M, N).

  • y (numpy.ndarray) – Right-hand side vector or matrix with shape (M,) or (M, P).

Returns:

Solution vector or matrix with shape (N,) or (N, P).

Return type:

numpy.ndarray

Notes

The solution is computed as: - For fixed parameter: \(x = (K^*K + \alpha I)^{-1}K^*y\) - For Morozov: automatically selects \(\alpha\) using discrepancy principle - For L-curve: automatically selects \(\alpha\) using L-curve criterion

eispy2d.regularization.regularization.conjugated_gradient(K, y, iterations)#

Perform the Conjugated-Gradient (CG) regularization.

Solve the linear ill-posed system through CG regularization [1]_.

Parameters:
  • K (numpy.ndarray) – The coefficient matrix (kernel).

  • y (numpy.ndarray) – The right-hand-side array.

  • iterations (int) – Number of iterations.

Returns:

The regularized solution vector.

Return type:

numpy.ndarray

References

eispy2d.regularization.regularization.landweber(K, y, x, iterations)#

Perform the Landweber regularization.

Solve the linear ill-posed system through Landweber regularization [1]_. The algorithm formula is:

\[x_{n+1} = x_n + a K^*(y - K x_n)\]
Parameters:
  • K (numpy.ndarray) – The coefficient matrix (kernel).

  • y (numpy.ndarray) – The right-hand-side array.

  • x (numpy.ndarray) – Initial guess for the solution.

  • iterations (int) – Number of iterations.

Returns:

The regularized solution vector.

Return type:

numpy.ndarray

References

eispy2d.regularization.regularization.lcurve_choice(K, y, bounds=(-20, 0), number_terms=21)#

Determine the regularization parameter through L-curve.

The regularization parameter is determined according to the L-curve. The L-curve is the graph between error and solution norms. The values are normalized and the chosen point is the one in which its distance from (0, 0) is minimum.

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel).

  • y (numpy.ndarray) – Right-hand-side array.

  • bounds (2-tuple, default: (-20, 0)) – Minimum and maximum value of the exponential form of the regularization parameter (log10 scale).

  • number_terms (int, default: 21) – Number of samples on the L-curve.

Returns:

Optimal regularization parameter \(\alpha\).

Return type:

float

eispy2d.regularization.regularization.least_squares(K, y, cutoff)#

Return the Spectral Cut-off solution to a linear matrix equation.

See explanation at https://numpy.org/doc/stable/reference/generated/numpy.linalg.lstsq.html

Parameters:
  • K (numpy.ndarray) – The coefficient matrix (kernel).

  • y (numpy.ndarray) – The right-hand-side array.

  • cutoff (float) – Truncation level (rcond) for singular values.

Returns:

The least squares solution vector.

Return type:

numpy.ndarray

eispy2d.regularization.regularization.mozorov_choice(K, y, delta=0.001)#

Apply the Discrepancy Principle of Morozov [1].

Compute the regularization parameter according to the starting guess of Newton’s method for solving the Discrepancy Principle of Morozov defined in [1].

Parameters:
  • K (numpy.ndarray) – Coefficient matrix (kernel).

  • y (numpy.ndarray) – Right-hand-side array.

  • delta (float, default: 1e-3) – Noise level of the problem.

Returns:

Optimal regularization parameter \(\alpha\).

Return type:

float

Notes

The Discrepancy Principle of Morozov is defined according to the zero of the following monotone function:

\[\phi(\alpha) = \|Kx^{\alpha,\delta}-y^{\delta}\|^2 - \delta^2\]

The initial guess of Newton’s method to determine the zero is:

\[\alpha = \frac{\delta\|K\|^2}{\|y^\delta\| - \delta}\]

References

eispy2d.regularization.regularization.svd(K=None, y=None, alpha=None, min_sv=None, U=None, s=None, V=None)#

Solve linear system using SVD with Tikhonov regularization and spectral cutoff.

Parameters:
  • K (numpy.ndarray, optional) – Coefficient matrix (kernel). If provided, computes SVD.

  • y (numpy.ndarray, optional) – Right-hand side vector.

  • alpha (float, optional) – Tikhonov regularization parameter.

  • min_sv (float, optional) – Minimum singular value threshold (spectral cutoff).

  • U (numpy.ndarray, optional) – Left singular vectors (if precomputed).

  • s (numpy.ndarray, optional) – Singular values (if precomputed).

  • V (numpy.ndarray, optional) – Right singular vectors (if precomputed).

Returns:

If K and y provided: solution vector. If only K provided: (U, s, V) SVD components. If U, s, V, y provided: solution vector.

Return type:

numpy.ndarray or tuple

Notes

The solution is computed as:

\[x = \sum_{n} \frac{s_n}{s_n^2 + \alpha} (U_n^* y) V_n\]

where singular values below min_sv are truncated.

eispy2d.regularization.regularization.tikhonov(K, y, alpha)#

Perform the Tikhonov regularization.

Solve the linear ill-posed system through Tikhonov regularization [1]_. The solution is given according to:

\[(K^*K + \alpha I)x = K^*y\]
Parameters:
  • K (numpy.ndarray) – The coefficient matrix (kernel).

  • y (numpy.ndarray) – The right-hand-side array.

  • alpha (float) – Regularization parameter.

Returns:

The regularized solution vector.

Return type:

numpy.ndarray

References

Module contents#