Skip to content

Instantly share code, notes, and snippets.

View aflaxman's full-sized avatar

Abraham Flaxman aflaxman

View GitHub Profile
@aflaxman
aflaxman / gist:287370
Created January 26, 2010 23:34
networkx-osm import open street map data as a networkx graph
"""
Read graphs in Open Street Maps osm format
Based on osm.py from brianw's osmgeocode
http://github.com/brianw/osmgeocode, which is based on osm.py from
comes from Graphserver:
http://github.com/bmander/graphserver/tree/master and is copyright (c)
2007, Brandon Martin-Anderson under the BSD License
"""
We couldn’t find that file to show.
""" Class for holding species occurrence data, and associated covariates"""
import csv
class Data:
def __init__(self, fname='data.csv'):
self.raw_data = [d for d in csv.DictReader(open(fname))]
self.seen = []
self.unseen = []
self.cov = {}
""" Generate graphs from the spatial preferential attachment model,
and animate them"""
from pymc import runiform, rnormal
from networkx import DiGraph, draw
from pylab import clf, axis, savefig
from numpy import maximum, minimum
def perturb(x, e):
from pylab import *
import random
index_set = [[i,j] for i in range(9) for j in range(9)]
def solve(T):
""" Find a solution to T, if possible
T is a 9x9 array, with blank cells set to -1
T is changed to the solution, returns 'success' or 'failure'
from pymc import *
def test(a0, b0):
# use non-informative priors
x = rbinomial(10, .5, 10)
a = Uniform('a', lower=-1000, upper=1000, value=a0)
b = Normal('b', mu=0, tau=.01, value=b0)
@deterministic
def theta(a=a, b=b):
*.pyc
*.png
*~
""" Script to remake some uncommunicative info graphics I've seen in the news"""
from pylab import *
# Eli Sander's article "Tax the Filthy Rich"
# http://www.thestranger.com/seattle/tax-the-filthy-rich/Content?oid=4837455
# http://www.thestranger.com/binary/8563/feature2.jpg
y = [2116.906, 787.162, 356.570, 72.858]
y2 = [38.400]
""" script to visualize some random graphs that are nice to draw"""
import networkx as nx
import pylab as pl
n = 100 # number of vertices
rc = .25 # critical radius for geometric graph
rr = .05 # repel radius for hard-core model
p = .25 # edge percolation probability
import pymc as pm
import numpy as np
# FIXME: Need to store duplicates too, when jumps are rejected. That means some mechanism
# for making sure the history is full-rank needs to be employed.
class HistoryCovarianceStepper(pm.StepMethod):
_state = ['n_points','history','tally','verbose']