Skip to content

Instantly share code, notes, and snippets.

@stucchio
stucchio / bayesian_ab_test.py
Last active April 2, 2023 03:17
Bayesian A/B test code
from matplotlib import use
from pylab import *
from scipy.stats import beta, norm, uniform
from random import random
from numpy import *
import numpy as np
import os
# Input data
@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 / bayes_bandit_empirical_gain_from_incorporating_priors.py
Created April 28, 2013 22:17
Empirical gain from incorporating priors into the Bayesian Bandit
from numpy import *
from scipy.stats import beta
import random
class BetaBandit(object):
def __init__(self, num_options=2, prior=None):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
@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 / basic_income_monte_carlo.py
Last active August 28, 2021 01:42
Monte carlo simulation of basic income/basic job calculations, from blog.
from pylab import *
from scipy.stats import *
num_adults = 227e6
basic_income = 7.25*40*50
labor_force = 154e6
disabled_adults = 21e6
current_wealth_transfers = 3369e9
def jk_rowling(num_non_workers):
@stucchio
stucchio / bayesian_ab_test_empiritcs.py
Last active January 26, 2021 00:54
bayesian a/b test empirics
from pylab import *
from scipy.stats import beta, norm, uniform
from random import random
from numpy import *
import numpy as np
import os
# Input data
prior_params = [ (1, 1), (1,1) ]
from pylab import *
from scipy.stats import uniform, binom, expon, beta
true_gamma = 0.5
N = 600
T = 15
data = zeros((2, N), dtype=float)
event_times = data[0,:]
event_times[:] = uniform(0,15).rvs(N)
@stucchio
stucchio / clone-ubuntu.sh
Created December 16, 2010 14:01
Clone a Virtualbox VM
#!/bin/sh
old=$1
new=$2
if [ $old ] && [ $new ]
then
echo "Cloning $old, saving result as $new"
else
echo "Usage: clone-ubuntu.sh oldname newname"
@stucchio
stucchio / console_output.log
Created February 4, 2020 20:52
Weird doctest errors
File "C:\Users\stucc\Dropbox\src\daywalker\test\..\readme.md", line 86, in readme.md
Failed example:
history[['open', 'high', 'low', 'close', 'volume', 'divCash', 'splitFactor']]
Expected:
open high low close volume divCash splitFactor
date
2004-08-12 17.50 17.58 17.5 17.50 2545100 0.0 1.0
2004-08-13 17.50 17.51 17.5 17.51 593000 0.0 1.0
2004-08-16 17.54 17.54 17.5 17.50 684700 0.0 1.0
Got:
import config
from azure.keyvault.secrets import SecretClient
from azure.identity import ClientSecretCredential
from azure.core.exceptions import ResourceNotFoundError
import time
class AzureKeyVaultConfiguration(config.Configuration):
"""
Configuration class.