Skip to content

Commit

Permalink
Merge pull request statsmodels#508 from jseabold/cholesky-diag
Browse files Browse the repository at this point in the history
ENH: Avoid taking cholesky decomposition of diagonal matrix. Closes statsmodels#488.
  • Loading branch information
jseabold committed Oct 5, 2012
2 parents adb9cd1 + 37fb015 commit fc21722
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions statsmodels/regression/linear_model.py
Expand Up @@ -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):
Expand Down

0 comments on commit fc21722

Please sign in to comment.