Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / online_stats.py
Created April 3, 2015 20:02
Online statistics in numpy
# Author: Kyle Kaster
# License: BSD 3-clause
import numpy as np
def online_stats(X):
"""
Converted from John D. Cook
http://www.johndcook.com/blog/standard_deviation/
"""
@kastnerkyle
kastnerkyle / simple_filtering.py
Last active August 29, 2015 14:18
Super crude filtering
# Author: Kyle Kastner
# License: BSD 3-clause
import numpy as np
from scipy.signal import lfilter
import matplotlib.pyplot as plt
sine = np.sin(np.linspace(-4 * np.pi, 4 * np.pi, 10000))
noise = 0.2 * np.random.randn(len(sine))
s = sine + noise
# Original code from tinrtgu on Kaggle under WTFPL license
# Relicensed to BSD 3-clause (it does say do what you want...)
# Authors: Kyle Kastner
# License: BSD 3-clause
# Reference links:
# Adaptive learning: http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/41159.pdf
# Criteo scalable response prediction: http://people.csail.mit.edu/romer/papers/TISTRespPredAds.pdf
# Vowpal Wabbit (hashing trick): https://github.com/JohnLangford/vowpal_wabbit/
# Hashing Trick: http://arxiv.org/pdf/0902.2206.pdf
@kastnerkyle
kastnerkyle / optimizers.py
Last active January 12, 2021 13:46
Theano optimizers
# Authors: Kyle Kastner
# License: BSD 3-clause
import theano.tensor as T
import numpy as np
import theano
class rmsprop(object):
"""
RMSProp with nesterov momentum and gradient rescaling
@kastnerkyle
kastnerkyle / example_hdf5.py
Created April 30, 2015 18:01
Example file for building hdf5 datasets
# -*- coding: utf 8 -*-
# Author: Kyle Kastner
# License: BSD 3-clause
from __future__ import division
import os
import numpy as np
import tables
import numbers
import fnmatch
@kastnerkyle
kastnerkyle / convert_mp3_to_wav.sh
Last active August 29, 2015 14:21
convert_mp3_to_wav.sh
ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav
find ../mp3_symlinks/ -name *.mp3 -exec sh -c 'echo $(basename {} .mp3)' \;
find ../mp3_symlinks/ -name *.mp3 -exec sh -c 'ffmpeg -i {} -acodec pcm_s16le -ac 1 -ar 16000 $(basename {} .mp3).wav' \;
@kastnerkyle
kastnerkyle / tricks.sh
Last active August 29, 2015 14:21
Useful Bash and other tricks
for f in *.ipynb ; do echo $f; aspell list < "$f" | sort | uniq -c ; done | less
2to3 -f imports folder/path | patch -p0
@kastnerkyle
kastnerkyle / all_gists.py
Created May 22, 2015 22:04
Clone all gists, python 3
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib.request, urllib.parse, urllib.error
from subprocess import call
from urllib.request import urlopen
import os
@kastnerkyle
kastnerkyle / updates_test.py
Last active April 14, 2016 00:26
Test basic updates and pickling
import numpy as np
import theano
import theano.tensor as T
import pickle
class sgd_nesterov(object):
def __init__(self, params):
self.memory_ = [theano.shared(np.zeros_like(p.get_value()))
for p in params]
@kastnerkyle
kastnerkyle / pickle_test.py
Last active August 29, 2015 14:21
Load saved theano function and continue training, see https://gist.github.com/kastnerkyle/bcbc004a1843a64602e0
import numpy as np
import theano
import theano.tensor as T
import pickle
d = pickle.load(open("info.pkl", mode="rb"))
X = d["X"]
y = d["y"]
fit_function2 = d["fit_function"]