Skip to content

Instantly share code, notes, and snippets.

@stucchio
stucchio / beta_bandit.py
Created April 14, 2013 15:46
The beta-distribution based bayesian bandit algorith,.
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@stucchio
stucchio / beta_bandit.py
Last active April 3, 2022 21:17
Beta-distribution Bandit
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior
@stucchio
stucchio / nyc_teacher.py
Created May 26, 2012 02:51
Plots used in my "NO SCATTERPLOT" post
# Data from: http://www.ny1.com/content/top_stories/156599/now-available--2007-2010-nyc-teacher-performance-data#doereports
from pylab import *
from pandas import *
import re
def get_data(filename):
d = read_csv(filename, delimiter="\t")
d['teacher'] = d['teacher_name_first_1'] + " " + d['teacher_name_last_1']
return d
@stucchio
stucchio / hexbin_vs_scatter.py
Created March 24, 2012 14:58
Hexbin vs Scatterplot
from numpy import *
from pylab import *
x = rand(N)
y = x + random.normal(0, 0.4, size=(N,))
subplot(211)
axis((0,1,0,1))
scatter(x,y)
subplot(212)
@stucchio
stucchio / rc.local
Created December 3, 2011 17:55
Making networking work on cloned Ubuntu VMs
if ! ifconfig eth0 && ! -f /var/log/rewriting-net-rules;
then
echo "Mac address for eth0 is incorrect."
/bin/rm -rf /etc/udev/rules.d/70-persistent-net.rules
touch /var/log/rewriting-net-rules
echo "Rebooting now."
/sbin/reboot
else
/bin/rm /var/log/rewriting-net-rules
fi
@stucchio
stucchio / gist:1403042
Created November 29, 2011 02:09
Graphs of bodyweight vs time
from pylab import *
E = 1.5 # exercise level
height = 6*12 #Height in inches
a = E * (66 + 12.7*height) / 3500.0
b = E * 6.23 / 3500
g = E * 6.775 / (365*3500.0)
age_range = (28, 40)
t = arange(age_range[0]*365,age_range[1]*365)
@stucchio
stucchio / fsm.js
Created August 9, 2011 08:12
Javascript Finite State Machine
function FiniteStateMachine(states, transitions, initialState) {
var state = initialState;
this.getState = function() {
return state;
};
this.transition = function(newState) {
if (_.detect(transitions, function(transition) { return (transition[0] == state) && (transition[1] == newState); })) {
if (('onExit' in states[state]) && (typeof states[state].onExit == 'function')) {
@stucchio
stucchio / run-elephant.sh
Created April 4, 2011 18:14
A script to run elephantdb as a daemon
#!/bin/sh
if test -s /var/run/hadoop/elephantdb.pid;
then
OLDPID=`cat /var/run/hadoop/elephantdb.pid`
echo "Killing old elephant process, pid=$OLDPID"
kill $OLDPID
rm /var/run/hadoop/elephantdb.pid
fi;
nohup java elephantdb.main /elephant/global-conf.clj /usr/local/hadoop/conf/elephantdb-local-conf.clj "`date`" > /var/log/hadoop/elephantdb.log &
@stucchio
stucchio / employment_vs_investment.py
Created March 31, 2011 18:15
Employment vs investment
from pylab import *
from numpy import *
import matplotlib.cbook as cbook
from datetime import datetime
from scipy.interpolate import interp1d
def read_file(filename):
dates = []
values = []
for l in open(filename).readlines():
@stucchio
stucchio / UUIDToDoubleMapWritable.java
Created March 25, 2011 23:14
A specialized map to save overhead in hadoop
package stylewok.utils.writable;
import org.apache.hadoop.io.*;
import java.util.*;
import java.io.*;
public class UUIDToDoubleMapWritable extends HashMap<UUIDWritable,Double> implements Writable {
public UUIDToDoubleMapWritable() { }