Skip to content

Instantly share code, notes, and snippets.

View casperkaae's full-sized avatar

Casper Sønderby casperkaae

View GitHub Profile
class LinearLayer():
def __init__(self, num_inputs, num_units, scale=0.01):
self.num_units = num_units
self.num_inputs = num_inputs
self.W = np.random.random((num_inputs, num_units)) * scale
self.b = np.zeros(num_units)
def __str__(self):
return "LinearLayer(%i, %i)" % (self.num_inputs, self.num_units)
@casperkaae
casperkaae / mirror_padding.py
Created July 28, 2016 20:30
mirror padding for theano
def mirror_padding(images, filter_size):
"""
Mirror padding is used to apply a 2D convolution avoiding the border
effects that one normally gets with zero padding.
We assume that the filter has an odd size.
To obtain a filtered tensor with the same output size, substitute
a ``conv2d(images, filters, mode="half")`` with
``conv2d(mirror_padding(images, filters.shape), filters, mode="valid")``.
H=heads, T=Tail
HHH = 1
HHT = 2
HTH = 3
HTT = 4
THH = 5
THT = flip again
TTH = flip again
TTT = flip again
@casperkaae
casperkaae / tests.py
Last active March 22, 2017 20:38
tests.py
import numpy as np
import torch
from torch.autograd import Variable
def dynamic_avg_pooling_test():
from functions.dynamic_avg_pooling import dynamic_avg_pooling
batch_size = 7 #crashes if below 8
nc = 32
# Packages we're using
import numpy as np
import matplotlib.pyplot as plt
import copy
from scipy.io import wavfile
import soundfile as sf
from utils.snr import residual_snrdb
@casperkaae
casperkaae / soundfun.py
Last active April 2, 2017 22:32
sound fun
# Packages we're using
import numpy as np
import copy
import soundfile as sf
def overlap(X, window_size, window_step):
"""
Create an overlapped version of X
Parameters
def update_dynamic_datasets(outputfolder=None, recompute_out_of_sample_static_y_hat=True):
###### COMBINED PREPREOCESSING ###########
logger.info('Preprocessing - making out of sample predictions')
target_col = 'intraday_pct_change_next'
#df = load_newest_dataset_from_fileserver(STATIC_EARNINGS_DATA_NAME)
# ds = load_newest_dataset_from_fileserver(MARKET_BAR_DATASET_NAME)
#df = get_static_earnings_input_data(df, ds, overwrite_overnight_pct_change=True)
#if settings.STATIC_DATASET_SETTINGS['use_shifted_static_data'] and recompute_out_of_sample_static_y_hat:
# df_shift = load_newest_dataset_from_fileserver(STATIC_EARNINGS_DATA_SHIFTED_NAME)