This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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="")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
LICENSE: BSD (same as pandas) | |
example use of pandas with oracle mysql postgresql sqlite | |
- updated 9/18/2012 with better column name handling; couple of bug fixes. | |
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle. | |
to do: | |
save/restore index (how to check table existence? just do select count(*)?), | |
finish odbc, |
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 14 columns, instead of 11 in line 6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Year,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Total | |
1950,3091.48387097,3266.96428571,3325.90322581,3187.86666667,3160.58064516,3078.7,2958.09677419,2885.80645161,3056.83333333,2943.70967742,2912.8,2864.74193548,3059.45479452 | |
1951,3029.5483871,3181.71428571,3210.74193548,3142.96666667,3196.41935484,3087.1,3017.0,2929.35483871,3022.56666667,2884.61290323,2806.4,2878.16129032,3031.17808219 | |
1952,3072.0,3223.24137931,3268.4516129,3181.03333333,3115.93548387,2994.03333333,2973.5483871,2865.29032258,3070.0,2807.74193548,2860.5,2814.5483871,3027.62739726 | |
1953,3052.90322581,3175.96428571,3248.19354839,3163.06666667,3142.83870968,3039.6,2975.5483871,2856.61290323,3061.5,2774.12903226,2679.63333333,2846.16129032,3000.07945205 | |
1954,3074.06451613,3238.64285714,3172.93548387,3180.3,3243.35483871,3096.2,3021.51612903,2930.4516129,3054.9,2781.06451613,2848.86666667,2862.19354839,3040.39178082 | |
1955,3058.03225806,3235.96428571,3286.93548387,3178.4,3151.77419355,3104.63333333,2988.51612903,2933.41935484,3064.06666667,287 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gspread | |
from pandas import * | |
import logging | |
class GDocError(Exception): | |
def __init__(self, value): | |
self.parameter = value | |
def __str__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Trivial GARCH implementation in python | |
# | |
# From Peter Tessin's http://www.petertessin.com/TimeSeries.pdf | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pandas import DataFrame, Series | |
import numpy as np | |
import math | |
import random | |
import copy | |
NaN_Flag = -1 # pandas uses np.nan, but that coerces ints to floats :( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from numpy import asmatrix, asarray, ones, zeros, mean, sum, arange, prod, dot, loadtxt | |
from numpy.random import random, randint | |
import pickle | |
MISSING_VALUE = -1 # a constant I will use to denote missing integer values | |
def impute_hidden_node(E, I, theta, sample_hidden): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coroutine(func): | |
""" | |
A decorator that turns a function with normal input into a coroutine. | |
This decorator takes care of priming the coroutine, doing the looping and | |
handling the closing. | |
The first argument of any decorated function is what was received when | |
data was sent to the coroutine via the ``.send`` method. All the other | |
``*args`` and ``**kwargs`` are what was passed to the decorated function | |
when instantiating the coroutine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To check if this is up-to-date with the tax rates go to | |
# http://www.expatax.nl/tax-rates-2016.php and see if there's anything | |
# newer there. | |
# | |
# I make no guarantees that any of this is correct. I calculated this | |
# at the time and have been updating it when new tax rates come along | |
# because people keep finding this useful. | |
# | |
# There's also an interactive JS version of this created by | |
# @stevermeister at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Average runs looks like this: | |
# $ ./serialization.py | |
# Starting json... | |
# done: 5.75292301178 | |
# Starting simplejson... | |
# done: 6.66689586639 | |
# Starting cjson... | |
# done: 2.09307098389 |