Skip to content

Instantly share code, notes, and snippets.

View fonnesbeck's full-sized avatar

Chris Fonnesbeck fonnesbeck

  • Philadelphia Phillies
View GitHub Profile
@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.
@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]
*.pyc
*.png
*~
@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]
@huyng
huyng / matplotlibrc
Created February 8, 2011 15:50
my default matplotlib settings
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@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.