View gist:287370
This file contains 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
""" | |
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 | |
""" |
View data.py
This file contains 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
""" 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 = {} |
View spa.py
This file contains 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
""" 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): |
View sudoku.py
This file contains 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
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' |
View value_error_test.py
This file contains 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
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): |
View .gitignore
This file contains 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
*.pyc | |
*.png | |
*~ |
View not_bad_graphs.py
This file contains 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
""" 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] |
View pretty_networks.py
This file contains 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
""" 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 |
View history_steps.py
This file contains 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 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'] | |
OlderNewer