Permalink
Browse files

Merge pull request #508 from jseabold/cholesky-diag

ENH: Avoid taking cholesky decomposition of diagonal matrix. Closes #488.
  • Loading branch information...
2 parents 3c1dbed + 1415cfc commit d10372dcab1191a920fc4f64f11d0ebbc27a3b2f @jseabold jseabold committed Oct 5, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 statsmodels/regression/linear_model.py
@@ -53,16 +53,18 @@ def _get_sigma(sigma, nobs):
if sigma is None:
return None, None
sigma = np.asarray(sigma).squeeze()
+ if sigma.ndim == 0:
+ sigma = np.repeat(sigma, nobs)
if sigma.ndim == 1:
+ cholsigmainv = np.diag(1/sigma**.5)
sigma = np.diag(sigma)
- elif sigma.ndim == 0:
- sigma = np.diag([sigma] * nobs)
+ else:
+ cholsigmainv = np.linalg.cholesky(np.linalg.pinv(sigma)).T
if sigma.shape != (nobs, nobs):
raise ValueError("Sigma must be a scalar, 1d of length %s or a 2d "
"array of shape %s x %s" % (nobs, nobs))
- cholsigmainv = np.linalg.cholesky(np.linalg.pinv(sigma)).T
return sigma, cholsigmainv
class RegressionModel(base.LikelihoodModel):

0 comments on commit d10372d

Please sign in to comment.