Repository navigation
ENH Kernel covariance - #4726
ENH Kernel covariance #4726
Conversation
|
This pull request introduces 1 alert when merging dcc7e6d into 8928f8d - view on LGTM.com new alerts:
Comment posted by LGTM.com |
| return np.exp(-(x - loc)**2 / (2 * self.bw2)).sum(1) / self.bwk | ||
|
|
||
|
|
||
| def kernel_covariance(exog, loc, group, kernel=None, bw=None): |
|
For now, I have mainly a question about the use case for this and related PRs: |
|
Regarding sparse versus dense, this returns a function cov(x, y) that computes the cross-covariance matrix between Z(x) and Z(y), where Z(.) is a process on R^p (possibly with repeated independent observations). The dimension of Z(.) will generally be small (e.g. for human subject studies, height, weight, blood pressure at age x). cov(x, y) in this case would return a 3x3 matrix, which is a covariance matrix if x=y and a cross-covariance matrix otherwise. The underlying covariance function is infinite dimensional but we only ever evaluate it at one point. This could be used for spatial data, but it is also useful for longitudinal or similarly-indexed data with many repeated observations, e.g. growth curves on individuals. Since the observations can be made at arbitrary time points, and there can be different numbers of them per subject, it doesn't always work well with MixedLM and GEE. The spatial application would normally not have repeated observations. You could set When there are replicates, any one subject can have just a few observations, because the underlying infinite-dimensional covariance function is shared by everyone, and we can pool data to gain power. Comparing to ProcessRegression, this uses kernels rather than a parametric model for the covariance, and does not estimate the mean and covariance parameters jointly (here you would have to estimate the mean first and subtract it out). The advantage of this approach is that it might be more flexible than the parametric approaches, and it can handle multivariate observations (e.g. joint model of temperature and humidity) rather than just one variable at a time. |
|
Thanks for the application. I was thinking of spatial panel data like what pysal handles, i.e. each |
|
aside: I added topic-covtype as additional label |
|
One use-case is imputation, taking values that are observed at arbitrary time points for different individuals, then imputing values on a common grid of time points for additional analyses. Hence #4722 to make the covariance modeling and imputation work together a bit better. |
|
This pull request introduces 2 alerts when merging 0bfcee2 into 8928f8d - view on LGTM.com new alerts:
Comment posted by LGTM.com |
Codecov Report
@@ Coverage Diff @@
## master #4726 +/- ##
==========================================
+ Coverage 81.08% 81.09% +<.01%
==========================================
Files 579 580 +1
Lines 89521 89625 +104
Branches 9975 9992 +17
==========================================
+ Hits 72592 72682 +90
- Misses 14654 14664 +10
- Partials 2275 2279 +4
Continue to review full report at Codecov.
|
| j2 = ii[j2.flat] | ||
| w = kx[j1] * ky[j2] | ||
|
|
||
| cm += np.einsum("ij,ik,i->jk", exog[j1, :], exog[j2, :], w) |
There was a problem hiding this comment.
in GLM according to timing by @thequackdaddy using something like the following was faster than einsum, but it was for a matrix version (GLM.hessian IIRC)
(exog[j1, :] * w).dot(exog[j2, :])`
|
I think this is fine, and you can merge when ready. I read through most of Genton, Kleiber to get a basic idea (but not more than that). I think the current location in correlation_tools is fine because it returns a (nested) helper function instead of doing some full covariance computation. |
|
This pull request introduces 2 alerts when merging 658ca7f into 8928f8d - view on LGTM.com new alerts:
Comment posted by LGTM.com |
This implements a simple method of moments estimator of a spatial covariance function for multivariate data, using the approach discussed on page 7 of this paper:
Genton M, W Kleiber (2015). Cross covariance functions for multivariate geostatics. Statistical Science 30(2). https://arxiv.org/pdf/1507.08017.pdf