Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / example_pairwise.py
Last active June 11, 2022 17:13
Example of pairwise processing with "smart broadcasting"
import numpy as np
def exponential_kernel(x1, x2):
# Broadcasting tricks to get every pairwise distance.
return np.exp(-((x1[np.newaxis, :, :] - x2[:, np.newaxis, :]) ** 2).sum(2)).T
a = np.random.randn(100, 5)
print(exponential_kernel(a, a).shape)
@kastnerkyle
kastnerkyle / example_theano_clone.py
Created July 29, 2014 14:26
Example of using theano.clone to replace an input
import theano.tensor as T
import theano
a = T.vector()
b = T.matrix()
fa = a ** 2
f = theano.function([a], fa)
f2 = theano.function([b], theano.clone(fa, replace={a: b}, strict=False))
print(f([2]))
print(f2([[2]]))
@kastnerkyle
kastnerkyle / single_file_cp.py
Created September 8, 2014 00:15
The CP algorithm from scikit-tensor in a single file. Should be identical (or damn close)!
# License: GPL
# Based on scikit-tensor by mnick
# https://github.com/mnick/scikit-tensor
"""Tensor factorization."""
import numpy as np
from scipy import linalg
def _matricize(X, axis):
@kastnerkyle
kastnerkyle / speech.py
Last active July 23, 2020 06:52
Code for speech and audio experiments. - DEPRECATED! See audio_tools.py
# License: BSD 3-clause
# Authors: Kyle Kastner,
# Pierre Luc Carrier
import numpy as np
from numpy.lib.stride_tricks import as_strided
import scipy.signal as sg
from scipy import linalg, fftpack
from numpy.testing import assert_almost_equal
@kastnerkyle
kastnerkyle / covariance_test.py
Last active August 29, 2015 14:10
Test code for combining covariances
import numpy as np
from numpy.testing import assert_almost_equal
A = np.arange(200).reshape(40, 5).astype('float32')
B = np.arange(100).reshape(20, 5) + 10.
C = np.vstack((A, B))
mA = np.mean(A, axis=0)
mB = np.mean(B, axis=0)
mC = np.mean(C, axis=0)
@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 / fm.py
Created January 30, 2015 19:05
Simple frequency modulation
import numpy as np
import matplotlib.pyplot as plt
control = np.zeros(10000)
control[:2000] = -50
control[5000:7000] = 50.
control[7000:] = -50
def frequency_modulation(modulation_signal, carrier_freq=100.,
@kastnerkyle
kastnerkyle / conv_deconv_vae.py
Last active October 19, 2024 08:20
Convolutional Variational Autoencoder, modified from Alec Radford at (https://gist.github.com/Newmu/a56d5446416f5ad2bbac)
# Alec Radford, Indico, Kyle Kastner
# License: MIT
"""
Convolutional VAE in a single file.
Bringing in code from IndicoDataSolutions and Alec Radford (NewMu)
Additionally converted to use default conv2d interface instead of explicit cuDNN
"""
import theano
import theano.tensor as T
from theano.compat.python2x import OrderedDict
@kastnerkyle
kastnerkyle / vae.py
Created March 26, 2015 18:10
VAE in a single file
# Alec Radford, Indico, Kyle Kastner
# License: MIT
"""
VAE in a single file.
Bringing in code from IndicoDataSolutions and Alec Radford (NewMu)
"""
import theano
import theano.tensor as T
from theano.compat.python2x import OrderedDict
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
# 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