Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@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 / 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"]
@kastnerkyle
kastnerkyle / sed_commands.sh
Last active August 29, 2015 14:22
Sed commands
# skip hidden files and sed replace
find . -not -path '*/\.*' -type f -exec sed -i -e 's|from pelican|from ../lib/pelican|' {} +
# replace in every file recursive
find . -type f -exec sed -i -e 's/foo/bar/g' {} +
# replace in all files in current dir
sed -i -- 's/foo/bar/g' *
# tmp_wav.txt is raw text from dropbox downloads list - pull out wav files, making sure to strip leading whitespace
@kastnerkyle
kastnerkyle / numpy_tricks.py
Created June 24, 2015 17:18
Stupid numpy tricks
import numpy as np
# Broadcast tricks to repeat a matrix
a = np.arange(100 * 10).reshape((100, 10))
# Number of times to clone each entry
clone_count = 2
# axis 0 clone
b = np.ones((1, clone_count, a.shape[1]))
c = (a[:, None, :] * b).reshape((-1, a.shape[-1]))
# axis 1 clone
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kastnerkyle
kastnerkyle / Optimizer.py
Last active September 17, 2015 10:08 — forked from jiahao/Optimizer.py
Pure Python implementation of some numerical optimizers
#!/usr/bin/env python
'''
Pure Python implementation of some numerical optimizers
Created on Jan 21, 2011
@author Jiahao Chen
'''
@kastnerkyle
kastnerkyle / test_ctc.py
Last active October 11, 2015 03:42
Test of log-space CTC cost function
"""
bitmap utils and much of the ctc code modified from Shawn Tan
"""
# Author: Kyle Kastner
# License: BSD 3-clause
from theano import tensor
from scipy import linalg
import theano
import numpy as np
import matplotlib.pyplot as plt
@kastnerkyle
kastnerkyle / gp.py
Created November 7, 2015 01:44
Minimal experiments in fast gaussian processes
import numpy as np
import matplotlib.pyplot as plt
from scipy import linalg
from sklearn.externals import joblib
mem = joblib.Memory(cachedir='.')
def plot_gp_confidence(gp, show_gp_points=True, X_low=-1, X_high=1,
X_count=1000, xlim=None, ylim=None, show=False):
class SPPLayer(lasagne.layers.Layer):
def __init__(self, incoming, **kwargs):
super(SPPLayer, self).__init__(incoming, **kwargs)
# divide by 4 gives 16 patches
self.win1 = (int(np.floor(incoming.output_shape[2]/4.0)), int(np.floor(incoming.output_shape[3]/4.0)))
self.str1 = (int(np.ceil(incoming.output_shape[2]/4.0)), int(np.ceil(incoming.output_shape[3]/4.0)))
# divide by 2 gives 4 patches
self.win2 = (int(np.floor(incoming.output_shape[2]/2.0)), int(np.floor(incoming.output_shape[3]/2.0)))
@kastnerkyle
kastnerkyle / gist:8d82b4f93705e339354f
Created December 12, 2015 17:11 — forked from anonymous/gist:0a6e9ceccd30e1d5f992
Mixture of Gaussian densities, and derivatives
def gaussian_density_batch(x, mean, stddev, correlation, compute_derivatives=False):
"""
Compute the Gaussian density at x for a 2D normal distribution with parameters mean, stddev, correlation.
This works simultaneously on a batch of inputs. The inputs should have dimensions:
x.shape = (n, 1, 2)
mean.shape = stddev.shape = (n, m, 2)
correlation.shape = (n, m, 1)
where n*m is the number of different Gaussian density functions that we want to evaluate, on n input points x.
So the same input x is plugged into the density for m Gaussian pdfs. (This is convenient for evaluating a