Skip to content

Instantly share code, notes, and snippets.

View cwidmer's full-sized avatar

Christian Widmer cwidmer

  • Activision-Blizzard
  • Los Angeles
View GitHub Profile
@cwidmer
cwidmer / pca_eigh.py
Last active August 29, 2015 13:56
perform pca via eigendecomposition
def dual_pca(X, max_num_pcs):
"""
assuming N << D (X.shape[0] << X.shape[1]),
we first compute the kernel matrix K = XX^T, perform an
eigendecomposition and subsequently reconstruct
truncated principle components
"""
K = X.dot(X.T)
"""
snippet to time different indexing strategies
based on:
http://wesmckinney.com/blog/?p=215
http://stackoverflow.com/questions/11800075/faster-numpy-fancy-indexing-and-reduction/11813040#11813040
http://stackoverflow.com/questions/14386822/fast-numpy-fancy-indexing?rq=1
"""
import numpy as np
"""
cache linear algebra (or any other) operations
based on hashes of input arguments
"""
import numpy.linalg as la
from sklearn.external import joblib
mem = joblib.Memory(cachedir=cachedir, verbose=True, compress=True)
#mem.clear()
@cwidmer
cwidmer / blocking_eigenvecs
Created October 1, 2014 19:53
Properties of blocking eigen decomposition
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@cwidmer
cwidmer / log_det.py
Last active August 29, 2015 14:07
different methods for log determinants
import numpy as np
import time
# generate data
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