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 / 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
@cwidmer
cwidmer / blocking_eigenvecs
Created October 1, 2014 19:53
Properties of blocking eigen decomposition
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"""
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()
"""
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
@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)
@cwidmer
cwidmer / experiment_toy_hmtmkl.py
Last active August 29, 2015 13:55
toy example for learning the similarity
#!/usr/bin/env python2.6
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Written (W) 2013 Christian Widmer
# Copyright (C) 2013 Max-Planck-Society, MSKCC, TU-Berlin
"""
@cwidmer
cwidmer / dendogram.py
Created January 30, 2014 09:15
plot matrix with dendogram
import numpy as np
import copy
import random
import pylab
import scipy.cluster.hierarchy as sch
def create_linkage_matrix(num_tasks):
"""
create stack of matrices for
@cwidmer
cwidmer / shogun_string_factory.py
Created December 5, 2013 21:08
python module to create shogun objects for dealing with string kernels and string data withing the COFFIN framework
#!/usr/bin/env python2.5
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Written (W) 2010-2013 Christian Widmer
# Copyright (C) 2010-2013 Max-Planck-Society, TU-Berlin, MSKCC
"""
@cwidmer
cwidmer / viz_seq.py
Created December 5, 2013 20:49
Visualize a list of sequences (of same length, assuming DNA encoding) as a color coded matrix
import pylab
import numpy
def show_seqs(seqs):
"""
plot color coded training sequences
"""
@cwidmer
cwidmer / coshuffle.py
Created December 5, 2013 20:46
Shuffle several iterables the same way
import random
def coshuffle(*args):
"""
will shuffle target_list and apply
same permutation to other lists
>>> helper.coshuffle([2, 1, 3], [4, 2, 8], [6, 3, 12])
([5, 3, 2, 1, 4], [5, 3, 2, 1, 4], [5, 3, 2, 1, 4])