Skip to content

Instantly share code, notes, and snippets.

@mblondel
mblondel / kernel_sgd.py
Last active April 21, 2024 13:41
Kernel SGD
# Mathieu Blondel, May 2012
# License: BSD 3 clause
import numpy as np
def euclidean_distances(X, Y=None, Y_norm_squared=None, squared=False):
XX = np.sum(X * X, axis=1)[:, np.newaxis]
YY = np.sum(Y ** 2, axis=1)[np.newaxis, :]
distances = np.dot(X, Y.T)
distances *= -2
@jboner
jboner / latency.txt
Last active May 5, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@npinto
npinto / theano_hacks.py
Created October 3, 2012 22:16
Theano Memory Hacks
import time
import gc
import numpy as np
def theano_memory_hack(func_exp, local_vars,
input_exps=('input',),
msize_best=None,
msize_start=1024, msize_factor=2,
verbose=False):
@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active April 17, 2024 10:51
Backend Architectures Keywords and References
@mblondel
mblondel / matrix_sketch.py
Last active February 13, 2019 09:26
Frequent directions algorithm for matrix sketching.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
from scipy.linalg import svd
def frequent_directions(A, ell, verbose=False):
"""
Return the sketch of matrix A.
@erogol
erogol / cluster.py
Created December 13, 2013 15:46
clustering with theano
import numpy as np
import numpy
import theano
import theano.tensor as T
from theano import function, config, shared, sandbox
from theano import ProfileMode
from sklearn import cluster, datasets
import matplotlib.pyplot as plt
def rsom(data, cluster_num, alpha, epochs = -1, batch = 1, verbose = False):
@syllog1sm
syllog1sm / gist:10343947
Last active November 7, 2023 13:09
A simple Python dependency parser
"""A simple implementation of a greedy transition-based parser. Released under BSD license."""
from os import path
import os
import sys
from collections import defaultdict
import random
import time
import pickle
SHIFT = 0; RIGHT = 1; LEFT = 2;
# read shorten (shn) files into numpy arrays
from __future__ import division
import os.path as path
import os
from subprocess import call
import struct
import tempfile
def shnread(shnfile):
@kastnerkyle
kastnerkyle / conv_deconv_vae.py
Last active April 21, 2023 01:18
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