Skip to content

Instantly share code, notes, and snippets.

View erikbern's full-sized avatar

Erik Bernhardsson erikbern

View GitHub Profile
# Simple models of two competing firms bidding on employees
# Each employee is described in terms of k factors
# Company X knows about the x first factors
# Company Y knows about the y first factors
import numpy
from matplotlib import pyplot
n = 10000
k, x, y = 10,
@erikbern
erikbern / install-tensorflow.sh
Last active October 19, 2016 14:00
Install TensorFlow on EC2
# Start from ami-763a311e
# Install various packages
sudo apt-get update
sudo apt-get upgrade -y # choose “install package maintainers version”
sudo apt-get install -y build-essential python-pip python-dev git python-numpy swig python-dev default-jdk zip zlib1g-dev
# Install Bazel
git clone https://github.com/bazelbuild/bazel.git
cd bazel
@erikbern
erikbern / install-tensorflow.sh
Last active June 26, 2023 00:40
Installing TensorFlow on EC2
# Note – this is not a bash script (some of the steps require reboot)
# I named it .sh just so Github does correct syntax highlighting.
#
# This is also available as an AMI in us-east-1 (virginia): ami-cf5028a5
#
# The CUDA part is mostly based on this excellent blog post:
# http://tleyden.github.io/blog/2014/10/25/cuda-6-dot-5-on-aws-gpu-instance-running-ubuntu-14-dot-04/
# Install various packages
sudo apt-get update
@erikbern
erikbern / marketing_mc.py
Last active January 15, 2021 00:50
MCMC for simple marketing data
import pymc, pymc.graph
import matplotlib.pyplot as plt
import numpy as np
import sys
channels = [
('A', 2292.04, 9),
('B', 1276.85, 2),
('C', 139.59, 3),
('D', 954.98, 5)
@erikbern
erikbern / README.md
Last active September 8, 2015 03:29
Antipodes

The cities of Beijing and Buenos Aires are almost antipodes, i.e. they are situated almost opposite of each other on the globe.

An interesting attribute of this is that travelling between the two cities can be done through any point of earth and the trip will still be roughly the same distance. This D3 visualization demonstrates this principle: drag the map around to change perspective, click the map to set a "midpoint" to travel through.

Code for this visualization was stolen from all over the web without any deeper understanding of D3 – in particular this one and this one.

IIRC this is in a theme in Wong Kar-Wai's movie Happy Together.

def coin():
while True:
yield random.randint(0, 1)
def dice_optimal():
x, y, z = 0, 1, 1
for c in coin():
x, y, z = x+c*z, y+c*z, 2*z
a, b = x*6//z, y*6//z
@erikbern
erikbern / gist:7cd899651aff9b656e9f
Last active August 29, 2015 14:24
Stupid graph visualizations
http://blog.revolutionanalytics.com/2015/07/the-network-structure-of-cran.html
http://radar.oreilly.com/2015/06/graphs-in-the-world-modeling-systems-as-networks.html
http://quid.com/insights/the-future-of-artificial-intelligence/?utm_content=bufferb9759&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer
http://www.kpcb.com/blog/a-breakthrough-approach-to-making-data-useful
https://www.cbinsights.com/blog/e-commerce-investments-top-venture-capital-firms/
https://www.recordedfuture.com/two-shady-men-report/
http://www.galvanize.com/blog/2015/08/05/the-first-interactive-visualization-of-product-integrations/#.Vczc1RNVikq
@erikbern
erikbern / gist:1f32359164e994ef0dd2
Created May 26, 2015 02:23
LSHF, Annoy, Flann, Panns
----------------------------------------------------------------------------------------
n_samples: 1000 n_features: 100
LSHF index build time: 0.0258071422577
ANNOY index build time: 0.012866973877
FLANN index build time: 0.00251913070679
Panns index build time: 3.09596705437
LSHF average query time: 0.00537742614746 , Average accuracy: 0.536
ANNOY average query time: 0.000244197845459 , Average accuracy: 0.9954
FLANN average query time: 0.000175647735596 , Average accuracy: 0.5824
Panns average query time: 0.0499544477463 , Average accuracy: 0.8956
import numpy as np
import matplotlib.pyplot as plt
mean = np.array([1, 1, 1])
cov = np.array([[1, 0.5, 0.5], [0.5, 1, 0.5], [0.5, 0.5, 0.5]])
people = np.random.multivariate_normal(mean, cov, 100000)
criterion = np.array([0, 0.2, 1.0])
scores = np.dot(people, criterion)
@erikbern
erikbern / gist:ba3456f836ccc9c044e8
Last active August 29, 2015 14:18
simple javascript task framework to flip recursion inside out
function serializeArgs(args) {
return JSON.stringify(args);
}
function unroll(f) {
if (f._cache == undefined)
f._cache = {};
var f_new = function() {
var key = serializeArgs(arguments);