New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow matrix structure in covariance matrices to be exploited #1643
Conversation
vinv_d = spl.cho_solve(vco, dmat) | ||
rslt = self.cov_struct.covariance_matrix_solve(expval, i, | ||
sdev, (dmat, resid)) | ||
vinv_d, vinv_resid = tuple(rslt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rslt
might be None
?
y /= sdev[:, None] | ||
|
||
if flatten: | ||
y = y[:,0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.squeeze would be safer I think.
np.squeeze will cause shape error later if y.shape[1] > 1
IIUC
M-dependent is the only case I really worked my way through it. So I might postpone understanding this and just do a superficial review before merge. |
Thanks for the comments. I think I've addressed everything. The m-dependent structure needs a bit of cleanup. I will work with Frank on that. |
I'm not a big fan of This looks like a clean branch according to the network tree, and can be merged with green button. |
for x in rhs: | ||
if x.ndim == 1: | ||
x1 = x / stdev | ||
y = x1 / (1 - self.dep_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side comment, doesn't need to be changed
in general, I still prefer floating point integers to signal that we are working with floats not integers.
(1. - self.dep_params)
(I still have a left-over habit to hunt for bugs caused by integer division.)
one more: can you inherit the docstring for the methods in the subclasses? for I mentioned this in Frank's PR |
I think this is about ready to merge. |
Ready to merge now. Thanks for your help. |
REF: Allow matrix structure in covariance matrices to be exploited
merged |
REF: Allow matrix structure in covariance matrices to be exploited
This PR provides adds a new method
covariance_matrix_solve
to the CovStruct class that solves a system of equations whose coefficient matrix is the covariance matrix represented by the CovStruct instance.Currently, we construct this covariance matrix explicitly, and solve these systems with a general-purpose solver. However, for many of the dependence structures, the linear algebra can be optimized to exploit the structure of the matrix.
We provide a default implementation of
covariance_matrix_solve
that uses a general-purpose solver.We override this with optimized methods for the independence, autoregressive, and exchangeable cases.
The speed improvement would be most noticeable when the cluster sizes are large.
Tests for the independence and exchangeable cases match results obtained from R (as did the earlier code).
We don't have a comparator for the autoregressive case, so I added a regression test. It agrees with the results from the previous (non-optimized) implementation.