The linalg Module

class mogp_emulator.linalg.cholesky.ChoInv(L)

Class representing inverse of the covariance matrix

Parameters:L (ndarray) – Factorized \({A}\) square matrix using pivoting. Assumes lower triangular factorization is used.
logdet()

Compute the log of the matrix determinant

Computes the log determinant of the matrix. This is simply twice the sum of the log of the diagonal of the factorized matrix.

Returns:Log determinant of the factorized matrix
Return type:float
solve(b)

Solve a Linear System factorized using Cholesky Decomposition

Solve a system \({Ax = b}\) where the matrix has been factorized using the cholesky function.

Parameters:b (ndarray) – Right hand side to be solved. Can be any array that satisfies the rules of the scipy cho_solve routine.
Returns:Solution to the appropriate linear system as a ndarray.
Return type:ndarray
solve_L(b)

Solve a Linear System with one component of the Cholesky Decomposition

Solve a system \({Lx = b}\) where the \(L\) matrix is the factorized matrix found using the cholesky function. This is effectively a matrix sqaure root.

Parameters:b (ndarray) – Right hand side to be solved. Can be any array that satisfies the rules of the scipy solve_triangular routine.
Returns:Solution to the appropriate linear system as a ndarray.
Return type:ndarray
class mogp_emulator.linalg.cholesky.ChoInvPivot(L, P)

Class representing Pivoted Cholesky factorized matrix

Parameters:
  • L (ndarray) – Factorized \({A}\) square matrix using pivoting. Assumes lower triangular factorization is used.
  • P (list or ndarray) – Pivot matrix, expressed as a list or 1D array of integers that is the same length as L. Must contain only nonzero integers as entries, with each number up to the length of the array appearing exactly once.
solve(b)

Solve a Linear System factorized using Pivoted Cholesky Decomposition

Solve a system \({Ax = b}\) where the matrix has been factorized using the pivot_cholesky function. The routine rearranges the order of the RHS based on the pivoting order that was used, and then rearranges back to the original ordering of the RHS when returning the array.

Parameters:b (ndarray) – Right hand side to be solved. Can be any array that satisfies the rules of the scipy cho_solve routine.
Returns:Solution to the appropriate linear system as a ndarray.
Return type:ndarray
solve_L(b)

Solve a Linear System with one component of the Pivoted Cholesky Decomposition

Solve a system \({Lx = b}\) where the matrix \(L\) is the factorized matrix found using the pivot_cholesky function. Can also solve a system which has been factorized using the regular Cholesky decomposition routine if P is the set of integers from 0 to the length of the linear system. The routine rearranges the order of the RHS based on the pivoting order that was used, and then rearranges back to the original ordering of the RHS when returning the array.

Parameters:b (ndarray) – Right hand side to be solved. Can be any array that satisfies the rules of the scipy cho_solve routine.
Returns:Solution to the appropriate linear system as a ndarray.
Return type:ndarray
mogp_emulator.linalg.cholesky.cholesky_factor(A, nugget, nugget_type)

Interface for Cholesky factorization

Calls the appropriate method given how the nugget is handled and returns the factorized matrix as a ChoInv class along with the nugget value

mogp_emulator.linalg.cholesky.fixed_cholesky(A)

Cholesky decomposition with fixed noise level

mogp_emulator.linalg.cholesky.jit_cholesky(A, maxtries=5)

Performs Jittered Cholesky Decomposition

Performs a Jittered Cholesky decomposition, adding noise to the diagonal of the matrix as needed in order to ensure that the matrix can be inverted. Adapted from code in GPy.

On occasion, the matrix that needs to be inverted in fitting a GP is nearly singular. This arises when the training samples are very close to one another, and can be averted by adding a noise term to the diagonal of the matrix. This routine performs an exact Cholesky decomposition if it can be done, and if it cannot it successively adds noise to the diagonal (starting with 1.e-6 times the mean of the diagonal and incrementing by a factor of 10 each time) until the matrix can be decomposed or the algorithm reaches maxtries attempts. The routine returns the lower triangular matrix and the amount of noise necessary to stabilize the decomposition.

Parameters:
  • A (ndarray) – The matrix to be inverted as an array of shape (n,n). Must be a symmetric positive definite matrix.
  • maxtries (int) – (optional) Maximum allowable number of attempts to stabilize the Cholesky Decomposition. Must be a positive integer (default = 5)
Returns:

Lower-triangular factored matrix (shape (n,n) and the noise that was added to the diagonal to achieve that result.

Return type:

tuple containing an ndarray and a float

mogp_emulator.linalg.cholesky.pivot_cholesky(A)

Pivoted cholesky decomposition routine

Performs a pivoted Cholesky decomposition on a square, potentially singular (i.e. can have collinear rows) covariance matrix. Rows and columns are interchanged such that the diagonal entries of the factorized matrix decrease from the first entry to the last entry. Any collinear rows are skipped, and the diagonal entries for those rows are instead replaced by a decreasing entry. This allows the factorized matrix to still be used to compute the log determinant in the same way, which is required to compute the marginal log likelihood/posterior in the GP fitting.

Returns the factorized matrix, and an ordered array of integer indices indicating the pivoting order. Raises an error if the decomposition fails.

Parameters:A (ndarray) – The matrix to be inverted as an array of shape (n,n). Must be a symmetric matrix (though can be singular).
Returns:Lower-triangular factored matrix (shape (n,n) an an array of integers indicating the pivoting order needed to produce the factorization.
Return type:tuple containing an ndarray of shape (n,n) of floats and a ndarray of shape (n,) of integers.