pyimcom.lakernel
Linear algebra kernels to solve linear systems.
Classes
- _LAKernel
Abstract base class of linear algebra kernels.
- EigenKernel
LA kernel using eigendecomposition.
- CholKernel
LA kernel using Cholesky decomposition.
- IterKernel
LA kernel using iterative method.
- EmpirKernel
Fake LA kernel using empirical relation.
Functions
- conjugate_gradient
Simplified version of scipy.sparse.linalg.cg.
- _extract_submatrix
Extract a submatrix from a symmetric matrix.
- _extract_subvector
Extract a subvector from a vector.
- _assign_subvector
Assign values to a subvector of a vector.
Classes
Abstract base class of linear algebra kernels. |
|
LA kernel using eigendecomposition. |
|
LA kernel using Cholesky decomposition. |
|
LA kernel using iterative method. |
|
Fake LA kernel using empirical relation. |
Functions
|
Simplified version of scipy.sparse.linalg.cg. |
|
Extract a submatrix from a symmetric matrix. |
|
Extract a subvector from a vector. |
|
Assign values to a subvector of a vector. |
Module Contents
- class _LAKernel(outst)[source]
Abstract base class of linear algebra kernels.
- Parameters:
outst (coadd.OutStamp) – Output postage stamp to which this kernel instance is attached.
- __call__() None[source]
Solve linear systems.
- Return type:
None
Notes
This produces the following arrays for self.outst:
T = coaddition matrix, shape = (n_out, m, n)
UC = fractional squared error in PSF, shape = (n_out, m)
Sigma = output noise amplification, shape = (n_out, m)
kappa = Lagrange multiplier per output pixel, shape = (n_out, m)
- class EigenKernel(outst)[source]
Bases:
_LAKernelLA kernel using eigendecomposition.
- _call_multi_kappa(nbis: int = 13) None[source]
Solve linear systems for multiple kappa nodes.
- Parameters:
nbis (int, optional) – Number of bisections.
- Return type:
None
Notes
Based on pyimcom_lakernel.CKernelMulti of furry-parakeet. This one generates multiple images. there can be n_out target PSFs.
- class CholKernel(outst)[source]
Bases:
_LAKernelLA kernel using Cholesky decomposition.
- static _cholesky_wrapper(AA: numpy.array, di: tuple[numpy.array, numpy.array], A: numpy.array) numpy.array[source]
Wrapper for cholesky, rectifies negative eigenvalue(s) if needed.
- Parameters:
AA (np.array) – System matrix A plus kappa times noise; shape (n,n).
di ((np.array, np.array)) – Indices to main diagonal of AA; each has shape (n,).
A (np.array) – Original system matrix; shape (n,n).
- Returns:
L – Cholesky results; shape (n,n).
- Return type:
np.array
- conjugate_gradient(A: numpy.array, b: numpy.array, rtol: float = 0.0015, maxiter: int = 30) numpy.array[source]
Simplified version of scipy.sparse.linalg.cg.
- Parameters:
A (np.array) – System matrix A, shape (n,n)
b (np.array) – Column vector b, shape (n,).
rtol (float, optional) – Relative tolerance.
maxiter (int, optional) – Maximum number of iterations.
- Returns:
x – Solution vector b, shape (n,).
- Return type:
np.array
- _extract_submatrix(mat_orig: numpy.array, selection: numpy.array) numpy.array[source]
Extract a submatrix from a symmetric matrix.
- _extract_subvector(vec_orig: numpy.array, selection: numpy.array) numpy.array[source]
Extract a subvector from a vector.
- _assign_subvector(vec_left: numpy.array, vec_right: numpy.array, selection: numpy.array) None[source]
Assign values to a subvector of a vector.
- Parameters:
vec_left (np.array) – Vector to be assigned to.
vec_right (np.array) – Subvector of values to assign.
selection (np.array) – Integer array of indices of elements to assign to; same length as vec_left.
- Return type:
None
- class IterKernel(outst)[source]
Bases:
_LAKernelLA kernel using iterative method.
- static _iterative_wrapper(AA: numpy.array, mBhalf: numpy.array, relevant_matrix: numpy.array, rtol: float = 0.0015, maxiter: int = 30) numpy.array[source]
Wrapper for conjugate gradient method.
- Parameters:
AA (np.array) – System matrix A plus kappa times noise. Shape (n,n).
mBhalf (np.array) – System matrix -B/2 (for a single target PSF). Shape (n,n).
relevant_matrix (np.array) – Boolean array indicating whether to use an input pixel for an output pixel. Shape (m,n).
rtol (float, optional) – Relative tolerance.
maxiter (int, optional) – Maximum number of iteration.
- Returns:
Output T matrix (for a single target PSF). Shape (m,n).
- Return type:
np.array
- _call_single_kappa(exact_UC: bool = False) None[source]
Solve linear systems for single kappa node.
- Parameters:
exact_UC (bool, optional) – Whether to use exact expression for U/C. The default is False, as this is slow and the gain is very small.
- Return type:
None
- _call_multi_kappa(exact_UC: bool = True) None[source]
Solve linear systems for multiple kappa nodes.
- Parameters:
exact_UC (bool, optional) – Whether to use exact expression for U/C. The default is True, as the approximation does not work. KC: Please avoid this whenever possible as this is SUPER slow.
- Return type:
None