Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Fix masked array are not supported in linalg.solve (#3)
Browse files Browse the repository at this point in the history
Fix issue described here: pykalman#83
  • Loading branch information
mbalatsko authored Sep 19, 2023
2 parents d026511 + e48bb7b commit 5d72ec7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions pykalman/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ def array2d(X, dtype=None, order=None):

def log_multivariate_normal_density(X, means, covars, min_covar=1.e-7):
"""Log probability for full covariance matrices. """
if hasattr(linalg, 'solve_triangular'):
# only in scipy since 0.9
solve_triangular = linalg.solve_triangular
else:
# slower, but works
solve_triangular = linalg.solve
n_samples, n_dim = X.shape
nmix = len(means)
log_prob = np.empty((n_samples, nmix))
Expand All @@ -70,7 +64,7 @@ def log_multivariate_normal_density(X, means, covars, min_covar=1.e-7):
cv_chol = linalg.cholesky(cv + min_covar * np.eye(n_dim),
lower=True)
cv_log_det = 2 * np.sum(np.log(np.diagonal(cv_chol)))
cv_sol = solve_triangular(cv_chol, (X - mu).T, lower=True).T
cv_sol = np.linalg.solve(cv_chol, (X - mu).T).T
log_prob[:, c] = - .5 * (np.sum(cv_sol ** 2, axis=1) + \
n_dim * np.log(2 * np.pi) + cv_log_det)

Expand Down

0 comments on commit 5d72ec7

Please sign in to comment.