Skip to content

Instantly share code, notes, and snippets.

View fonnesbeck's full-sized avatar

Chris Fonnesbeck fonnesbeck

  • Philadelphia Phillies
View GitHub Profile
@minrk
minrk / foo.py
Created November 16, 2014 04:12
a=1
@fonnesbeck
fonnesbeck / gist:342992
Created March 25, 2010 00:03
Equal in distribution
\,{\buildrel d \over =}\,
@fonnesbeck
fonnesbeck / factor2numeric.R
Created March 25, 2010 00:06
Convert factor levels to numeric in R. Slightly more efficient than "as.numeric(as.character(f))"
as.numeric(levels(f))[f]
@fonnesbeck
fonnesbeck / cprob.tex
Created March 24, 2010 23:59
Conditional probability statement in LaTeX
Y_i \sim \left\{ \begin{array}{l}
0, \text{with probability } (1-\psi) \\
\text{Poisson}(\mu), \text{with probability } \psi
\end{array} \right.
@mja
mja / homebrew_scipy.sh
Created December 13, 2010 08:09
Install numpy, scipy, and matplotlib on OS X 10.6
homebrew install gfortran
homebrew install python
homebrew install distribute
homebrew install pip
pip install ipython
pip install numpy
pip install scipy
pip install -f http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz matplotlib
@jeffreyhorner
jeffreyhorner / Twitchimps.R
Created December 17, 2010 23:04
Maps your follower names to R variables located in an environment on your search path. Each variable contains a list of influence scores for that follower.
library(twitteR)
library(infochimps)
library(datamap)
infochimps('YOUR_API_KEY')
# Creates a new mapper, similar to an OO class
newMapper(type='twitchimps:influence',
# Init is called once during newMap(). Note that
@roban
roban / plot2Ddist.py
Created January 24, 2011 12:14
Routines related to plotting 2D distributions of parameters (mainly for pymc models).
"""Routines related to plotting 2D distributions of parameters.
The core of this module is plot2Ddist, which plots a two-dimensional
distribution with 1D marginal histograms along each axis and optional
features like contours and lines indicating ranges and true values.
"""
import itertools
import math
@fonnesbeck
fonnesbeck / fill_missing.py
Created February 8, 2011 15:18
Nice Python idiom for replacing missing values in a data iterable
missing = -999
filled_data = [(x, missing)[x is ''] for x in raw_data]
@fonnesbeck
fonnesbeck / least_squares.py
Created April 14, 2011 13:15
Least squares with equality constraint (taken and modified from http://fseoane.net/blog/2011/least-squares-with-equality-constrain/)
import numpy as np
from scipy import linalg
def lse(A, b, B, d, cond=None):
"""
Equality-contrained least squares.
The following algorithm minimizes ||Ax - b|| subject to the
constrain Bx = d.
@brantfaircloth
brantfaircloth / stdout_progress.py
Created May 27, 2011 06:02
pretty easy progress indicator
# this works just fine w/ multiprocess...
# now with more flushing
import sys
import time
sys.stdout.write("This is running")
sys.stdout.flush()
for i in range(5):
sys.stdout.write(".")