Skip to content

Instantly share code, notes, and snippets.

View cjbayesian's full-sized avatar

Corey Chivers cjbayesian

View GitHub Profile
@cjbayesian
cjbayesian / bayes_update.R
Created August 16, 2012 20:23
generate a video demonstrating Bayesian updating
## Corey Chivers, 2012 ##
sim_bayes<-function(p=0.5,N=100,y_lim=20,a_a=2,a_b=10,b_a=8,b_b=3)
{
## Simulate outcomes in advance
outcomes<-sample(1:0,N,prob=c(p,1-p),replace=TRUE)
success<-cumsum(outcomes)
for(frame in 1:N)
{
png(paste("plots/",1000+frame,".png",sep=""))
@cjbayesian
cjbayesian / plot_skies.R
Created October 13, 2012 21:54
Observing Dark Worlds visualization
################## Plot training skies ###################
##
## corey.chivers@mail.mcgill.ca
##
##########################################################
## calculate a vector given
## x,y,e1,e2
gal_line<-function(g,scale=100)
{
@cjbayesian
cjbayesian / intro_to_simulation.R
Created March 22, 2013 11:50
Introduction to simulation using R
#########################################################
## Intro to Simulation - R/Stats Intro Series
## Designed by: Corey Chivers, 2013
## Department of Biology, McGill University
#########################################################
##@ 0.1 @##
rm(list=ls()) # Housekeeping
#setwd('<my working directory>') # set working dir
## Simulate Grime Dice ##
red<-c(4,4,4,4,4,9)
blue<-c(2,2,2,7,7,7)
olive<-c(0,5,5,5,5,5)
yellow<-c(3,3,3,3,8,8)
magenta<-c(1,1,6,6,6,6)
## Play n match-ups between d1 and d2
@cjbayesian
cjbayesian / AUC.R
Last active January 7, 2017 04:50
Calculate and plot AUC
###################################################
##
## Functions for calculating AUC and plotting ROC
## Corey Chivers, 2013
## corey.chivers@mail.mcgill.ca
##
###################################################
## Descrete integration for AUC calc
@cjbayesian
cjbayesian / GOL.R
Created October 24, 2013 19:10
Functions for simulating Conway's Game of Life
## Functions for simulating Conway's Game of Life
## Modified from http://www.petrkeil.com/?p=236
neighbour_count <- function(X)
{
side <- nrow(X)
# make the shifted copies of the original array
allW = cbind( rep(0,side) , X[,-side] )
allNW = rbind(rep(0,side),cbind(rep(0,side-1),X[-side,-side]))
allN = rbind(rep(0,side),X[-side,])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cjbayesian
cjbayesian / parseBMC_XML.py
Created December 20, 2013 17:25
Parse BMC OA articles from XML to utf-8 text of the title, abstract, and body.
#!/usr/bin/python
"""
Parse BMC OA articles from XML to utf-8 text of the title, abstract, and body.
"""
import libxml2
from os import listdir
from time import gmtime, strftime
input_dir = './BMC_FTP/content/articles/'
files = listdir(input_dir)
@cjbayesian
cjbayesian / buffet_basketball.R
Last active January 4, 2016 04:39
What’s Warren Buffett’s $1 Billion Basketball Bet Worth? I look into it in this post http://wp.me/p1C5UP-gF
## Warren Buffet's 1B Basketball Challenge ##
expected_value <- function(p,ngames=63,prize=1000000000){
p^ngames * prize
}
## What is the expected value of an entry
## given a particular level of prediction accuracy
expected_value(p=0.80)
expected_value(p=0.85)
def plot_correlogram(df,figsize=(20,20)):
''' Creat an n x n matrix of scatter plots for every
combination of numeric columns in a dataframe'''
cols = list(df.columns[df.dtypes=='float64'])
n = len(cols)
fig, ax = plt.subplots(n,n,figsize=figsize)
for i,y in enumerate(cols):
for j,x in enumerate(cols):
if i != n-1: