Skip to content

Instantly share code, notes, and snippets.

@danstowell
danstowell / reversegeocoding.py
Created October 20, 2012 13:44 — forked from tommorris/post.rb
simplified version of reverse geocode parse
#!/bin/env python
# python port by Dan Stowell, of OSM reverse geocoding by Tom Morris
import json
import urllib2
def latlon_to_label(latitude, longitude):
url = "http://nominatim.openstreetmap.org/reverse?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1" % (latitude, longitude)
data = urllib2.urlopen(url).read()
@danstowell
danstowell / heatinterpolate.py
Created April 16, 2013 14:27
combining density estimation and delaunay interpolation for confidence-weighted value mapping in python
#!/usr/bin/env python
# combining density estimation and delaunay interpolation for confidence-weighted value mapping
# Dan Stowell, April 2013
import numpy as np
from numpy import random
from math import exp, log
from scipy import stats, mgrid, c_, reshape, rot90
@danstowell
danstowell / data1d_gchangepoint.data.R
Last active December 19, 2015 02:29
a kind of relaxed version of a changepoint model
D <- 1
N <- 100
beta_a <- 0.05
beta_b <- 0.5
x <- structure(c(26.9413373923, 29.1350302225, 29.1582008922, 28.7840903488, 24.7588135825, 24.5383857689, 22.0150222148, 34.3357977978, 33.3175453175, 27.0393355201, 29.0391675549, 23.1313991805, 22.26141398, 20.8979942215, 25.4268018477, 29.8337205377, 31.127327082, 24.100751496, 27.5635478812, 23.8609747894, 23.9787664652, 21.6289647513, 26.669515063, 32.5843649319, 25.4968136481, 35.7060523151, 25.5803512966, 41.8961419951, 26.7957989466, 17.9698918602, 33.0624273937, 18.4957449301, 26.8025773082, 26.973815048, 27.8235580668, 20.4345371567, 23.0191935867, 27.3180574495, 35.26315069, 27.3524079853, 26.671244883, 28.1304610893, 25.4276672374, 26.9752666167, 24.0932313213, 22.4464662722, 17.8121045108, 20.2510237823, 29.0263323195, 22.4228546253, 40.6781371183, 39.0103908783, 38.3286502205, 40.3057236764, 38.8028148176, 38.4926162261, 37.8330233658, 41.8476895218, 43.5582415338, 40.9933617032, 41.6652154894, 38.7461368463, 41.6872160115, 39.1353024768, 39.67998957
@danstowell
danstowell / gchangepoint_lts.stan
Created July 19, 2013 08:19
a kind of relaxed version of a changepoint model, with an added assumption about common cause in stacked observations
/*
NOTE: changepoint model for vector timeseries, plus "linear transform stack" feature.
Originally designed for the lellouch data (where each vector is actually a stack of 3 related vectors).
So imagine, for example, that the "inherent" thing you're observing generates a spectrogram of size 256,
but it's actually observed from 3 different vantage points, to create an obsn of size 768. Each different vantage point we'll assume
applies a linear transform to the underlying data, (hobs * x + bgspec), where the "hobs" and "bgspec" are unchanging in time
but are independently specified per bin and per vantage point.
cd ~/dev/stan/stan
K <- 4
D <- 1000
M_trn <- 9
M_tst <- 3
proby_trn <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 1, 1, 1, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 1, 1, 1), .Dim=c(9, 4))
tpor_trn <- structure(c(1.01207e-05, 8.78817e-05, 5.01181e-06, 1.19763e-06, 0.000143943, 3.11904e-08, 1.83136e-05, 2.91702e-05, 1.94456e-05, 4.31514e-05, 2.84705e-05, 6.11549e-06, 2.299e-06, 0.000180823, 2.78093e-08, 2.57135e-05, 0.000105035, 4.86663e-05, 2.35292e-05, 8.56379e-06, 3.44704e-06, 5.21752e-07, 2.61876e-05, 1.74499e-09, 1.07338e-05, 3.41347e-05, 3.77774e-05, 2.214e-05, 1.48449e-05, 4.70669e-06, 6.86431e-07, 1.33485e-05, 0, 5.44041e-06, 3.25767e-05, 8.47303e-06, 1.52004e-05, 9.99668e-06, 2.46284e-06, 7.87308e-07, 1.09859e-05, 0, 3.39304e-06, 1.239e-05, 2.67495e-06, 2.52913e-05, 1.10843e-05, 5.10063e-06, 6.15147e-07, 3.27169e-06, 0, 3.28779e-06, 1.93232e-06, 3.01899e-06, 2.03921e-05, 2.98715e-06, 4.00504e-06, 1.77206e-07, 7.91671e-06, 0, 2.11167e-06, 1.14282e-06,
tpl <- structure(c(3.50128e-05, 3.43381e-05, 4.83906e-05, 2.23098e-05, 4.89224e-05, 2.59125e-05, 6.10499e-05, 5.98049e-05, 1.60997e-05, 1.18467e-05, 8.9037e-06, 2.75486e-05, 1.13574e-05, 1.38972e-05, 4.67831e-06, 1.54967e-05, 6.43235e-06, 9.21997e-06, 3.9244e-06, 6.15266e-06, 5.9558e-06, 1.38254e-05, 1.29561e-06, 2.74637e-06, 4.33535e-06, 9.1281e-06, 2.69797e-06, 1.17998e-06, 3.91783e-06, 5.60089e-06, 5.27389e-06, 8.78703e-07, 2.11481e-06, 2.52339e-06, 3.47976e-06, 3.41276e-07, 2.01813e-06, 1.60832e-06, 3.5245e-06, 9.21568e-07, 4.77709e-05, 3.65018e-05, 6.71138e-05, 3.9697e-05, 0.000870703, 0.000460224, 0.000613368, 0.00153852, 0.0010759, 0.00035442, 0.000182669, 0.0026906, 0.000223979, 0.000144171, 4.9295e-05, 0.000478472, 9.1398e-05, 0.000107013, 2.41158e-05, 0.000143066, 6.41374e-05, 0.000151668, 1.75161e-05, 2.32282e-05, 3.84267e-05, 7.5703e-05, 2.61891e-05, 1.33881e-05, 3.34044e-05, 4.10054e-05, 5.50091e-05, 4.19871e-06, 2.09267e-05, 1.5714e-05, 4.58509e-05, 1.21529e-06, 2.54472e-05, 7.90544e-06, 6.72243
#!/usr/bin/env python
# a script to analyse a set of files to illustrate how the panning tends to vary by frequency, via a simple FFT analysis.
# REQUIREMENTS:
# - Python (was tested on 2.7)
# - Python modules:
# - numpy
# - scikits.audiolab
# - matplotlib
@danstowell
danstowell / crosstab.py
Last active August 29, 2015 13:56
Cross-tabulation analysis of the data comparing HOT OSM building damage annotations against damage annotations from the American Red Cross, at https://github.com/AmericanRedCross/OSM-Assessment/tree/gh-pages/data
#!/usr/bin/env python
import os, json
import numpy as np
# crosstabulate the geojson records for OSM damage indicators vs "observed" (by American Red Cross analysts) damage
datadir = '.'
@danstowell
danstowell / mapat_chance.py
Created April 8, 2014 19:20
Empirical plot of the chance values attained for the "Mean Average Precision" statistic
# understanding chance level in MAP calculation
import ml_metrics
import numpy as np
import matplotlib.pyplot as plt
results = np.zeros((100,100))
data = np.zeros((100, 10))
# no need to shuffle the annots since the groundtruth will be randomly generated
N <- 200
K <- 4
timepos <- c(0.0, 2.08978153718, 2.6774000865, 3.47584796473, 3.78710127148, 4.75454597707, 6.66987539583, 7.24902152136, 8.49394193938, 10.4795896694, 10.7914520039, 11.4969222693, 13.3095734861, 14.7212655024, 15.2931492467, 15.4171748097, 15.7443055882, 16.3382608385, 19.567384084, 20.9367692864, 22.0817809742, 22.7254312132, 23.403135471, 23.8066143306, 25.4891533587, 26.6521259878, 28.8649882504, 28.9655706897, 29.1462279535, 30.8224952884, 32.4190207294, 32.4851131989, 33.7009422433, 34.200217965, 35.0046621559, 36.5020537758, 37.2170190379, 37.9581204385, 37.9809986145, 39.206561022, 39.5827104717, 39.9391764411, 39.9627692061, 41.1659966046, 41.8917759456, 44.1068011549, 44.4874876662, 45.468215782, 46.0485677517, 47.0857797338, 47.9105602445, 48.3423708895, 51.2038621099, 51.6573257642, 52.1885429832, 54.4739163581, 55.63263262, 55.7679908666, 57.0184307288, 58.4159798588, 58.6414905971, 61.4434801692, 61.9000345735, 62.64477926, 63.23209667, 65.3153604468, 65.7821474602, 66.397281497