Skip to content

Instantly share code, notes, and snippets.

@cwidmer
Last active August 29, 2015 14:07
Show Gist options
  • Save cwidmer/37f9879adc6ab6359c57 to your computer and use it in GitHub Desktop.
Save cwidmer/37f9879adc6ab6359c57 to your computer and use it in GitHub Desktop.
different methods for log determinants
import numpy as np
# generate data
X = np.random.randn(1000, 10000)
K = X.dot(X.T)
# np function
np.linalg.slogdet(K)
# using eigh
S1, U1 = np.linalg.eigh(K)
np.log(S1[S1 > 1e-9]).sum()
# using svd
U,S,V = np.linalg.svd(X, full_matrices=False)
S2 = S*S
np.log(S2[S2 > 1e-9]).sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment