Computational gain for the one factor model
Closed this issue · 3 comments
TomMaullin commented
For the one factor model, large gains can be made by considering that Z'Z is block diagonal. Ideally it would be nice to account for this and implement speedier computation of D(I+Z'ZD)^(-1) for this use case.
TomMaullin commented
Places in the code this could be undertaken:
- Computation of
DinvIplusZtZD
could be split into 4 cases:- r=1,nraneffs[0]=1 (in which case DinvIplusZtZD is diagonal)
- r=1, nraneffs[0]>1 (in which case it's block diagonal)
- q>1000 (in which case the recursive inverse method is probably the best choice)
- else (just do it with numpy).
- Anywhere where there is multiplication by
DinvIplusZtZD
in the one factor model can be reduced to a running sum of matrices of much smaller dimension (probably using einsum even). Two cases would be of possible speedup:- r=1,nraneffs[0]=1 (using a dot product of the diagonal elements)
- r=1, nraneffs[0]>1 (using
Ddict
and an einsum)
- For the one factor model,
D
need never be constructed in full. This would have to be removed from 3 places:- Whereever it is created.
- Where its used to calculate
DinvIplusZtZD
- Where its used in the log-likelihood.
TomMaullin commented
Important: For this to work we must first ensure that the factor is given in increasing order (else pd.get_dummies
in blmm_batch
will give Z in a non-diagonal format.).
TomMaullin commented
Update: In PR #45 , the following use case has now been accounted for in the 3D code:
- When
r=1 and nraneffs[0]=1
, the code does not constructZtZ
,DinvIplusZtZD
orD
.
The case r=1 and nraneffs[0]>1
has not been considered.