Skip to content

Instantly share code, notes, and snippets.

View mattjj's full-sized avatar

Matthew Johnson mattjj

View GitHub Profile
@mattjj
mattjj / stanfordtmt.scala
Created November 13, 2012 19:24
Stanford TMT Example
val source = CSVFile("pubmed-oa-subset.csv") ~> IDColumn(1);
val tokenizer = {
SimpleEnglishTokenizer() ~> // tokenize on space and punctuation
CaseFolder() ~> // lowercase everything
WordsAndNumbersOnlyFilter() ~> // ignore non-words and non-numbers
MinimumLengthFilter(3) // take terms with >=3 characters
}
val text = {
@mattjj
mattjj / graphs.py
Created November 21, 2012 01:52
graphs
from __future__ import division
import numpy as np
na = np.newaxis
from matplotlib import pyplot as plt
def adj_path(n):
a = np.zeros((n,n))
a.flat[1::a.shape[0]+1] = a.flat[a.shape[0]::a.shape[0]+1] = 1
return a
@mattjj
mattjj / get_TIPS_prices.sh
Last active December 10, 2015 10:38
get TIPS prices
#!/bin/bash
curl -s "http://online.wsj.com/mdc/public/page/2_3020-tips-${1}.html?mod=mdc_pastcalendar" \
| tr '^M' '\n' \
| grep -E '<td class="(([pn]?num)|(text))">' \
| sed -E 's/<[^>]*>([^<]*)<.*/\1/' \
| awk '(NR%6==0){print p; p=""; next}{p=p "\t" $0;}' \
| sed "s/^/${1}/"
@mattjj
mattjj / cachefile.sh
Created January 1, 2013 18:18
simple shell cachefile convenience function
#!/bin/bash
usage() { echo "usage: ${0##*/} commandstring cachefilename"; }
if [ $# -ne 2 ]; then usage; exit 0; fi
if [ -e "$2" ]
then
cat "$2"
else
eval "$1" | tee $2
fi
@mattjj
mattjj / unscented_transform.py
Created January 13, 2013 17:16
unscented transform for UKF/UKS stuff
from __future__ import division
import numpy as np
def unscented_transform(mu,Sigma,alpha,kappa,beta=2):
n = mu.shape[0]
lmbda = alpha**2*(n+kappa)-n
points = np.empty((2*n+1,n))
mean_weights = np.empty(2*n+1)
cov_weights = np.empty(2*n+1)
@mattjj
mattjj / double-pendulum.scm
Created January 24, 2013 18:51
double pendulum from SICM
;; the lagrangian for two unconstrained masses in gravity
;; (this is just 1/2 m v^2 - mgh from high school)
(define ((L-ms-in-g m-tuple g) local)
(let ((v-tuple (velocities local))
(q-tuple (coordinate local)))
(let ((momenta (uptuple-map (lambda (mi vi) (* (/ 1 2) mi (norm vi))) m-tuple v-tuple))
(potentials (uptuple-map (lambda (mi qi) (* mi g (ref qi 1))) m-tuple q-tuple)))
(let ((T (uptuple-reduce + momenta))
(V (uptuple-reduce + potentials)))
(- T V)))))
@mattjj
mattjj / skinning.py
Created February 19, 2013 21:35
skinning
from __future__ import division
import numpy as np
import sys
sys.path.append('/Users/mattjj/Dropbox/work/datta/renderer')
from MouseData import MouseData
m = MouseData('/Users/mattjj/Dropbox/work/datta/renderer/data/mouse_mesh_low_poly3.npz')
translations = m.joint_translations
def inv(E):
from __future__ import division
import numpy as np
np.seterr(divide='ignore')
from matplotlib import pyplot as plt
plt.ioff()
import pyhsmm
pyhsmm.internals.states.use_eigen()
from pyhsmm.util.text import progprint_xrange
@mattjj
mattjj / config.fish
Created March 16, 2013 17:36
in ~/.config/fish/config.fish and ~/.config/fish/functions/fish_prompt.fish
set PATH "$HOME"/bin /opt/local/Library/Frameworks/Python.framework/Versions/Current/bin/\
/opt/local/bin /opt/local/sbin $PATH
set CDPATH . "$HOME" $CDPATH
set fish_greeting ""
function fish_user_key_bindings
bind \e\[1\;9A 'history-token-search-backward'
end
@mattjj
mattjj / chunk_data.py
Last active August 24, 2021 15:11
data chunking with overlapping windows! uses stride tricks so no data is copied; it just produces a view!
from __future__ import division
import numpy as np
from numpy.lib.stride_tricks import as_strided as ast
def chunk_data(data,window_size,overlap_size=0,flatten_inside_window=True):
assert data.ndim == 1 or data.ndim == 2
if data.ndim == 1:
data = data.reshape((-1,1))
# get the number of overlapping windows that fit into the data