Skip to content

Commit f9f8db4

Browse files
committed
Merge pull request hildensia#12 from closedLoop/patch-1
fullcov_obs_log_likelihood performance improvement
2 parents a6ab82d + c89d662 commit f9f8db4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

bayesian_changepoint_detection/offline_changepoint_detection.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ def fullcov_obs_log_likelihood(data, t, s):
164164

165165
N0 = dim # weakest prior we can use to retain proper prior
166166
V0 = np.var(x)*np.eye(dim)
167-
Vn = V0 + np.array([np.outer(x[i], x[i].T) for i in xrange(x.shape[0])]).sum(0)
167+
168+
# Improvement over np.outer
169+
# http://stackoverflow.com/questions/17437523/python-fast-way-to-sum-outer-products
170+
# Vn = V0 + np.array([np.outer(x[i], x[i].T) for i in xrange(x.shape[0])]).sum(0)
171+
Vn = V0 + np.einsum('ij,ik->jk', x, x)
168172

169173
# section 3.2 from Xuan paper:
170174
return -(dim*n/2)*np.log(np.pi) + (N0/2)*np.linalg.slogdet(V0)[1] - \

0 commit comments

Comments
 (0)