Skip to content

Instantly share code, notes, and snippets.

View iskandr's full-sized avatar

Alex Rubinsteyn iskandr

View GitHub Profile
@iskandr
iskandr / keras2-highway-network.py
Created April 17, 2017 20:24
Since Keras 2.0 removed the Highway Network layer, here's my attempt at implementing something equivalent using the functional API
import keras.backend as K
from keras.layers import Dense, Activation, Multiply, Add, Lambda
import keras.initializers
def highway_layers(value, n_layers, activation="tanh", gate_bias=-3):
dim = K.int_shape(value)[-1]
gate_bias_initializer = keras.initializers.Constant(gate_bias)
for i in range(n_layers):
gate = Dense(units=dim, bias_initializer=gate_bias_initializer)(value)
gate = Activation("sigmoid")(gate)
@iskandr
iskandr / svd_timing_experiment.py
Last active January 6, 2016 19:03
Timing full SVD vs. truncated SVD
import time
import numpy as np
import sklearn.decomposition
import seaborn
RANK = 50
N_COLS = 1000
def evaluate_svd(svd_fn, reconstruct_fn, min_rows=100, max_rows=5000, n_samples=100, n_cols=N_COLS, rank=RANK, random_seed=0):
np.random.seed(random_seed)
object ForLoop {
def main(args: Array[String]) {
var acc = 0L
for (i <- 0L to 1000000000L) {
acc += i
}
println("For loop!")
}
}
@iskandr
iskandr / cudatree1.ipynb
Created October 14, 2013 00:00
cudatree getting suboptimal accuracy on covtype
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@iskandr
iskandr / gini.py
Created August 7, 2013 20:26
gini score
import numpy as np
LeftCounts = np.array([150,150])
RightCounts = np.array([200,200])
NLeft = sum(LeftCounts)
NRight = sum(RightCounts)
NTotal = float(NLeft + NRight)
LL = np.dot(LeftCounts,LeftCounts)
RR = np.dot(RightCounts,RightCounts)
def dilate_naive(x, k):
m,n = x.shape
y = np.empty_like(x)
for i in xrange(m):
for j in xrange(n):
currmax = x[i,j]
for ii in xrange(max(0, i-k/2), min(m, i+k/2+1)):
for jj in xrange(max(0, j-k/2), min(n, j+k/2+1)):
elt = x[ii,jj]
if elt > currmax:
def dilate_two_pass(x, k):
m,n = x.shape
y = np.empty_like(x)
for i in xrange(m):
for j in xrange(n):
left_idx = max(0, i-k/2)
right_idx = min(m, i+k/2+1)
currmax = x[left_idx, j]
for ii in xrange(left_idx+1, right_idx):
elt = x[ii, j]
@iskandr
iskandr / dilate-two-pass.py
Created June 3, 2013 22:11
Image dilation in Python as two separate 1-D passes
def dilate_two_pass(x, window_size):
m,n = x.shape
k,l = window_size
y = np.empty_like(x)
for i in xrange(m):
for j in xrange(n):
left_idx = max(0, i-k/2)
right_idx = min(m, i+k/2+1)
currmax = x[left_idx, j]
for ii in xrange(left_idx+1, right_idx):
@iskandr
iskandr / dilate-naive.py
Last active December 18, 2015 01:09
Naive image dilation in Python
def dilate_naive(x, (k,l)):
m,n = x.shape
y = np.empty_like(x)
for i in xrange(m):
for j in xrange(n):
currmax = x[i,j]
for ii in xrange(max(0, i-k/2), min(m, i+k/2+1)):
for jj in xrange(max(0, j-l/2), min(n, j+l/2+1)):
elt = x[ii,jj]
if elt > currmax:
def numpy_count_thresh(values, thresh):
return np.sum(values < thresh)