Skip to content

Instantly share code, notes, and snippets.

@eickenberg
eickenberg / pfs_beginning_partial.py
Created November 20, 2017 05:23
pfs beginning stub
import torch
from torch import nn
from torch.nn import Parameter, functional as F
class Convolution2DEnergyTemporalBasis(nn.Module):
def __init__(self, n_input_channels,
n_filters_simple,
n_filters_complex,
n_filters_temporal,
@eickenberg
eickenberg / kcca.py
Created September 21, 2017 17:03
cca and regularized kernel cca
def kcca_dual_coef(K1, K2, gamma, n_coefs=None, reduced_problem=False):
eigen_shape = tuple(np.array(K1.shape) * 2)
eigen_matrix1 = np.zeros(eigen_shape)
em_view = eigen_matrix1.view()
em_view.shape = 2, eigen_shape[0] // 2, 2, eigen_shape[1] // 2
em_view = em_view.transpose(0, 2, 1, 3)
eigen_matrix2 = np.zeros(eigen_shape)
em_view2 = eigen_matrix2.view()
@eickenberg
eickenberg / cuda_fft_test.py
Created December 7, 2016 11:46
Script for benchmarking skcuda fft performance (pure calculation) wrt pyfftw
"""testing skcuda fft in 3 dimensions"""
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
#from scipy import fftpack as fft
from pyfftw.interfaces import numpy_fft as fft
import skcuda.fft as cu_fft
@eickenberg
eickenberg / periodize.py
Created July 11, 2016 12:19
Code for periodizing a signal in Fourier (corresponds to subsampling in signal space)
# Code for periodizing a signal in Fourier (corresponds to subsampling in signal space)
def periodize_1d(array, axis, downsampling):
axis_shape = array.shape[axis]
before_shape = array.shape[:axis]
after_shape = array.shape[axis + 1:]
new_shape = before_shape + (downsampling, -1) + after_shape
return array.reshape(new_shape).mean(axis)
@eickenberg
eickenberg / vae.py
Last active August 29, 2015 14:20
Variational autoencoder (sketch)
# Author: Michael Eickenberg
# License: BSD 3-clause
# This is a rapidly written proof of concept. There may remain big bugs. I find it overfits quite quickly atm
import numpy as np
import theano
theano.config.floatX = 'float32'
import theano.tensor as T
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
@eickenberg
eickenberg / convolutional_zca.py
Created April 4, 2015 16:45
Draft of a convolutional ZCA
# Disclaimer: This doesn't seem to work 100% yet, but almost ;)
# Convolutional ZCA
# When images are too large in amount of pixels to be able to determine the
# principal components of an image batch, one can suppose translation
# invariance of the eigen-structure and do the ZCA in a convolutional manner
import theano
import theano.tensor as T
import numpy as np
@eickenberg
eickenberg / loess.py
Created February 2, 2015 17:27
Locally weighted regression
# Author Michael Eickenberg <michael.eickenberg@nsup.org>, Fabian Pedregosa
# Coded in 2012, another era, pure python, no guarantees for 1000% correctness or speed
"""
This module implements the Lowess function for nonparametric regression.
Functions:
lowess Fit a smooth nonparametric regression curve to a scatterplot.
For more information, see
@eickenberg
eickenberg / spam.py
Created February 2, 2015 17:26
An implementation of Sparse Additive Models in Coordinate Descent
# Author Michael Eickenberg <michael.eickenberg@nsup.org>, Fabian Pedregosa
# Coded in 2012, another era, pure python, no guarantees for 1000% correctness or speed
# requires loess.py
import numpy as np
from loess import lowess
VERBOSE = 100
@eickenberg
eickenberg / theano_l1.py
Last active August 29, 2015 14:14
checking theano l1 gradient == sign
import theano
import theano.tensor as T
import numpy as np
# 0 and some arbitrarily small positive and negative numbers
test_vector = np.array(
[0., 1., -1., .1, -.1, 10., -10., 1e-8, -1e-8,
1e-10, -1e-10, 1e-16, -1e-16]).astype(np.float32)
@eickenberg
eickenberg / fancy_max_pool.py
Last active August 29, 2015 14:13
Maxpooling with arbitrary pooling strides and pooling shapes
# Maxpooling with arbitrary pooling strides and pooling shapes
# Based on theano.tensor.signal.downsample.max_pool_2d. This
# operation is repeated the minimum necessary times to account for
# all stride steps.
#Author: Michael Eickenberg, michael.eickenberg@nsup.org
import theano
import numpy as np