Skip to content

Instantly share code, notes, and snippets.

View matpalm's full-sized avatar
🎯
Focusing

mat kelcey matpalm

🎯
Focusing
View GitHub Profile
@matpalm
matpalm / gpu_stat.py
Last active October 10, 2023 10:31
json formatting of nvidia-settings
#!/usr/bin/env python
# gpu_stat.py [DELAY [COUNT]]
# dump some gpu stats as a line of json
# {"util":{"PCIe":"0", "memory":"11", "video":"0", "graphics":"13"}, "used_mem":"161"}
import json, socket, subprocess, sys, time
try:
delay = int(sys.argv[1])
except:
delay = 1
import numpy as np
import time
np.random.seed(123)
# square matrices will do for a demo
m = np.random.randn(1000, 1000).astype('float32')
x = np.random.randn(1000, 1000).astype('float32')
b = np.random.randn(1000, 1000).astype('float32')
start = time.time()
for i in range(500):
y = np.add(np.dot(m, x), b)

sorted by sum log(P)

$ cat test | ./mm_loglikelihood.py --model oms.mm.json | sort -k1 -nr -t"     "
sum_log(P)      mean_log(P)     B? sequence
-20.0139103713	-1.42956502652	F  A/DT white/JJ blaze/NN and/CC noseband/NN is/VBZ preferred/VBN over/IN a/DT solid-colored/JJ head/NN ./.
-21.8407084327	-3.12010120468	T  Sign/VB In/IN |/CD Sign/NN Up/IN
-30.9669696364	-1.93543560227	F  The/DT average/JJ household/NN size/NN was/VBD 2.69/CD and/CC the/DT average/JJ family/NN size/NN was/VBD 3.09/CD ./.
-36.3208027746	-2.59434305533	T  com/NN is/VBZ a/DT division/NN of/IN ThreadPit/NNP Copyright/NNP ©/CD 2005-2014/CD 6/CD Dollar/NN Shirts/NNS
-38.8882082333	-1.94441041167	F  The/DT airline/NN was/VBD established/VBN in/IN 1991/CD and/CC began/VBD operations/NNS in/IN 1992/CD as/IN Iran/NNP 's/POS first/JJ private/JJ airline/NN ./.
@matpalm
matpalm / bump.R
Last active December 15, 2015 06:19
overwhelming dodgy bump chart
library(ggplot2)
df = read.delim('foo.tsv')
ggplot(df, aes(time, rank)) +
geom_line(aes(colour=item), size=2) +
geom_text(aes(label=df$item), size=10) +
xlim(0.5, 2.5) + ylim(-0.5, 1.5) +
facet_grid(~group) +
scale_y_reverse() +
opts(legend.position="none",
strip.text.x=theme_text(size=20))
#!/usr/bin/env python
import json
import urllib
def estimated_count_for(search_term):
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % urllib.urlencode({'q': search_term})
results = json.loads(urllib.urlopen(url).read())
try:
return results['responseData']['cursor']['estimatedResultCount']
except KeyError:
@matpalm
matpalm / gist:4499644
Created January 10, 2013 05:15
tau does not equal sigma
sigma_p = ggplot(df, aes(tau)) + geom_density() + opts(title="sigma")
@matpalm
matpalm / sdf
Last active December 10, 2015 07:58
uniform std dev
std_dev = Uniform('std_dev', lower=0, upper=50)
@deterministic(plot=False)
def precision(std_dev=std_dev):
return 1.0 / (std_dev * std_dev)
process = Normal('process', mu=mean, tau=precision, value=data, observed=True)
@matpalm
matpalm / gist:4219904
Created December 5, 2012 22:02
metro trains webapp
def service_level(line):
# fuck em
return "Good Service"
/* head -- output first part of file(s)
Copyright (C) 89, 90, 91, 1995-2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@matpalm
matpalm / gist:3977169
Created October 29, 2012 23:17
l33t hax0r
...
elif "apple computers" in text:
return "Computer Hardware"
elif "Hockey" in text:
return "Sports"
elif "McKinsey" in text:
return "Management Consulting"
elif "NASA" in text:
return "Aviation & Aerospace"
...