Last active
August 29, 2015 14:07
Revisions
-
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,14 @@ t0 = time.time() np.linalg.slogdet(K) tnp = time.time() - t0 + tK print "tslogdet:", tnp # np function t0 = time.time() np.log(np.linalg.det(K)) tnp = time.time() - t0 + tK print "tdet:", tnp # using eigh t0 = time.time() -
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ X = np.random.randn(1000, 10000) t0 = time.time() K = X.dot(X.T) + 1e-9*np.eye(X.shape[0]) tK = time.time() - t0 print "tK:", tK @@ -32,7 +32,7 @@ # using cholesky (creates lower-triagular matrix, for which eigenvalues can be read off the diagonal) t0 = time.time() L = np.linalg.cholesky(K) log_det_chol = np.log(np.diag(L)**2).sum() tcho = time.time() - t0 + tK print "tcho:", tcho -
cwidmer renamed this gist
Oct 17, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,3 +36,17 @@ L = np.linalg.cholesky(K+1e-9*np.eye(K.shape[0])) log_det_chol = np.log(np.diag(L)**2).sum() tcho = time.time() - t0 + tK print "tcho:", tcho """ output: tK: 0.680999994278 tnp: 0.746999979019 teig: 1.02300000191 tsvd: 4.94499993324 tcho: 0.770999908447 verdict: use cholesky if other operations are done on matrices if only log det is needed, slogdet is fine (uses LU factorzation internally) """ -
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,6 @@ print "tsvd:", tsvd # using cholesky (creates lower-triagular matrix, for which eigenvalues can be read off the diagonal) t0 = time.time() L = np.linalg.cholesky(K+1e-9*np.eye(K.shape[0])) log_det_chol = np.log(np.diag(L)**2).sum() tcho = time.time() - t0 + tK print "tcho:", tcho -
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,38 @@ import numpy as np import time # generate data X = np.random.randn(1000, 10000) t0 = time.time() K = X.dot(X.T) tK = time.time() - t0 print "tK:", tK # np function t0 = time.time() np.linalg.slogdet(K) tnp = time.time() - t0 + tK print "tnp:", tnp # using eigh t0 = time.time() S1, U1 = np.linalg.eigh(K) np.log(S1[S1 > 1e-9]).sum() teig = time.time() - t0 + tK print "teig:", teig # using svd t0 = time.time() U,S,V = np.linalg.svd(X, full_matrices=False) S2 = S*S np.log(S2[S2 > 1e-9]).sum() tsvd = time.time() - t0 print "tsvd:", tsvd # using cholesky (creates lower-triagular matrix, for which eigenvalues can be read off the diagonal) t0 = time.time() L = np.linalg.cholesky(K+1e-9*np.eye(K.shape[0])) log_det_chol = np.log(np.diag(meh)**2).sum() tcho = time.time() - t0 + tK print "tcho:", tcho -
cwidmer revised this gist
Oct 17, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import numpy as np # generate data X = np.random.randn(1000, 10000) K = X.dot(X.T) # np function -
cwidmer created this gist
Oct 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ import numpy as np # generate data X = ... 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()