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 / pylab_external_legend.py
Last active December 30, 2015 08:39
snippet to create matplotlib plot with title, grid and externally located legend
import pylab
data1 = [1,2,3,4]
data2 = [2,3,4,5]
pylab.plot(data1, "-o", label="meh")
pylab.plot(data2, "-o", label="arr")
pylab.title("example")
pylab.grid(True)
@cwidmer
cwidmer / auc.py
Last active December 30, 2015 09:59
code snippet to calculate the common performance measures, area under the precision-recall curve and area under the receiver operator characteristic curve
import pylab
def plot_roc(y, out, label="", out_fn=None):
"""
show or save ROC curve
"""
pylab.figure()
plot_roc_noshow(y, out, label=label)
@cwidmer
cwidmer / compressed_pickle.py
Last active August 22, 2021 06:19
save/load compressed pickled objects in python
import cPickle
import bz2
def save(filename, myobj):
"""
save object to file using pickle
@param filename: name of destination file
@type filename: str
@cwidmer
cwidmer / random_sequence.py
Created December 5, 2013 20:35
generates a random sequence of length over alphabet
def rand_seq(alphabet, length):
"""
generates a random sequence of length over alphabet
@param alphabet: alphabet from which to choose characters
@type alphabet: list<str>
@param length: length of random string
@type length: int
"""
@cwidmer
cwidmer / powerset.py
Last active December 30, 2015 10:08
Create power-set (the set of all possible subsets) from a python list
def power_set(orignal_list):
'''
PowerSet of a List
@param orignal_list: list from which to construct a powerset
'''
list_size = len(orignal_list)
num_sets = 2**list_size
powerset = []
# Don't include empty set
@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])
@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 / 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 / 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 / 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
"""