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 / 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 / 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 / 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 / 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 / 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)