Skip to content

Instantly share code, notes, and snippets.

View eob's full-sized avatar

Ted Benson eob

View GitHub Profile
@eob
eob / Polynomial Fitting
Created April 22, 2014 02:14
Polynomial Fitting
from scipy.optimize import curve_fit
from collections import Counter, defaultdict
import numpy as np
import time
def f(xss, a, b, c, d, e, f):
"""
Polynomial function up to order 5
"""
ret = []
I’ve worked in an economy that rewards someone who saves the lives of others on a battlefield with a
medal, rewards a great teacher with thank-you notes from parents, but rewards those who can detect
the mispricing of securities with sums reaching into the billions. In short, fate’s distribution of long
straws is wildly capricious.
From Warren Buffett's Giving Pledge
http://givingpledge.org/pdf/letters/Buffett_Letter.pdf
@eob
eob / gist:d597f558890c2c05a73a
Created August 9, 2015 10:12
record-poop.py
def record_poop():
data = {
"Timestamp": time.strftime("%Y-%m-%d %H:%M"),
"Measurement": 'Poopy Diaper'
}
requests.post(MAGIC_FORM_URL, data)
p (char *) [data bytes]
<body>
<table width="100%">
<tr>
<td colspan=3>
</td>
</tr>
<tr valign="top">
<td width="15%"> <div ex:role="facet" ex:expression=".venue" ex:facetLabel="Venue"></div>
def initializeToCrfPotentials = {
for (tweetIdx <- 0 until _Y.size) {
for (tokenIdx <- 0 until _Y(tweetIdx).size) {
for (labelIdx <- 0 until _Y(tweetIdx)(tokenIdx).size) {
// Note: the +1 in token index is because of the <S> token at the beginning
// of the CRF potentials.
logger.info(tweetIdx + " " + tokenIdx + " " + labelIdx)
_Y(tweetIdx)(tokenIdx)(labelIdx) = _crfPotentials(tweetIdx)(tokenIdx + 1)(labelIdx)
}
}
def initializeToCrfPosteriors = {
_Y = emptyY // Initialize to all 0s
require (_Y.size == _crfPotentials.size) // Santiy check: both are over tweets
for (tweet <- 0 until _crfPotentials.size) {
_forwardBackward.setInput(_crfPotentials(tweet))
val nodeMarginals = _forwardBackward.getNodeMarginals()
val nonBorderMarginals = nodeMarginals.slice(1, nodeMarginals.size - 1)
@eob
eob / gist:718298
Created November 27, 2010 21:35
Alignment Update
/**
* log q(Z_i = k) less than or equal to
* log P(Z_i=k) (the prior)
* + log E_ { q(y_i),q(T_k) } Theta^T_REW f_REW(x_i,y_i,T_k)
* - log E_ { q(T_k) } Z_ { x_i } (Theta, T_k)
*/
def update(td: TaggingDistribution, rd: RecordDistribution) = {
// Initialize to all -Infinity
_Z = logEmptyZ()
@eob
eob / gist:718300
Created November 27, 2010 21:38
Record Update
def update(td: TaggingDistribution, ad: AlignmentDistribution) = {
/*
* Setup: Create an empty set of records
*/
var TPrime = List[Record]()
for (i <- 0 until _T.size) {
val r = new Record(i, _schema)
r.setThetaRewrite(_T(i).thetaRewrite)
TPrime = TPrime :+ r
}
@eob
eob / gist:731611
Created December 7, 2010 09:23
Why Scala Syntax is Scary
object ListCase {
def matcher(l:List[Int]) {
l match {
case List(1,3,5,7) => println("Primes")
case List(_,_,_,3,_) => println("3 on 3")
case 1::rest => println("List starting with 1")
case List(_*) => println("Other list")
}
}
}