Skip to content

Instantly share code, notes, and snippets.

View CamDavidsonPilon's full-sized avatar
:shipit:
Learning bio brb

Cameron Davidson-Pilon CamDavidsonPilon

:shipit:
Learning bio brb
View GitHub Profile
@CamDavidsonPilon
CamDavidsonPilon / multiderivative.py
Last active December 15, 2015 09:59
This is a recursive implementation of evaluating PDF of a Cumulative Density Function (CDF) at a point `u`, in arbitrary dimension, using finite difference methods.
def cdf2pdf( f, u, delta=0.001, kwargs={} ):
"""
Computes every partial derivative of the CDF to find the underlying PDF.
f: a numpy vectorized python/numpy function
u: the point to evaluate the CDF at.
delta: the precision
kwargs: additional keywords args to f
"""
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as
you did, the {internet|net|web} will be {much more|a lot more}
useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch}
your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
Thanks.|
@CamDavidsonPilon
CamDavidsonPilon / snapple.py
Last active December 16, 2015 12:58
using data from https://gist.github.com/shanselman/5422230 as `filename`, will create a random comment.
import re
import random
CURLY_RE = re.compile( "\{(.*?)\}" )
def spam( filename ):
file = open(filename, "r")
@CamDavidsonPilon
CamDavidsonPilon / lr.py
Last active December 16, 2015 16:39
linear regression counter example
import numpy as np
from sklearn.linear_model import LinearRegression
#create some random data.
x1 = np.random.randn(250,1)
x2 = 0.001*np.random.randn(250,1) - x1
x3 = np.random.randn(250,1)
# Y is a linear combination of the created data, with
# weights (10,10,0.01)
@CamDavidsonPilon
CamDavidsonPilon / pushData.py
Last active December 18, 2015 11:39
reflexive art project.
import android
from time import sleep
from requests import post
droid = android.Android()
SERVER = "http://artech.herokuapp.com"
ID = 0
"""
@CamDavidsonPilon
CamDavidsonPilon / cover.py
Last active December 19, 2015 03:19
Make cover go now
%pylab
import scipy.stats as stats
print "Best to use custom matplotlibrc located in /styles directory of BMH project."
figure( figsize= ( 8, 11 ) )
#means = np.random.uniform( -4, 4, size = 5 )
means = np.array([ 3.90933614, -1.15148996, 1.70045292, -3.27613385, -0.71058847])
@CamDavidsonPilon
CamDavidsonPilon / biased_coin.py
Created November 24, 2013 22:21
biased coins to unbiased (heh cheating)
import random
p1 = 0.9
p2 = 0.1
N = 10000
s = 0.0
i = 0
while i < N:
@CamDavidsonPilon
CamDavidsonPilon / findN.ipynb
Last active January 1, 2016 11:39
find a bound on the expected number of samples needed for an A/B test.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@CamDavidsonPilon
CamDavidsonPilon / matplotlib_ipython.py
Created January 27, 2014 15:14
Ideal %matplotlib use
# using %matploblib <backend> also imports the following helpers
from matplotlib import pylplot as plt
from IPython.core.pylabtools import figsize
@CamDavidsonPilon
CamDavidsonPilon / exponential_survival_data.py
Last active August 29, 2015 13:56
Generate exponential survival data with probability alpha of censorship
def exponential_survival_data(n, cr=0.05, scale=1.):
t = stats.expon.rvs(scale=scale, size=n)
if cr == 0.0:
return t, np.ones(n, dtype=bool)
def pF(h):
v = 1.0*h/scale
return v / (np.exp(v)-1) - cr