spleaf.Spleaf#
- class spleaf.Spleaf(A, U, V, phi, offsetrow, b, F, copy=False)#
Symmetric S+LEAF (semiseparable + leaf) matrix.
A symmetric S+LEAF matrix \(C\) is defined as
\[C = A + \mathrm{tril}(U V^T) + \mathrm{triu}(V U^T) + F,\]where \(A\) is the diagonal part, the matrices \(U\) and \(V\) represent the symmetric semiseparable part, and \(F\) is the symmetric leaf part of \(C\).
A Cholesky decomposition of \(C\) is performed
\[C = L D L^T,\]where \(D\) is a diagonal matrix and \(L\) is a lower triangular matrix which itself decomposes as
\[L = \mathbb{I} + \mathrm{tril}(U W^T) + G,\]with \(U\) and \(W\) representing the strictly lower triangular semiseparable part, and \(G\) the strictly lower triangular leaf part of \(L\).
- Parameters:
- A(n,) ndarray
Diagonal of the matrix.
- U, V(n, r) ndarrays
Symmetric semiseparable part of the matrix, with preconditioning matrix phi. At row i, column j < i, the semiseparable part is
np.sum(U[i] * V[j] * np.prod(phi[j:i-1], axis=0))
- phi(n-1, r) ndarray
Preconditioning matrix for the semiseparable part.
- offsetrow(n,) ndarray
Offsets for the storage of each row in F (leaf part).
- b(n,) ndarray
Number of non-zero values left to the diagonal at each row of F.
- Fndarray
Symmetric leaf part of the matrix, stored in strictly lower triangular form, and in row major order. For
i-b[i] <= j < i
, the non-zero value \(F_{i,j}\) is stored at indexoffsetrow[i] + j
in F. (i.e. offsetrow should be defined asoffsetrow = np.cumsum(b-1) + 1
).- copybool
Whether to copy arrays.
- Attributes:
- nint
Size of the matrix.
- rint
Rank of the semiseparable part (number of components).
- A, U, V, phi, offsetrow, b, Fndarrays
See parameters.
- D(n,) ndarray
Diagonal part of the Cholesky decomposition of the matrix.
- W(n,r) ndarray
Semiseparable part of the Cholesky decomposition of the matrix.
- Gndarray
Leaf part of the Cholesky decomposition of the matrix (stored in the same way as F).
Methods
chi2
(y)Compute \(\chi^2 = y^T C^{-1} y\) for a given vector of residuals \(y\).
chi2_grad
(*args, **kwargs)Compute the gradient of the \(\chi^2\) (
chi2()
) with respect to the residuals and to the initial parameters (seegrad_param()
).Backward propagation of the gradient for the Cholesky decomposition.
conditional
(y, U2, V2, phi2, ref2left, ...)Conditional mean and covariance at new abscissas of the Gaussian process corresponding to the semiseparable part of the covariance matrix, knowning the observed values \(y\).
conditional_derivative
(y, dU2, V2, dV2, ...)Conditional mean and covariance at new abscissas of the derivative of the Gaussian process corresponding to the semiseparable part of the covariance matrix, knowning the observed values \(y\).
dotL
(x[, copy])Compute \(y = L x\).
dotLT
(x[, copy])Compute \(y = L^T x\).
dotLT_back
(grad_y)Backward propagation of the gradient for
dotLT()
.dotL_back
(grad_y)Backward propagation of the gradient for
dotL()
.expand
()Expand the matrix as a full (n x n) matrix.
Expand the inverse of the matrix as a full (n x n) matrix.
Expand \(L^{-1}\) as a full (n x n) matrix.
expandL
()Expand \(L\) as a full (n x n) matrix.
grad_param
(*args, **kwargs)Gradient of a function with respect to the initial parameters (A, U, V, phi, F), after a call to
cholesky_back()
.Initialize (or reinitialize) the backward propagation of the gradient.
logdet
()Compute the (natural) logarithm of the determinant of the matrix.
loglike
(y)Compute the (natural) logarithm of the likelihood for a given vector of residuals \(y\).
loglike_grad
(*args, **kwargs)Compute the gradient of the log-likelihood (
loglike()
) with respect to the residuals and to the initial parameters (seegrad_param()
).sample
([nreal])Generate random samples from the covariance matrix.
self_conditional
(y[, calc_cov, index])Compute the conditional mean and covariance of the Gaussian process corresponding to the semiseparable part of the covariance matrix, knowning the observed values \(y\).
self_conditional_derivative
(y[, dU, dV, ...])Conditional mean and covariance of the derivative of the Gaussian process corresponding to the semiseparable part of the covariance matrix, knowning the observed values \(y\).
set_param
(A, U, V, phi, F[, copy])Update the initial parameters (A, U, V, phi, F) and recompute the Cholesky decomposition of the matrix.
solveL
(y[, copy])Solve for \(x = L^{-1} y\).
solveLT
(y[, copy])Solve for \(x = L^{-T} y\).
solveLT_back
(grad_x)Backward propagation of the gradient for
solveLT()
.solveL_back
(grad_x)Backward propagation of the gradient for
solveL()
.sqD
()Compute the square-root of D.