Skip to content

Instantly share code, notes, and snippets.

from multiprocessing import Pool
# parallelize function
def product(a,b):
print a*b
# auxiliary funciton to make it work
def product_helper(args):
return product(*args)
import numpy as np
import theano
import theano.tensor as T
from theano import function,sandbox
from theano import ProfileMode
import warnings
# Dummy Data
theano.config.floatX = 'float32' # Theano needs this type of data for GPU use
erogol /
Last active August 29, 2015 13:57 — forked from dmaniry/gist:5170087
ZCA whitening of given data matrix
import numpy as np
from scipy import linalg
from sklearn.utils import array2d, as_float_array
from sklearn.base import TransformerMixin, BaseEstimator
class ZCA(BaseEstimator, TransformerMixin):
def __init__(self, regularization=10**-5, copy=False):
self.regularization = regularization

tmux cheatsheet

As configured in my dotfiles.

start new:


start new with session name:

erogol /
Created April 22, 2014 08:07
sklearn call
if __name__ == '__main__':
from sklearn.cross_validation import StratifiedShuffleSplit
# svc = LinearSVC(class_weight='auto', penalty='l1', dual=False, verbose = 15, C=0.1)
svc = Perceptron(penalty='l1', alpha=0.05, fit_intercept=True, n_iter = 100, shuffle=True, n_jobs=-1, class_weight='auto', verbose=15)
sf = StratifiedShuffleSplit(y,n_iter = 2, train_size =0.9, test_size=0.1);
for train,test in sf:
X_train, X_test = X[train], X[test]
y_train, y_test = y[train], y[test]
print 'Train set size: ', X_train.shape
print 'Test set size: ', X_test.shape
erogol /
Created May 29, 2014 10:07
bing scrabber but add more to query address
from bs4 import BeautifulSoup
import requests
import urllib2
import os
import re, urlparse
import time
import pdb
from interruptingcow import timeout
import pandas as pd
from sqlalchemy import *
engine = create_engine('mysql://username:pass@server_address', pool_recycle=60)
DF ='csv/file/path.csv')
DF = DF.dropna()
DF.to_sql('table_name', con=engine, if_exists='replace', flavor='mysql') # replace truncates the existing table and creates a new one
erogol /
Created November 19, 2014 16:28
svd based whitining
def svd_whiten(X):
U, s, Vt = np.linalg.svd(X)
# U and Vt are the singular matrices, and s contains the singular values.
# Since the rows of both U and Vt are orthonormal vectors, then U * Vt
# will be white
X_white =, Vt)
return X_white
erogol / gist:78fe47aaa31cd9c72f10
Created December 23, 2014 09:00
name: "sentio_full_train"
# N.B. input image must be in CIFAR-10 format
# as described at
name: "data"
type: HDF5_DATA
top: "data"
top: "label"
hdf5_data_param {
"metadata": {
"name": "",
"signature": "sha256:7278f115593dc43b248938b9210d9794dad8be21e1221b4b92f49716c2b633b8"
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
"cells": [