gsum.helpers.
cartesian
(*arrays)[source]¶Makes the Cartesian product of arrays.
1D arrays where earlier arrays loop more slowly than later ones
The cartesian product
gsum.helpers.
coefficients
(y, ratio, ref=1, orders=None)[source]¶Returns the coefficients of a power series
The orders at which y was computed. Defaults to 0, 1, …, n_curves-1
gsum.helpers.
partials
(coeffs, ratio, ref=1, orders=None)[source]¶Returns the partial sums of a power series given the coefficients
The ``k``th partial sum is given by
The n lowest order coefficients in a power series
The ratio variable that is raised to the nth power in the nth term of the sum
The overall multiplicative scale of the series, default is 1
The orders corresponding to the given coefficients. All not given
orders are assumed to have coefficients equal to zero. The default
assumes that the n lowest order coefficients are given:
[0, 1, ..., n_curves-1]
.
The partial sums
gsum.helpers.
geometric_sum
(x, start, end, excluded=None)[source]¶The geometric sum of x from i=start to i=end (inclusive)
with the i in exclude excluded from the sum.
The value to be summed
The start index of the sum
The end index of the sum (inclusive)
The indices to exclude from the sum
The geometric sum
gsum.helpers.
predictions
(dist, dob=None)[source]¶Return the mean and set of degree of belief intervals for a distribution
If dob is None, just the mean is returned, else a tuple of the mean and degree of belief intervals is returned. The interval array is shaped (len(dob), 2, len(mean)) and is then squeezed to remove all axes of length 1.
gsum.helpers.
gaussian
(X, Xp=None, ls=1)[source]¶A gaussian correlation function
gsum.helpers.
hpd
(dist, alpha, *args)[source]¶Returns the highest probability density interval of scipy dist.
Inspired by this answer https://stackoverflow.com/a/25777507
gsum.helpers.
kl_gauss
(mu0, cov0, mu1, cov1=None, chol1=None)[source]¶The Kullbeck-Liebler divergence between two mv Gaussians
The divergence from \(\mathcal{N}_1\) to \(\mathcal{N}_0\) is given by
which can be thought of as the amount of information lost when \(\mathcal{N}_1\) is used to approximate \(\mathcal{N}_0\).
The mean of the posterior
The covariance of the posterior
The mean of the prior
The covariance of the prior
The Cholesky decomposition of the prior
The KL divergence
Exactly one of cov1 or chol1 must be given
gsum.helpers.
default_attributes
(**kws)[source]¶Sets None or empty *args/**kwargs arguments to attributes already stored in a class.
This is a handy decorator to avoid if statements at the beginning of method calls:
x = self.x
…
but is particularly useful when the function uses a cache to avoid unnecessary computations. Caches don’t recognize when the attributes change, so could result in incorrect returned values. This decorator must be put outside of the cache decorator though.
The key must match the parameter name in the decorated function, and the value corresponds to the name of the attribute to use as the default
gsum.helpers.
VariogramFourthRoot
(X, z, bin_bounds)[source]¶Computes the empirical semivariogram and uncertainties via the fourth root transformation.
Based mostly on the theory developed in Bowman & Crujeiras (2013) and Cressie & Hawkins (1980). Their original code was implemented in the sm R package, but was rewritten in Python as a check and to gain a better understanding of the implementation. There are unresolved discrepancies with their code to date.
The shaped input locations of the observed function.
The function values
The boundaries of the bins for the distances between the inputs. The bin location is computed as the average of all distances within the bin.
compute
(self, rt_scale=False)[source]¶Returns the mean semivariogram and approximate 68% confidence intervals.
Can be given on the 4th root scale or the variogram scale (default).
Returns results on 4th root scale if True (default is False)
The semivariogram estimate and its lower and upper 68% bands
corr_ijkl
(self, i, j, k, l)[source]¶The correlation between \(\sqrt(|Z_i - Z_j|)\) and \(\sqrt(|Z_k - Z_l|)\), estimated by gamma tilde
This is estimated using gamma tilde, the estimate of the variogram via the 4th root transform. Because the estimate can exceed the bounds [-1, 1], any correlation outside this range is manually set to +/-1.
cov_ijkl
(self, i, j, k, l)[source]¶The covariance between \(\sqrt(|Z_i - Z_j|)\) and \(\sqrt(|Z_k - Z_l|)\), estimated by gamma tilde
Only estimates the correlation when (i,j) != (k,l), otherwise uses 1.
rho_ijkl
(self, i, j, k, l)[source]¶The correlation between \((Z_i - Z_j)\) and \((Z_k - Z_l)\), estimated by gamma tilde
var_ij
(self, i, j)[source]¶The variance of sqrt(|Z_i - Z_j|), estimated by gamma tilde
gsum.helpers.
hpd_pdf
(pdf, alpha, x, x0=None, **kwargs)[source]¶Returns the highest probability density interval given the pdf.
Inspired by this answer https://stackoverflow.com/a/22290087