Solvers¶
There are currently two different GP solvers included with George using
different libraries for doing linear algebra.
Both of the solvers implement the same API and should (up to some tolerance)
give the same answers on the same datasets.
A solver is just a class that takes a Kernel
and that exposes 3
methods:
compute
— to compute and factorize the kernel matrix,apply_inverse
— to left-multiply the input by the covariance matrix \(C^{-1}\,b\) (actually implemented by solving the system \(C\,x = b\)), andapply_sqrt
— to apply the (Cholesky) square root of the covariance.
The solvers also provide the properties computed
and log_determinant
.
The simplest solver provided by George (BasicSolver
) uses scipy’s
Cholesky implementation
and the second implementation (HODLRSolver
) uses Sivaram
Amambikasaran’s HODLR algorithm to do the
linear algebra in \(\mathcal{O}(N\,\log^2 N)\) instead of
\(\mathcal{O}(N^3)\).
By default, George uses the BasicSolver
but the HODLRSolver
can be used as follows:
import george
kernel = ...
gp = george.GP(kernel, solver=george.HODLRSolver)
The HODLRSolver
is probably best for most one-dimensional problems
and some large multi-dimensional problems but it doesn’t (in general) scale
well with the number of input dimensions.
In practice, it’s worth trying both solvers on your specific problem to see
which runs faster.
Basic Solver¶
-
class
george.
BasicSolver
(kernel)¶ This is the most basic solver built using
scipy.linalg.cholesky()
.- kernel (george.kernels.Kernel): A subclass of
Kernel
specifying the kernel function.
-
apply_inverse
(y, in_place=False)¶ Apply the inverse of the covariance matrix to the input by solving
\[K\,x = y\]- Parameters
y (ndarray[nsamples] or ndadrray[nsamples, nrhs]) – The vector or matrix \(y\).
in_place (Optional[bool]) – Should the data in
y
be overwritten with the result \(x\)? (default:False
)
-
apply_sqrt
(r)¶ Apply the Cholesky square root of the covariance matrix to the input vector or matrix.
- Parameters
(ndarray[nsamples] or ndarray[nsamples (r) – The input vector or matrix.
nrhs] – The input vector or matrix.
-
compute
(x, yerr)¶ Compute and factorize the covariance matrix.
- Parameters
x (ndarray[nsamples, ndim]) – The independent coordinates of the data points.
yerr (ndarray[nsamples] or float) – The Gaussian uncertainties on the data points at coordinates
x
. These values will be added in quadrature to the diagonal of the covariance matrix.
-
property
computed
¶ A flag indicating whether or not the covariance matrix was computed and factorized (using the
compute()
method).
-
dot_solve
(y)¶ Compute the inner product of a vector with the inverse of the covariance matrix applied to itself:
\[y\,K^{-1}\,y\]- Parameters
y (ndarray[nsamples]) – The vector \(y\).
-
get_inverse
()¶ Get the dense inverse covariance matrix. This is used for computing gradients, but it is not recommended in general.
- kernel (george.kernels.Kernel): A subclass of
HODLR Solver¶
-
class
george.
HODLRSolver
(kernel, min_size=100, tol=0.1, seed=42)¶ A solver using Sivaram Amambikasaran’s HODLR algorithm to approximately solve the GP linear algebra in \(\mathcal{O}(N\,\log^2 N)\).
- Parameters
kernel – An instance of a subclass of
kernels.Kernel
.min_size – (optional[int]) The block size where the solver switches to a general direct factorization algorithm. This can be tuned for platform and problem specific performance and accuracy. As a general rule, larger values will be more accurate and slower, but there is some overhead for very small values, so we recommend choosing values in the hundreds. (default:
100
)tol – (optional[float]) The precision tolerance for the low-rank approximation. This value is used as an approximate limit on the Frobenius norm between the low-rank approximation and the true matrix when reconstructing the off-diagonal blocks. Smaller values of
tol
will generally give more accurate results with higher computational cost. (default:0.1
)seed – (optional[int]) The low-rank approximation method within the HODLR algorithm is not deterministic and, without a fixed seed, the method can give different results for the same matrix. Therefore, we require that the user provide a seed for the random number generator. (default:
42
)
-
apply_inverse
(y, in_place=False)¶ Apply the inverse of the covariance matrix to the input by solving
\[K\,x = y\]- Parameters
y (ndarray[nsamples] or ndadrray[nsamples, nrhs]) – The vector or matrix \(y\).
in_place (Optional[bool]) – Should the data in
y
be overwritten with the result \(x\)? (default:False
)
-
apply_sqrt
(r)¶ Apply the Cholesky square root of the covariance matrix to the input vector or matrix.
- Parameters
(ndarray[nsamples] or ndarray[nsamples (r) – The input vector or matrix.
nrhs] – The input vector or matrix.
-
compute
(x, yerr)¶ Compute and factorize the covariance matrix.
- Parameters
x (ndarray[nsamples, ndim]) – The independent coordinates of the data points.
yerr (ndarray[nsamples] or float) – The Gaussian uncertainties on the data points at coordinates
x
. These values will be added in quadrature to the diagonal of the covariance matrix.
-
property
computed
¶ A flag indicating whether or not the covariance matrix was computed and factorized (using the
compute()
method).
-
dot_solve
(y)¶ Compute the inner product of a vector with the inverse of the covariance matrix applied to itself:
\[y\,K^{-1}\,y\]- Parameters
y (ndarray[nsamples]) – The vector \(y\).
-
get_inverse
()¶ Get the dense inverse covariance matrix. This is used for computing gradients, but it is not recommended in general.