SparseCov#
- class sep241covariance.SparseCov(cov_func, threshold=1e-08)#
Bases:
objectA callable wrapper class for covariance functions that represents the covariance matrix sparsely under certain assumptions:
The covariance function k(x, y) must have a positive range, only dependent on the distance d = abs(x - y), and be strictly decreasing with respect to d. Further, the data must be strictly increasing, 1-dimensional, and contain integers (divisible by 1, not necessarily type int). Since the data is strictly increasing, for any data point x, as y becomes farther away in terms of index, d must be increasing. Since k(x, y) is strictly decreasing with respect to d, for any data point x, once we find a y for which k(x, y) <= threshold, every data point beyond y must also satisfy k(x, y) <= threshold.
So if we choose a threshold at which we consider the covariance negligible, the significant data will be clustered around the diagonal. So we can compute the covariance matrix in O(nm) time and memory, where n is the length of the data and m is the average number of points y satisfying k(x, y) <= threshold across all x.
- Parameters:
cov_func (pymc3.gp.cov.Covariance) – A pymc3 covariance function. Must have a positive range and be strictly decreasing with respect to the distance between points.
threshold (float, optional) – Do not calculate or represent any covariances k <= threshold. Defaults to 1e-8.
- auto_jitter(matrix)#
Calculates the jitter necessary to guarantee positive definiteness of the sparsified covariance matrix. Assumes that the matrix would be positive semi-definite before the sparsification.
- Parameters:
matrix (scipy.sparse.spmatrix) – The NxN sparsified covariance matrix.
- Returns:
jitter to guarantee positive definiteness.
- Return type:
float